首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在GraphQL模式中使用数字作为键吗?

在GraphQL模式中使用数字作为键吗?
EN

Stack Overflow用户
提问于 2018-09-10 21:09:44
回答 1查看 1.9K关注 0票数 6

您能否使用GraphQL架构语言将数字用作GraphQL架构中的键?也就是说(这是一个小片段.)

代码语言:javascript
复制
type tax_code_allocation_country_KOR_states {
  "11": tax_code_allocation_state_tax_query
  "26": tax_code_allocation_state_tax_query
  "27": tax_code_allocation_state_tax_query
}

或者下面,我意识到这是不正确的JSON:

代码语言:javascript
复制
type tax_code_allocation_country_KOR_states {
  11: tax_code_allocation_state_tax_query
  26: tax_code_allocation_state_tax_query
  27: tax_code_allocation_state_tax_query
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-09-10 22:18:28

不,这是规格说明禁止的。可以在数字前面加上下划线:

代码语言:javascript
复制
type tax_code_allocation_country_KOR_states {
  _11: tax_code_allocation_state_tax_query
  _26: tax_code_allocation_state_tax_query
  _27: tax_code_allocation_state_tax_query
}

或者根本不在类型级别执行此操作,而是映射查询或简单地运行筛选器查询:

代码语言:javascript
复制
type tax_code_allocation_country_KOR_states {
  tax(code: 11): tax_code_allocation_state_tax_query
  tax(codes: [11, 26, 27]): [tax_code_allocation_state_tax_query]
}

# query subselection
{ _11: tax(code: 11), _26: tax(code: 26), _27: tax(code: 27) }
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52265518

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档