Module: ElasticGraph::Apollo::SchemaDefinition::ApolloDirectives::Requires

Included in:
FieldExtension
Defined in:
elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/apollo_directives.rb

Overview

Supports Apollo’s @requires directive.

Instance Method Summary collapse

Instance Method Details

#apollo_requires(fields:) ⇒ void

This method returns an undefined value.

Adds the @requires directive to the schema element.

Examples:

Add @requires to a field

ElasticGraph.define_schema do |schema|
  schema.object_type "Product" do |t|
    t.field "size", "Int"
    t.field "weight", "Int"
    t.field "shippingEstimate", "String" do |f|
      f.apollo_requires fields: "size weight"
    end
  end
end

Parameters:

  • fields (String)

    A GraphQL selection set (provided as a string) of object fields and subfields that the subgraph can resolve only at this query path.



220
221
222
# File 'elasticgraph-apollo/lib/elastic_graph/apollo/schema_definition/apollo_directives.rb', line 220

def apollo_requires(fields:)
  directive "requires", fields: fields
end