我正在使用出色的graphql-ruby宝石(http://graphql-ruby.org/)。我有一个数据结构,该结构基本上将i18n字符串存储为哈希值:{'en': 'Hello', 'es': 'Hola'}
。在正常情况下效果很好。
但是,我们仅添加了简体中文和繁体中文,并带有“ zh-CN”和“ zh-TW”的语言代码。由于graphql-ruby翻译了camelCase中的所有输入字段,因此这些字段被翻译为'zh-cn'和'zh-tw'。
这是我的输入类的样子:
class CoreGql::InputTypes::I18nStringInput < GraphQL::Schema::InputObject
graphql_name "I18nStringInput"
argument :en, String, :required=>false
argument :es, String, :required=>false
argument :de, String, :required=>false
argument :fr, String, :required=>false
argument :is, String, :required=>false
argument :ja, String, :required=>false
argument :nl, String, :required=>false
argument 'zh-CN', String, :required=>false
argument 'zh-TW', String, :required=>false
end
是否有一种方法可以覆盖字段和/或参数的graphql-ruby命名约定?我希望它准确地是“ zh-CN”和“ zh-TW”。
答案 0 :(得分:1)
argument :'zh-CN', String, :required=>false, :camelize => false
可以转储您描述的架构。
但是,在GraphiQL上会出现错误:
Error: Names must match /^[_a-zA-Z][_a-zA-Z0-9]*$/ but "zh-CN" does not.
at assertValidName (http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:30302:11)
at http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:28613:44
at Array.forEach (<anonymous>)
at GraphQLInputObjectType._defineFieldMap (http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:28612:16)
at GraphQLInputObjectType.getFields (http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:28601:49)
at typeMapReducer (http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:29968:26)
at Array.reduce (<anonymous>)
at http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:29961:36
at Array.forEach (<anonymous>)
at typeMapReducer (http://localhost:3000/assets/graphiql/rails/graphiql-0.11.11.self-8e737fccee2b9e37d473d51a9032299b320e847f04671cb2030e717b0009b2c1.js?body=1:29954:27)
我认为最好将zh_CN
之类的名称与camelize: false
一起使用