Sha256: 9db5f0f111049405ed2483f9ce70c396140419dfe2aac3ac1bd07f81c43aa840

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require "active_support/core_ext/object/json"

require "graphql"
require "graphiti"
require "graphiti_graphql/version"
require "graphiti_graphql/graphiti_schema/wrapper"
require "graphiti_graphql/graphiti_schema/sideload"
require "graphiti_graphql/graphiti_schema/resource"
require "graphiti_graphql/errors"
require "graphiti_graphql/schema"
require "graphiti_graphql/runner"
require "graphiti_graphql/util"

Graphiti.class_eval do
  class << self
    attr_writer :graphql_schema
  end

  # TODO probably move these off of Graphiti
  def self.gql(query, variables)
    runner = ::GraphitiGraphQL::Runner.new
    runner.execute(query, variables, graphql_schema.schema)
  end

  def self.graphql_schema
    @graphql_schema ||= GraphitiGraphQL::Schema.generate
  end

  def self.graphql_schema?
    !!@graphql_schema
  end

  def self.graphql_schema!(entrypoint_resources = nil)
    @graphql_schema = GraphitiGraphQL::Schema.generate(entrypoint_resources)
  end
end

module GraphitiGraphQL
  class Error < StandardError; end

  class Configuration
    attr_accessor :schema_reloading

    def initialize
      self.schema_reloading = true
    end
  end

  class << self
    attr_accessor :schema_class
  end

  def self.config
    @config ||= Configuration.new
  end

  def self.define_context(&blk)
    @define_context = blk
  end

  def self.get_context
    obj = Graphiti.context[:object]
    if @define_context
      @define_context.call(obj)
    else
      {object: obj}
    end
  end
end

if defined?(::Rails)
  require "graphiti_graphql/engine"
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
graphiti_graphql-0.1.1 lib/graphiti_graphql.rb