我正在使用graphql-dotnet和graphql服务器和asp.net内核.我已经按照以下方式配置了模式。
public class PdsGraphQlSchema: Schema
{
public PdsGraphQlSchema()
{
FieldNameConverter = new PascalCaseFieldNameConverter();
Query = CommonServiceLocator.ServiceLocator.Current.GetInstance<GraphQlQueries>();
Mutation = CommonServiceLocator.ServiceLocator.Current.GetInstance<GraphQlMutations>();
}
}在这里,我添加了FieldNameConverter = new PascalCaseFieldNameConverter();但是在输出时没有得到更改。输出总是camelCased。我怎么可以忽略骆驼套管或使用帕斯卡尔套管。
对于ConfigureServices,我使用了以下方法
services.AddGraphQL(_ =>
{
_.EnableMetrics = true;
_.ExposeExceptions = true;
});services.AddSingleton();
在Configure内部,我使用了以下方法
app.UseGraphQL<PdsGraphQlSchema>();
app.UseGraphQLPlayground(new GraphQLPlaygroundOptions
{ Path = "/ui/playground" });期待你的帮助。
发布于 2018-11-27 09:36:24
对于这个问题,它是由DefaultGraphQLExecuter没有在GetOptions中设置FieldNameConverter引起的。
尝试下面的解决方案:
DefaultGraphQLExecuter.public类MyDefaultGraphQLExecuter : DefaultGraphQLExecuter TSchema : ISchema { public MyDefaultGraphQLExecuter(TSchema模式、IDocumentExecuter documentExecuter、IOptions options、IEnumerable侦听器、IEnumerable validationRules):基(模式、documentExecuter、选项、侦听器、validationRules) {}受保护的重写ExecutionOptions ExecutionOptions(字符串查询、字符串查询、输入变量、对象上下文、){ var options =(、查询、变量、上下文、);=;返回选项;}}DefaultGraphQLExecuter
services.AddGraphQL(options => { options.EnableMetrics = true;options.ExposeExceptions = Environment.IsDevelopment();//options )。)( services.AddTransient(typeof(IGraphQLExecuter<>),typeof(MyDefaultGraphQLExecuter<>));发布于 2021-04-14 17:29:42
必须在架构中使用from NameConverter字段。
public class AppSchema : Schema
{
public AppSchema(IServiceProvider provider)
: base(provider)
{
NameConverter = new GraphQL.Conversion.DefaultNameConverter();
Query = new AppQuery();
Mutation = new AppMutation();
}
}你有三个选择
1- DefaultFieldNameConverter()没有变化,您可以看到在输出中所写的内容
2- PascalCaseFieldNameConverter()在all First Charecter to Lowercase中
3- CamelCaseFieldNameConverter()在all First Charecter to Lowercase中
https://stackoverflow.com/questions/53465161
复制相似问题