Sha256: 8898af8eb4e1af86f99fbf303812f13e55b38189698fed53f7b1292ddb4db72b

Contents?: true

Size: 1.81 KB

Versions: 24

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

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

    max_depth Ibrain::Config.graphql_max_depth
    query_analyzer(Ibrain::LogQueryDepth)

    # 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

24 entries across 24 versions & 1 rubygems

Version Path
ibrain-core-0.5.15 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.13 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.12 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.10 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.9 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.8 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.7 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.6 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.5 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.4 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.3 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.2 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.1 app/graphql/ibrain/base_schema.rb
ibrain-core-0.5.0 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.9 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.8 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.7 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.5 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.4 app/graphql/ibrain/base_schema.rb
ibrain-core-0.4.3 app/graphql/ibrain/base_schema.rb