Module: ElasticGraph::Apollo::SchemaDefinition::ApolloDirectives::Key

Included in:
InterfaceTypeExtension, ObjectTypeExtension
Defined in:
elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/apollo_directives.rb

Overview

Supports Apollo’s @key directive.

Instance Method Summary collapse

Instance Method Details

#apollo_key(fields:, resolvable: true) ⇒ void

Note:

ElasticGraph automatically defines an apollo_key of id for every indexed type. This API is only needed when defining additional keys on an indexed type, or defining a key for a non-indexed type.

This method returns an undefined value.

Adds the @key directive to the schema element.

Examples:

Define a @key on a non-indexed type

ElasticGraph.define_schema do |schema|
  schema.object_type "Campaign" do |t|
    t.field "organizationId", "ID"
    t.field "id", "ID"
    t.apollo_key fields: "id organizationId", resolvable: false
  end
end

Parameters:

  • fields (String)

    A GraphQL selection set (provided as a string) of fields and subfields that contribute to the entity’s unique key.

  • resolvable (Boolean) (defaults to: true)

    If false, indicates to the Apollo router that this subgraph doesn’t define a reference resolver for this entity. This means that router query plans can’t “jump to” this subgraph to resolve fields that aren’t defined in another subgraph.



129
130
131
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/apollo_directives.rb', line 129

def apollo_key(fields:, resolvable: true)
  directive "key", fields: fields, resolvable: resolvable
end