Sha256: b7b6623070d8662efb1d57b3055aefb97db96f72ac393466952a70e15b9237c0

Contents?: true

Size: 1.72 KB

Versions: 19

Compression:

Stored size: 1.72 KB

Contents

# frozen_string_literal: true

module Ibrain
  class BaseSchema < ::GraphQL::Schema
    use GraphQL::Batch

    # use GraphQL::Guard.new(
    #   policy_object: ::Ibrain::Config.graphql_policy.safe_constantize,
    #   not_authorized: ->(type, field) { raise IbrainErrors::PermissionError.new("You not have permission to access #{type}.#{field}") }
    # )

    # Union and Interface Resolution
    def self.resolve_type(_abstract_type, _obj, _ctx)
      # TODO: Implement this function
      # to return the correct object type for `obj`
      raise(GraphQL::RequiredImplementationMissingError)
    end

    # Relay-style Object Identification:

    # Return a string UUID for `object`
    def self.id_from_object(object, type_definition, query_ctx)
      # Here's a simple implementation which:
      # - joins the type name & object.id
      # - encodes it with base64:
      # GraphQL::Schema::UniqueWithinType.encode(type_definition.name, object.id)
    end

    # Given a string UUID, find the object
    def self.object_from_id(id, query_ctx)
      # For example, to decode the UUIDs generated above:
      # type_name, item_id = GraphQL::Schema::UniqueWithinType.decode(id)
      #
      # Then, based on `type_name` and `id`
      # find an object in your application
      # ...
    end

    def self.field(*args, camelize: false, **kwargs, &block)
      # if camelize == false
      #   # Also make a camelized field:
      #   field(*args, camelize: false, **kwargs, &block)
      # end
      super
    end

    rescue_from(ActiveRecord::RecordNotFound) do |_err, _obj, _args, _ctx, field|
      # Raise a graphql-friendly error with a custom message
      raise GraphQL::ExecutionError, "#{field.type.unwrap.graphql_name} not found"
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
ibrain-core-0.3.7.rc.pre.1 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.7 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.6.pre.rc.1 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.6 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.5 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.4 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.3.pre.rc.2 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.3.pre.rc.1 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.3 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.2.pre.rc.4 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.2.pre.rc.3 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.2.pre.rc app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.2 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.1 app/graphql/ibrain/base_schema.rb
ibrain-core-0.3.0 app/graphql/ibrain/base_schema.rb
ibrain-core-0.2.9 app/graphql/ibrain/base_schema.rb
ibrain-core-0.2.8 app/graphql/ibrain/base_schema.rb
ibrain-core-0.2.7 app/graphql/ibrain/base_schema.rb
ibrain-core-0.2.6 app/graphql/ibrain/base_schema.rb