Graphql-ruby: Fields with underscores not being handled properly when classing types

Created on 22 May 2018  路  3Comments  路  Source: rmosolgo/graphql-ruby

When I am using a field with an underscore, it is unable to resolve it on the type. The interesting thing is that this works fine when using the GraphQL::ObjectType.define {...} syntax.

Example:

class Types::RoomType < Types::BaseObject
  description "A room"

  field :id, ID, null: false
  field :name, String, null: false
  field :room_type, Integer, null: false
end

Where Types::BaseObject inherits from GraphQL::Schema::Object

The specific error being returned is "Field 'room_type' doesn't exist on type 'Room'".

Thanks for the help!

Most helpful comment

Can this new behavior be added to the changelog or to the new class based API page? It totally caught me off guard.

All 3 comments

The new default behavior is to camelize field and argument names, so that field is roomType. You can override this by passing camelize: false to field(...), or you can override it in your base class / method.

See camelize option:

http://graphql-ruby.org/api-doc/1.8.0/GraphQL/Schema/Field#initialize-instance_method

Feel free to reopen this if it doesn't work for you!

Got it! Thanks for the help!

Can this new behavior be added to the changelog or to the new class based API page? It totally caught me off guard.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hueter picture hueter  路  3Comments

ecomuere picture ecomuere  路  3Comments

theodorton picture theodorton  路  3Comments

skanev picture skanev  路  3Comments

jturkel picture jturkel  路  3Comments