You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So if I want to get my hands on a CreateUserResult (the third level in), am I right to define a responseDefinition like below? I have seen people use an anonymous object to go one level below Data...so is there anything wrong with going two down? Or am I making things more complicated than they need to be?
public async Task<CreateUserResult> CreateUser(CreateUserInput input)
{
GraphQLRequest request = new()
{
Query = @"
mutation CreateUser($input: CreateUserInput!) {
createUser(input: $input) { createUserResult {newUser {id, name}, errorMessage }}
}",
Variables = new { input }
};
var responseDefinition = () => new { CreateUser = new { CreateUserResult = new CreateUserResult() } };
var response = await _graphQLClient.SendMutationAsync(request, responseDefinition);
return response.Data.CreateUser.CreateUserResult;
}
Thanks for any input
Fletcher
The text was updated successfully, but these errors were encountered:
I think the question still stands...but I have now realized that I may need to look at adjusting the output from the graphql server. I'm using HotChocolate v13.05 and its the .AddMutationConventions() that is causing this deeper nesting
builder.Services.AddGraphQLServer().AddQueryType().AddMutationType().AddMutationConventions() ...etc
I think the sensible option may be to adjust the server output so the client looks directly below the createUser node to get the data it requires. The extra depth of createUserResult below createUser is not really helpful. But I need to ask the HotChocolate folks what is the point of this deeper nesting....
am I right to define a responseDefinition like below
Yep, exactly right.
Regarding HotChocolate I can't offer you much help since I've never used it, but it seems possible to eliminate the createUserResult level and make the result of createUser directly a createUserResult object.
I am just starting to experiment with graphql and the graphql.client and have a pretty straight-forward mutation to add a new user:
With variables as below:
This gives me back json like this:
So if I want to get my hands on a CreateUserResult (the third level in), am I right to define a responseDefinition like below? I have seen people use an anonymous object to go one level below Data...so is there anything wrong with going two down? Or am I making things more complicated than they need to be?
Thanks for any input
Fletcher
The text was updated successfully, but these errors were encountered: