Module: ElasticGraph::Apollo::SchemaDefinition::APIExtension

Defined in:
elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/api_extension.rb

Overview

Module designed to be extended onto an SchemaDefinition::API instance to customize the schema artifacts based on the Apollo Federation subgraph spec.

To use this module, pass it in schema_definition_extension_modules when defining your Local::RakeTasks.

Examples:

Define local rake tasks with this extension module

require "elastic_graph/apollo/schema_definition/api_extension"

ElasticGraph::Local::RakeTasks.new(
  local_config_yaml: "config/settings/local.yaml",
  path_to_schema: "config/schema.rb"
) do |tasks|
  tasks.schema_definition_extension_modules = [ElasticGraph::Apollo::SchemaDefinition::APIExtension]
end

Instance Method Summary collapse

Instance Method Details

#tag_built_in_types_with(name, except: []) ⇒ void

This method returns an undefined value.

Applies an apollo tag to built-in types so that they are included in the Apollo contract schema.

Examples:

Tag all built-in types (except two) for inclusion in the public schema

ElasticGraph.define_schema do |schema|
  schema.tag_built_in_types_with "public", except: ["IntAggregatedValue", "FloatAggregatedValues"]
end

Parameters:

  • name (String)

    tag name

  • except (Array<String>) (defaults to: [])

    built-in types not to tag

See Also:



82
83
84
85
86
87
88
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/api_extension.rb', line 82

def tag_built_in_types_with(name, except: [])
  except_set = except.to_set
  on_built_in_types do |type|
    apollo_type = (_ = type) # : ApolloDirectives::Tag
    apollo_type.apollo_tag(name: name) unless except_set.include?(type.name)
  end
end

#target_apollo_federation_version(version) ⇒ void

This method returns an undefined value.

Picks which version of Apollo federation to target. By default, the latest supported version is targeted, but you can call this to pick an earlier version, which may be necessary if your organization is on an older version of Apollo federation.

Examples:

Set the Apollo Federation Version

ElasticGraph.define_schema do |schema|
  schema.target_apollo_federation_version "2.6"
end

Parameters:

  • version (String)

    version number



101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/api_extension.rb', line 101

def target_apollo_federation_version(version)
  # Allow the version to have the `v` prefix, but don't require it.
  version = version.delete_prefix("v")

  state.apollo_directive_definitions = DIRECTIVE_DEFINITIONS_BY_FEDERATION_VERSION.fetch(version) do
    supported_version_descriptions = DIRECTIVE_DEFINITIONS_BY_FEDERATION_VERSION.keys.map do |version_number|
      "v#{version_number}"
    end.join(", ")

    raise Errors::SchemaError, "elasticgraph-apollo v#{ElasticGraph::VERSION} does not support Apollo federation v#{version}. " \
      "Pick one of the supported versions (#{supported_version_descriptions}) instead."
  end
end