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.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/virtualshield/rails-graphql/llms.txt
Use this file to discover all available pages before exploring further.
Basic Object Definition
You can define objects in dedicated files or inline within your schema.Implementing Interfaces
Objects can implement one or more interfaces, inheriting their field definitions and validation rules.Star Wars Example
By default, interface fields are automatically imported. To prevent this, use
implements 'InterfaceName', import_fields: falseField Resolution
Objects support multiple ways to resolve field values:Automatic Resolution
Fields automatically map to methods on the underlying data:Custom Resolvers
Method Names
Type Assignment
Assign objects to Ruby classes for automatic mapping:Valid Member Checking
Objects can validate if a given value is a valid member:- Matches the assigned type
- Has all required fields (non-null fields)
- Responds to field method names
Descriptions and Documentation
Add descriptions for introspection and documentation:Common Patterns
Query Fields
Mutation Returns
Nested Objects
Usage in Queries
Once defined, query objects in your GraphQL documents:Objects create the structure of your GraphQL API. Unlike scalars, they allow nested field selection.
Related Documentation
- Interfaces - Share fields across multiple objects
- Fields - Configure output fields
- Type Assignment - Map types to Ruby classes
- Sources - Connect objects to data sources