-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
When implementing AsyncNodeGraphType ExecutionStrategy throws InvalidOperationException #171
Comments
Most likely you need to call |
I'd further guess that the field type in this case is an interface or union, and what happened is that IsTypeOf returned false for the Without seeing more of your code, this is just a guess, of course. |
Thank you for the reply. Regarding public sealed class CharacterType : AsyncNodeGraphType<CharacterModel>
{
public CharacterType()
{
Name = "Character";
Id(characterModel => characterModel.Id);
Field<NonNullGraphType<StringGraphType>>()
.Name("name")
.Resolve(context => context.Source.Name ?? "None");
}
public override async Task<CharacterModel> GetById(IResolveFieldContext<object> context, string id)
{
var characterService = context.RequestServices.GetRequiredService<CharacterService>();
Guid characterId = Guid.Parse(id);
return characterService.GetByIdAsync(characterId, context.CancellationToken);
}
} The workaround that is working at the moment is to extend |
Right I see. |
See faulty code here: (when used by the derived There's nobody that actively works on this project, but if you'd like to open a pull request @tico321 I would be happy to review it, and when merged, issue an updated release. |
Thank you for the fast response, I'll try to take a look over the weekend |
Supporting
Since I'm only using AsyncNodeGraphType I'm going to use the following class in my project until I can find a way to make it work with both Node and AsyncNode.
public class AsyncQueryGraphType : ObjectGraphType
{
public AsyncQueryGraphType()
{
Name = "Query";
Field<NodeInterface>()
.Name("node")
.Description("Fetches an object given its global Id")
.Argument<NonNullGraphType<IdGraphType>>("id", "The global Id of the object")
.ResolveAsync(ResolveObjectFromGlobalId);
}
private async Task<object> ResolveObjectFromGlobalId(IResolveFieldContext<object> context)
{
var globalId = context.GetArgument<string>("id");
var parts = Node.FromGlobalId(globalId);
var node = context.Schema.AllTypes[parts.Type];
var getById = node!.GetType().GetMethod("GetById");
dynamic awaitable = getById!.Invoke(node, new object[] { context, parts.Id });
await awaitable!;
return awaitable.GetAwaiter().GetResult();
}
} Having said that please let me know if you have any suggestions that may work and I'll take a look when I have some time. |
I found that when implementing
AsyncNodeGraphType
theExecutionStrategy
class will throw anInvalidOperationException
since the following call returns null:https://github.com/graphql-dotnet/graphql-dotnet/blob/ed720f46e26704ed457b723801637d9d726f45bd/src/GraphQL/Execution/ExecutionStrategy.cs#L636
The problem seems to be that the execution strategy is not awaiting the result and is trying to find the GraphType of Task instead of just T.
Our implementation broke after we upgraded GraphQL, here you can see the version of our packages:
Hope this gives you enough information to fix it
The text was updated successfully, but these errors were encountered: