如何覆盖 graphql-ruby 中的驼峰命名约定?
How can I override the camelCase naming convention in graphql-ruby?
我正在使用优秀的 graphql-ruby gem (http://graphql-ruby.org/)。我有一个数据结构,它基本上将 i18n 字符串存储为散列:{'en': 'Hello', 'es': 'Hola'}
。正常情况下效果很好。
不过,我们只是添加了简体中文和繁体中文,语言代码为'zh-CN'和'zh-TW'。由于 graphql-ruby 将所有输入字段翻译为驼峰式,这些字段将被翻译为 'zh-cn' 和 'zh-tw'.
这是我的输入 class 的样子:
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
有没有办法覆盖字段 and/or 参数的 graphql-ruby 命名约定?我希望它完全是 'zh-CN' 和 'zh-TW'。
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
比较好
我正在使用优秀的 graphql-ruby gem (http://graphql-ruby.org/)。我有一个数据结构,它基本上将 i18n 字符串存储为散列:{'en': 'Hello', 'es': 'Hola'}
。正常情况下效果很好。
不过,我们只是添加了简体中文和繁体中文,语言代码为'zh-CN'和'zh-TW'。由于 graphql-ruby 将所有输入字段翻译为驼峰式,这些字段将被翻译为 'zh-cn' 和 'zh-tw'.
这是我的输入 class 的样子:
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
有没有办法覆盖字段 and/or 参数的 graphql-ruby 命名约定?我希望它完全是 'zh-CN' 和 'zh-TW'。
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