1

我正在使用出色的 graphql-ruby gem ( 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”。

4

1 回答 1

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)

我觉得最好使用 name like zh_CNwithcamelize: false

于 2018-12-04T06:19:48.097 回答