如何更改hotchocaly默认json序列化器

发布于 2025-01-22 10:02:08 字数 391 浏览 0 评论 0原文

如何更改Hotchocalate使用的JSON序列化器,我在文档中找不到任何东西。

我试图查看源代码,但似乎在httprespessextensions中进行了硬编码。

它使用骆驼盒,因此​​将我的所有模型更改在应用程序的前侧会很痛苦, 有什么想法吗?我认为团队意识到这一点: https://github.com/chillicream/chillicream/chillicream/hotchocaly/hotchocaly/hhotchocaly/问题/4072 但是我正在寻找解决方法

How can i change the json serializer used by hotchocalate i could not find anything in the documentation.

i tried to look at the source code but it seems like it hard coded in the HttpResponseExtensions .

its uses camel case so it will a pain to change all my models in the front side of the app ,
any ideas ? i think that the team is aware of this : https://github.com/ChilliCream/hotchocolate/issues/4072 but i'm looking for a workaround

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

怀里藏娇 2025-01-29 10:02:08

在寻找将案例与模型匹配的方法时,会遇到这个问题。就我而言,我想在查询输入和响应字段中保持外壳相同。

通过添加命名约定来覆盖默认符号范围:

public class NoCaseNamingConvention : DefaultNamingConventions
{
    public override NameString GetMemberName(MemberInfo member, MemberKind kind) {
        if (member == null)
            throw new ArgumentNullException(nameof(member));

        if ((kind == MemberKind.InputObjectField || kind == MemberKind.ObjectField) && member.MemberType == MemberTypes.Property)
            return member.Name;

        return base.GetMemberName(member, kind);
    }
}

并将约定添加到GraphQl:

services.AddGraphQLServer()
    .AddConvention<INamingConventions, NoCaseNamingConvention>()
    .RegisterDbContext<ApplicationContext>(DbContextKind.Pooled)
    .AddQueryType<Query>()
    .AddProjections()
    .AddFiltering()
    .AddSorting();

还值得注意的是,您可以更改数据中的顶级响应对象的名称:

public class Query
{
    [GraphQLName("Components")]
    [UseProjection]
    [UseFiltering]
    [UseSorting]
    public IQueryable<ComponentTable> GetComponents(ApplicationContext context) => context.Components;
}

​a>

希望这对人们有帮助:)

Came across this question when looking for a way of matching cases to Models. In my case I wanted to keep casings the same for the query input and response fields.

Got around this by adding a naming convention to override the DefaultNamingConventions:

public class NoCaseNamingConvention : DefaultNamingConventions
{
    public override NameString GetMemberName(MemberInfo member, MemberKind kind) {
        if (member == null)
            throw new ArgumentNullException(nameof(member));

        if ((kind == MemberKind.InputObjectField || kind == MemberKind.ObjectField) && member.MemberType == MemberTypes.Property)
            return member.Name;

        return base.GetMemberName(member, kind);
    }
}

And adding the Convention to the GraphQL:

services.AddGraphQLServer()
    .AddConvention<INamingConventions, NoCaseNamingConvention>()
    .RegisterDbContext<ApplicationContext>(DbContextKind.Pooled)
    .AddQueryType<Query>()
    .AddProjections()
    .AddFiltering()
    .AddSorting();

Also worth noting you can change the name of the top level response object in data:

public class Query
{
    [GraphQLName("Components")]
    [UseProjection]
    [UseFiltering]
    [UseSorting]
    public IQueryable<ComponentTable> GetComponents(ApplicationContext context) => context.Components;
}

Playground Before

Playground After

Hope this is helpful to folks :)

云裳 2025-01-29 10:02:08

模式具有Camescase Field命名的大会。您会返回Pascalcass的响应,并在骆驼案中询问。在客户案例不敏感的情况下进行反序列化,并且不要触摸客户端模型。

Schema has convention of camescase field naming. It would be wierd you return PascalCasing in response, and asking in camel case. Make deserialization in client case insensitive, and don't touch client models.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文