Sha256: b4485a7b70c5bd5f593da5603c25fd5816d3207a3b4037443ccf3eeb54334323

Contents?: true

Size: 1.92 KB

Versions: 5

Compression:

Stored size: 1.92 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"

module GraphitiGraphQL
  class Configuration
    attr_accessor :schema_reloading, :federation_application_controller

    def initialize
      self.schema_reloading = true
    end

    def define_context(&blk)
      @define_context = blk
    end

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

  module Runnable
    def gql(query, variables)
      runner = ::GraphitiGraphQL::Runner.new
      runner.execute(query, variables, GraphitiGraphQL.schemas.graphql)
    end
  end

  class SchemaProxy
    def graphql
      generated.schema
    end

    def graphiti
      generated.graphiti_schema
    end

    def generated
      @generated ||= GraphitiGraphQL::Schema.generate
    end

    # resources: All resources to put in the schema. Mostly just for testing.
    # entrypoints: All resources to expose as top-level query objects
    def generate!(resources: nil, entrypoints: nil)
      @generated = GraphitiGraphQL::Schema
        .generate(resources: resources, entrypoints: entrypoints)
    end

    def generated?
      !!@generated
    end

    def clear!
      @generated = nil
    end
  end

  class << self
    attr_accessor :schema_class
  end

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

  def self.configure
    yield config
  end

  def self.schemas
    @schemas ||= SchemaProxy.new
  end
end

Graphiti.extend(GraphitiGraphQL::Runnable)

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

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
graphiti_graphql-0.1.17 lib/graphiti_graphql.rb
graphiti_graphql-0.1.16 lib/graphiti_graphql.rb
graphiti_graphql-0.1.15 lib/graphiti_graphql.rb
graphiti_graphql-0.1.14 lib/graphiti_graphql.rb
graphiti_graphql-0.1.12 lib/graphiti_graphql.rb