graphql hotchoc using ResolveWith
Using resolveWith might be a good use-case for you. You can use it with the following code example,
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// setting up and using resolver | |
builder.Services.AddGraphQLServer().AddQueryType<FooQueryType>(); | |
// another class - wiring up | |
public class FooQueryType : ObjectType | |
{ | |
protected override void Configure(IObjectTypeDescriptor descriptor) | |
{ | |
descriptor | |
.Field("foo") | |
.Argument("arg", a => a.Type<NonNullType<StringType>>()) | |
.ResolveWith<FooResolvers>(r => r.GetFoo(default)); | |
} | |
} | |
// Then you have your resolvers | |
public class FooResolvers | |
{ | |
public string GetFoo(string arg) | |
{ | |
return "magicfoo"; | |
} | |
} | |
} |
Then to run your query
query {
foo(arg:"")
}
Comments