here I have a mutation, as you can see the parameter name is Product with capital P and the field name is CreateProduct with capital C when I execute this mutation from graphical I have to write the name of the field on camel casing and also the name of the parameter, is there a way to configure graphql-dotnet to respect the names as they are written in the code?
const string STR_Product = "Product";
public Mutations(IProductService ProductService)
{
Name = "Mutation";
Field<ProductType>(
"CreateProduct",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<ProductInputType>> { Name = STR_Product }),
resolve: context =>
{
var ProductInput = context.GetArgument<ProductInput>(STR_Product);
return ProductService.CreateAsync(ProductInput.Code, ProductInput.Name, ProductInput.Description);
//return new ProductInputType();
}
);
}
}
You can pass a IFieldNameConverter
to the ExecutionOptions
. It defaults to using CamelCaseFieldNameConverter
.
Some special considerations are needed for the Introspection types, as those are required to be camel case according to the GraphQL Specification.
GraphQL.NET provides CamelCaseFieldNameConverter
, PascalCaseFieldNameConverter
, and DefaultFieldNameConverter
. You could also write your own. Source found here.
using System;
using GraphQL;
using GraphQL.Types;
public class Program
{
public static void Main(string[] args)
{
var schema = Schema.For(@"
type Query {
Hello: String
}
");
var json = schema.Execute(_ =>
{
_.Query = "{ Hello }";
_.Root = new { Hello = "Hello World!" };
_.FieldNameConverter = new DefaultFieldNameConverter();
});
Console.WriteLine(json);
}
}