graphql - 在 GraphQL Schema 中使用数字作为键?

标签 graphql apollo-server

您可以使用 GraphQL Schema Language 将数字用作 GraphQL Schema 中的键吗?即(这是一个小片段......)

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:
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
}

最佳答案

不,这是specification 禁止的。 .可以用下划线作为数字前缀:

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
}

或者根本不在类型级别执行此操作,而是映射查询或简单地运行过滤器查询:
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) }

关于graphql - 在 GraphQL Schema 中使用数字作为键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52265518/

相关文章:

python-3.x - 如何发送包含扩展查询的 graphQL 查询?

python - 是否有可能将对象数组(json)作为突变的输入字段传递? Graphite 烯- python

facebook - 我可以在 Facebook Graph API 中查询可选字段吗?

vue.js - 为什么需要 graphql-tag 才能将 Apollo 与 Nuxt 结合使用?

passport.js - 更新 nestjs/graphql 后不通过标题

graphql - ApolloServer 不触发自定义指令

node.js - 如何将 cookie 从 apollo-server 传递到 apollo-clenet

graphql - 如何使用 DataLoader 与 Hot Chocolate GraphQL 进行连接

javascript - ES6 中函数后面的模板文字(反引号)的用途是什么?

graphql - 如何使用 Apollo GraphQL 查询结果作为另一个查询的输入?又名 : request chaining