class ApolloFederation::FederatedDocumentFromSchemaDefinition

Constants

FEDERATION_QUERY_FIELDS
FEDERATION_TYPES

Public Instance Methods

build_field_node(field_type) click to toggle source
Calls superclass method
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 34
def build_field_node(field_type)
  field_node = super
  merge_directives(field_node, field_type)
end
build_interface_type_node(interface_type) click to toggle source
Calls superclass method
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 29
def build_interface_type_node(interface_type)
  field_node = super
  merge_directives(field_node, interface_type)
end
build_object_type_node(object_type) click to toggle source
Calls superclass method
# 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_type_definition_nodes(types) click to toggle source
Calls superclass method
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 39
def build_type_definition_nodes(types)
  non_federation_types = types.select do |type|
    if query_type?(type)
      !type.fields.values.all? { |field| FEDERATION_QUERY_FIELDS.include?(field.graphql_name) }
    else
      !FEDERATION_TYPES.include?(type.graphql_name)
    end
  end
  super(non_federation_types)
end

Private Instance Methods

build_arguments_node(arguments) click to toggle source
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 74
def build_arguments_node(arguments)
  (arguments || []).map do |arg|
    GraphQL::Language::Nodes::Argument.new(name: arg[:name], value: arg[:values])
  end
end
merge_directives(node, type) click to toggle source
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 56
def merge_directives(node, type)
  if type.is_a?(ApolloFederation::HasDirectives)
    directives = type.federation_directives
  elsif type.is_a?(GraphQL::Define::InstanceDefinable)
    directives = type.metadata[:federation_directives]
  else
    directives = []
  end

  (directives || []).each do |directive|
    node = node.merge_directive(
      name: directive[:name],
      arguments: build_arguments_node(directive[:arguments]),
    )
  end
  node
end
query_type?(type) click to toggle source
# File lib/apollo-federation/federated_document_from_schema_definition.rb, line 52
def query_type?(type)
  type == warden.root_type_for_operation('query')
end