Sha256: ffc690dd52268af99bf0d4dc54dc9e8219ef1b44026f47bd43afbd03c482c5df

Contents?: true

Size: 1.94 KB

Versions: 15

Compression:

Stored size: 1.94 KB

Contents

begin
  require "apollo-federation"
rescue LoadError
  raise "You must add the 'apollo-federation' gem to use GraphitiGraphQL federation"
end

begin
  require "graphql/batch"
rescue LoadError
  raise "You must add the 'graphql-batch' gem to use GraphitiGraphQL federation"
end

# We don't want to add these as dependencies,
# but do need to check things don't break
if Gem::Version.new(ApolloFederation::VERSION) >= Gem::Version.new("2.0.0")
  raise "graphiti_graphql federation is incompatible with apollo-federation >= 2"
end

if Gem::Version.new(GraphQL::Batch::VERSION) >= Gem::Version.new("1.0.0")
  raise "graphiti_graphql federation is incompatible with graphql-batch >= 1"
end

require "graphiti_graphql"
require "graphiti_graphql/federation/loaders/has_many"
require "graphiti_graphql/federation/loaders/belongs_to"
require "graphiti_graphql/federation/federated_resource"
require "graphiti_graphql/federation/federated_relationship"
require "graphiti_graphql/federation/resource_dsl"
require "graphiti_graphql/federation/apollo_federation_override"
require "graphiti_graphql/federation/schema_decorator"

module GraphitiGraphQL
  module Federation
    # * Extend Graphiti::Resource with federated_* macros
    # * Add apollo-federation modules to graphql-ruby base types
    # * Mark federation = true for checks down the line
    def self.setup!
      Graphiti::Resource.send(:include, ResourceDSL)
      schema = GraphitiGraphQL::Schema
      schema.base_field = Class.new(schema.base_field) do
        include ApolloFederation::Field
      end
      schema.base_object = Class.new(schema.base_object) do
        include ApolloFederation::Object
      end
      schema.base_object.field_class(schema.base_field)
      schema.base_interface = Module.new do
        include GraphQL::Schema::Interface
        include ApolloFederation::Interface
      end
      schema.base_interface.field_class(schema.base_field)
      GraphitiGraphQL::Schema.federation = true
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
graphiti_graphql-0.1.17 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.16 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.15 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.14 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.12 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.11 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.10 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.9 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.8 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.7 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.6 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.5 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.4 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.3 lib/graphiti_graphql/federation.rb
graphiti_graphql-0.1.2 lib/graphiti_graphql/federation.rb