在 GraphQL Schema 中使用数字作为键? [英] Use number as key in GraphQL Schema?
本文介绍了在 GraphQL Schema 中使用数字作为键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您可以使用 GraphQL Schema Language 将数字用作 GraphQL Schema 中的键吗?即(这是一个小片段......)
Can you use numbers as a key in GraphQL Schema using the GraphQL Schema Language? i.e. (this is a small snippet...)
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
}
OR 下面,我意识到这是不正确的 JSON:
OR the below, which I realise is incorrect 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
}
推荐答案
不,这是被 规范.可以在数字前加上下划线:
No, this is forbidden by the specification. It is possible to prefix the numbers with an underscore:
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
}
或者根本不在类型级别执行此操作,而是映射查询或简单地运行过滤器查询:
Or alternatively not do this on the type level at all and instead map the query or simply run a filter 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 Schema 中使用数字作为键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文