Graphql-dotnet: Generic Creation of ObjectGraphType

Created on 7 Oct 2018  路  3Comments  路  Source: graphql-dotnet/graphql-dotnet

Hi,

I'm trying to use a generic response using ObjectGraphType like this:

public class ResponseRegister : ObjectGraphType>
{
public ResponseRegister(){
Field(x => x.Error, nullable:true).Description("Hay error");
Field,IEnumerable >()
.Description("Lista de errores")
.Name("ErrorList");
Field()
.Name("Entity")
.Description("Entity");
}
}

When I register each mutations like this:

Field>
(
"CreateSchoolSite",
arguments:new QueryArguments(new QueryArgument>{Name = "schoolSite"}),
resolve: context =>
{
var entity = context.GetArgument("schoolSite");
return _repository.AddSchoolSiteAsync(entity);
}
);

Field>
(
"CreateTeacher",
arguments:new QueryArguments(new QueryArgument>{Name = "teacher"}),
resolve: context =>
{
var entity = context.GetArgument("teacher");
return _repository.AddTeacherAsync(entity);
}
);

It alwasy takes the last field register to autocomplete on graphiQL, I'd like to know if that's a problem with something that I'm doing, with the component or maybe with GraphiQL. For example in this case, if I try to call the mutation CreateSchoolSite, it takes the values of CreateTeacher to autocomplete the response.

Thanks for your help

question

Most helpful comment

Are you providing a unique type name on your ResponseRegister types?

All 3 comments

Are you providing a unique type name on your ResponseRegister types?

Hi @joemcbride

What do you mean on "unique type name"?

My ResponseRegister is like this:

public class ResponseRegister : ObjectGraphType>
{
public ResponseRegister(){
Field(x => x.Error, nullable:true).Description("Hay error");
Field,IEnumerable >()
.Description("Lista de errores")
.Name("ErrorList");
Field()
.Name("Entity")
.Description("Entity");
}
}

And in the implementations, I'm trying to do it in this way

Field> with the name CreateStudent
Field> with the name CreateTeacher

If I try to call the mutation the autocomplete always shows me
the option of the TeacherType for the response of the migration, in this way

mutation{
createSchool
(
school:
{
name:"test school same ID"
internalIdentification:"800236529"
}
) {
entity{
userId
}
}
}

But the parameter userId doesn't belongs to StudentType, it belongs to TeacherType.

Hi @joemcbride

Now I got what you meant. The issue was caused because I didn't add a unique name for the generic ObjectGraphType. It was solved just by doing this:

public class ResponseRegister : ObjectGraphType>
{
public ResponseRegister(){
Name=typeof(TEntity).Name;
Field(x => x.Error, nullable:true).Description("Hay error");
Field,IEnumerable >()
.Description("Lista de errores")
.Name("ErrorList");
Field()
.Name("Entity")
.Description("Entity");
}
}

Thanks

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Walid-Abdulrazik picture Walid-Abdulrazik  路  3Comments

pravinhabbu4u picture pravinhabbu4u  路  4Comments

Jonatthu picture Jonatthu  路  3Comments

damithashyamantha picture damithashyamantha  路  4Comments

fiyazbinhasan picture fiyazbinhasan  路  3Comments