Module: ApolloFederation::Schema::CommonMethods

Defined in:
lib/apollo-federation/schema.rb

Constant Summary collapse

'federation'

Instance Method Summary collapse

Instance Method Details

#federation(version: '1.0', link: {}) ⇒ Object



19
20
21
22
# File 'lib/apollo-federation/schema.rb', line 19

def federation(version: '1.0', link: {})
  @federation_version = version
  @link = { as: DEFAULT_LINK_NAMESPACE }.merge(link)
end

#federation_2?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/apollo-federation/schema.rb', line 28

def federation_2?
  Gem::Version.new(federation_version.to_s) >= Gem::Version.new('2.0.0')
end

#federation_sdl(context: nil) ⇒ Object



32
33
34
35
36
37
38
# File 'lib/apollo-federation/schema.rb', line 32

def federation_sdl(context: nil)
  document_from_schema = FederatedDocumentFromSchemaDefinition.new(self, context: context)

  output = GraphQL::Language::Printer.new.print(document_from_schema.document)
  output.prepend(federation_2_prefix) if federation_2?
  output
end

#federation_versionObject



24
25
26
# File 'lib/apollo-federation/schema.rb', line 24

def federation_version
  @federation_version || find_inherited_value(:federation_version, '1.0')
end


40
41
42
# File 'lib/apollo-federation/schema.rb', line 40

def link_namespace
  @link ? @link[:as] : find_inherited_value(:link_namespace)
end

#query(new_query_object = nil) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/apollo-federation/schema.rb', line 44

def query(new_query_object = nil)
  return super if new_query_object.nil? && @query_object

  @orig_query_object = new_query_object
  federation_query_object = federation_query(original_query)
  federation_query_object.define_entities_field(schema_entities)

  super(federation_query_object)

  federation_query_object
end