当您在查询和突变中具有相同的概念时,是否有命名约定来避免GraphQL名称冲突?

问题描述 投票:0回答:1

我有以下架构:

type ProviderDetails{ ... }

type CustomerDetails{ ... }

type Provider{
 details: ProviderDetails!
}

type Customer{
 details: CustomerDetails!
}

input CustomerModReq{...}

type CustomerModResp{...}

type CustomerM{
 modifyDetails(update:CustomerModReq):CustomerModResp!
}

input ProviderModReq{...}
type ProviderModResp{...}
type ProviderM{
 modifyDetails(update:ProviderModReq):ProviderModResp!
}

type Query{
 provider(id: String): Provider!
 customer(id:String): Customer!
}

type Mutation{
 provider(id:String): ProviderM!
 customer(id:String): CustomerM!
}

我只是不确定M作为后缀是否真的很惯用。处理该命名问题的惯用方式是什么?

graphql naming-conventions naming
1个回答
0
投票

虽然尝试以这种方式命名您的变异名称不会违反规范,但它确实与既定的约定时期背道而驰,因此您不会在命名多余的类型时找到convention常规方法是用它们代表的任何操作来命名您的Mutation字段:

type Mutation {
  modifyCustomer
  modifyProvider
}

[当模式可能包含数十个或数百个字段时,通常会看到这样的命名:

type Mutation {
  customerAdd
  customerModify
  providerAdd
  providerModify
}

通常不建议使用单独的类型来命名突变,因为这不必要地使您的后端代码和客户端代码都变得复杂。例如,作为客户,如果我想批量处理变异调用并利用根级别字段是并行解析的事实,那么我不仅要使用别名,而且还必须为根字段加上别名以达到理想的效果。

© www.soinside.com 2019 - 2024. All rights reserved.