Skip to content

Custom Types

For types that don’t map directly to a resource (enums, inputs, value objects, etc.), drop them in app/graphql/types/.

Quail provides Quail::Object (aliased to GraphQL::Schema::Object) and Quail::Mutation (aliased to GraphQL::Schema::RelayClassicMutation) so you don’t need to reference graphql-ruby base classes directly.

app/graphql/types/address_type.rb
class Types::AddressType < Quail::Object
graphql_name "Address"
field :street, String, null: false
field :city, String, null: false
field :state, String, null: true
field :zip, String, null: false
end

You can then reference these types in your resources via computed attributes:

class UserResource
include Quail::Resource
attributes :id, :name
attribute :address, type: Types::AddressType, null: true do |user|
user.address # returns an object that responds to street, city, etc.
end
end

If you want all auto-generated Quail types to inherit from a custom base class, set it in the initializer:

app/graphql/types/base_object.rb
class Types::BaseObject < Quail::Object
end
config/initializers/quail.rb
Quail.base_object_class = Types::BaseObject