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/

相关文章:

scala - 为任意 JSON 创建 `Decoder`

node.js - 如何在保持对请求对象的访问的同时对express-graphql解析器进行依赖注入(inject)?

asp.net - 使用 Relay 和 graphql-dotnet 上传文件

将文本格式化为 Pascal 或 Camel 大小写的算法

angular - 使用 angular-apollo graphql 客户端获取 404 Not Found

java - 将多个 graphQL 模式文件映射到单独的解析器 - Spring Boot

c# - 如何处理每个资源的多个查询?

c# - 带有 GraphQL 的 EF 核心

groovy - PascalCase 中的第一个单词为小写