Class: ApolloFederation::FederatedDocumentFromSchemaDefinition

Inherits:
GraphQL::Language::DocumentFromSchemaDefinition
  • Object
show all
Defined in:
lib/apollo-federation/federated_document_from_schema_definition.rb

Constant Summary collapse

FEDERATION_TYPES =
[
  '_Any',
  '_Entity',
  '_Service',
].freeze
FEDERATION_QUERY_FIELDS =
[
  '_entities',
  '_service',
].freeze

Instance Method Summary collapse

Instance Method Details

#build_argument_node(argument_type) ⇒ Object



59
60
61
62
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 59

def build_argument_node(argument_type)
  argument_node = super
  merge_directives(argument_node, argument_type)
end

#build_enum_type_node(enum_type) ⇒ Object



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

def build_enum_type_node(enum_type)
  enum_node = super
  merge_directives(enum_node, enum_type)
end

#build_enum_value_node(enum_value_type) ⇒ Object



44
45
46
47
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 44

def build_enum_value_node(enum_value_type)
  enum_value_node = super
  merge_directives(enum_value_node, enum_value_type)
end

#build_field_node(field_type) ⇒ Object



64
65
66
67
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 64

def build_field_node(field_type)
  field_node = super
  merge_directives(field_node, field_type)
end

#build_input_object_node(input_object_type) ⇒ Object



54
55
56
57
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 54

def build_input_object_node(input_object_type)
  input_object_node = super
  merge_directives(input_object_node, input_object_type)
end

#build_interface_type_node(interface_type) ⇒ Object



29
30
31
32
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 29

def build_interface_type_node(interface_type)
  interface_node = super
  merge_directives(interface_node, interface_type)
end

#build_object_type_node(object_type) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 18

def build_object_type_node(object_type)
  object_node = super
  if query_type?(object_type)
    federation_fields = object_node.fields.select do |field|
      FEDERATION_QUERY_FIELDS.include?(field.name)
    end
    federation_fields.each { |field| object_node = object_node.delete_child(field) }
  end
  merge_directives(object_node, object_type)
end

#build_scalar_type_node(scalar_type) ⇒ Object



49
50
51
52
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 49

def build_scalar_type_node(scalar_type)
  scalar_node = super
  merge_directives(scalar_node, scalar_type)
end

#build_type_definition_nodes(types) ⇒ Object



69
70
71
72
73
74
75
76
77
78
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 69

def build_type_definition_nodes(types)
  non_federation_types = types.select do |type|
    if query_type?(type)
      !warden.fields(type).all? { |field| FEDERATION_QUERY_FIELDS.include?(field.graphql_name) }
    else
      !FEDERATION_TYPES.include?(type.graphql_name)
    end
  end
  super(non_federation_types)
end

#build_union_type_node(union_type) ⇒ Object



34
35
36
37
# File 'lib/apollo-federation/federated_document_from_schema_definition.rb', line 34

def build_union_type_node(union_type)
  union_node = super
  merge_directives(union_node, union_type)
end