graphql - 如何在 graphql dotnet 中使用 pascal 大小写代替 Camel 大小写

标签 graphql graphql-dotnet pascalcasing

这里我有一个突变,你可以看到参数名称是大写 P 的 Product,字段名称是大写 C 的 CreateProduct 当我从图形执行此突变时,我必须在驼峰外壳上写下字段的名称,并且还有参数的名称,有没有办法配置 graphql-dotnet 以尊重代码中编写的名称?

 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();
            }
        );


    }
}

最佳答案

您可以将 IFieldNameConverter 传递给 ExecutionOptions。默认使用CamelCaseFieldNameConverter

对于内省(introspection)类型需要一些特殊的考虑,因为根据 GraphQL 规范,这些类型需要采用驼峰式大小写。

GraphQL.NET 提供了 CamelCaseFieldNameConverterPascalCaseFieldNameConverterDefaultFieldNameConverter。您也可以自己编写。 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);
  }
}

关于graphql - 如何在 graphql dotnet 中使用 pascal 大小写代替 Camel 大小写,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55853230/

相关文章:

reactjs - React-Apollo Mutation 返回空响应

c# - 带有 List<Dictionary<string, string>> | 的 GraphQL.NET 突变JSON字符串

c# - 我可以在没有 Entity Framework 的情况下使用 graphql-dotnet 吗?

javascript - JS/C# 接口(interface)的 API 标准 - Camel 与 Pascal 案例

string - 如何在XSLT中将字符串格式化为Pascal大小写?

node.js - GraphQL 架构定义错误

javascript - Nexus-prisma:订购嵌套连接

c# - 为什么 graphql-dotnet 会为此模式返回 "Expected non-null value"错误?

sql - 内置函数将每个单词的首字母大写

GraphQL:许多小的变异,还是一个大的变异?