Custom Types
Overview
Section titled “Overview”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.
Defining a Custom Type
Section titled “Defining a Custom Type”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: falseendYou 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. endendCustom Base Class Configuration
Section titled “Custom Base Class Configuration”If you want all auto-generated Quail types to inherit from a custom base class, set it in the initializer:
class Types::BaseObject < Quail::ObjectendQuail.base_object_class = Types::BaseObject