Define GraphQL object types with fields to organize and structure your data
Objects are the principal building blocks of GraphQL schemas. They represent structured data with named fields, each returning a specific type. Objects create branches in the GraphQL tree, allowing you to organize and access your data hierarchically.
Objects can implement one or more interfaces, inheriting their field definitions and validation rules.
Star Wars Example
object 'Human' do self.assigned_to = MemoryTest::Human implements 'Character' desc 'A humanoid creature in the Star Wars universe' # Interface fields are automatically imported # Add object-specific fields field :home_planet, :string, desc: 'The home planet of the human, or null if unknown' field :greeting, :string, desc: 'A greeting phrase from this person to someone', arguments: arg(:name, :string, null: false)end
By default, interface fields are automatically imported. To prevent this, use implements 'InterfaceName', import_fields: false
Add descriptions for introspection and documentation:
object 'User' do desc 'A registered user in the system' field :id, null: false, desc: 'Unique identifier for the user' field :email, desc: 'Primary email address'end