Class: ElasticGraph::SchemaDefinition::API
- Inherits:
-
Object
- Object
- ElasticGraph::SchemaDefinition::API
- Defined in:
- elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb
Overview
Root API object that provides the schema definition API.
Instance Attribute Summary collapse
-
#factory ⇒ Factory
readonly
Object responsible for instantiating all schema element classes.
-
#state ⇒ State
readonly
Object which holds all state for the schema definition.
Instance Method Summary collapse
-
#deleted_type(name) ⇒ void
Registers the name of a type that existed in a prior version of the schema but has been deleted.
-
#enum_type(name) {|SchemaElements::EnumType| ... } ⇒ void
Defines a GraphQL enum type.
-
#interface_type(name) {|SchemaElements::InterfaceType| ... } ⇒ void
Defines a GraphQL interface.
-
#json_schema_version(version) ⇒ void
Defines the version number of the current JSON schema.
-
#object_type(name) {|SchemaElements::ObjectType| ... } ⇒ void
Defines a GraphQL object type Use it to define a concrete type that has subfields.
-
#on_built_in_types {|SchemaElements::EnumType, SchemaElements::InputType, SchemaElements::InterfaceType, SchemaElements::ObjectType, SchemaElements::ScalarType, SchemaElements::UnionType| ... } ⇒ void
Registers a customization callback that will be applied to every built-in type automatically provided by ElasticGraph.
-
#raw_sdl(string) ⇒ void
Defines a raw GraphQL SDL snippet that will be included in the generated
schema.graphql
artifact. -
#register_graphql_extension(extension_module, defined_at:, **extension_config) ⇒ void
Registers a GraphQL extension module that will be loaded and used by
elasticgraph-graphql
. -
#results ⇒ Object
The results of the schema definition.
-
#scalar_type(name) {|SchemaElements::ScalarType| ... } ⇒ void
Defines a GraphQL scalar type.
-
#union_type(name) {|SchemaElements::UnionType| ... } ⇒ void
Defines a GraphQL union type.
Instance Attribute Details
#factory ⇒ Factory (readonly)
Returns object responsible for instantiating all schema element classes.
51 52 53 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 51 def factory @factory end |
#state ⇒ State (readonly)
Returns object which holds all state for the schema definition.
48 49 50 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 48 def state @state end |
Instance Method Details
#deleted_type(name) ⇒ void
In situations where this API applies, ElasticGraph will give you an error message indicating that you need to use this API or SchemaElements::TypeWithSubfields#renamed_from. Likewise, when ElasticGraph no longer needs to know about this, it’ll give you a warning indicating the call to this method can be removed.
This method returns an undefined value.
Registers the name of a type that existed in a prior version of the schema but has been deleted.
261 262 263 264 265 266 267 268 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 261 def deleted_type(name) @state.register_deleted_type( name, defined_at: caller_locations(1, 1).first, # : ::Thread::Backtrace::Location defined_via: %(schema.deleted_type "#{name}") ) nil end |
#enum_type(name) {|SchemaElements::EnumType| ... } ⇒ void
This method returns an undefined value.
Defines a GraphQL enum type.
The type is restricted to an enumerated set of values, each with a unique name.
Use value
or values
to define the enum values in the passed block.
Note: if required by your configuration, this may generate a pair of Enum types (an input enum and an output enum).
193 194 195 196 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 193 def enum_type(name, &block) @state.register_enum_type @factory.new_enum_type(name.to_s, &block) nil end |
#interface_type(name) {|SchemaElements::InterfaceType| ... } ⇒ void
This method returns an undefined value.
Defines a GraphQL interface. Use it to define an abstract supertype with one or more fields that concrete implementations of the interface must also define. Each implementation can be an SchemaElements::ObjectType or SchemaElements::InterfaceType.
162 163 164 165 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 162 def interface_type(name, &block) @state.register_object_interface_or_union_type @factory.new_interface_type(name.to_s, &block) nil end |
#json_schema_version(version) ⇒ void
While this is an important part of how ElasticGraph is designed to support schema evolution, it can be annoying constantly
have to increment this while rapidly changing the schema during prototyping. You can disable the requirement to increment this
on every JSON schema change by setting enforce_json_schema_version
to false
in your Rakefile
.
This method returns an undefined value.
Defines the version number of the current JSON schema. Importantly, every time a change is made that impacts the JSON schema artifact, the version number must be incremented to ensure that each different version of the JSON schema is identified by a unique version number. The publisher will then include this version number in published events to identify the version of the schema it was using. This avoids the need to deploy the publisher and ElasticGraph indexer at the same time to keep them in sync.
315 316 317 318 319 320 321 322 323 324 325 326 327 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 315 def json_schema_version(version) if !version.is_a?(Integer) || version < 1 raise Errors::SchemaError, "`json_schema_version` must be a positive integer. Specified version: #{version}" end if @state.json_schema_version raise Errors::SchemaError, "`json_schema_version` can only be set once on a schema. Previously-set version: #{@state.json_schema_version}" end @state.json_schema_version = version @state.json_schema_version_setter_location = caller_locations(1, 1).to_a.first nil end |
#object_type(name) {|SchemaElements::ObjectType| ... } ⇒ void
This method returns an undefined value.
Defines a GraphQL object type Use it to define a concrete type that
has subfields. Object types can either be indexed (e.g. directly indexed in the datastore, and available to query from the
root Query
object) or embedded in other indexed types.
128 129 130 131 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 128 def object_type(name, &block) @state.register_object_interface_or_union_type @factory.new_object_type(name.to_s, &block) nil end |
#on_built_in_types {|SchemaElements::EnumType, SchemaElements::InputType, SchemaElements::InterfaceType, SchemaElements::ObjectType, SchemaElements::ScalarType, SchemaElements::UnionType| ... } ⇒ void
This method returns an undefined value.
Registers a customization callback that will be applied to every built-in type automatically provided by ElasticGraph. Provides an opportunity to customize the built-in types (e.g. to add directives to them or whatever).
341 342 343 344 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 341 def on_built_in_types(&customization_block) @state.built_in_types_customization_blocks << customization_block nil end |
#raw_sdl(string) ⇒ void
This method returns an undefined value.
Defines a raw GraphQL SDL snippet that will be included in the generated schema.graphql
artifact. Designed to be an escape hatch,
for when ElasticGraph doesn’t provide another way to write some type of GraphQL SDL element that you need. Currently, the only
known use case is to define custom GraphQL directives.
99 100 101 102 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 99 def raw_sdl(string) @state.sdl_parts << string nil end |
#register_graphql_extension(extension_module, defined_at:, **extension_config) ⇒ void
This method returns an undefined value.
Registers a GraphQL extension module that will be loaded and used by elasticgraph-graphql
. While such
extension modules can also be configured in a settings YAML file, it can be useful to register it here
when you want to ensure that the extension is used in all environments. For example, an extension library
that defines custom schema elements (such as elasticgraph-apollo
) may need to ensure its corresponding
GraphQL extension module is used since the custom schema elements would not work correctly otherwise.
288 289 290 291 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 288 def register_graphql_extension(extension_module, defined_at:, **extension_config) @state.graphql_extension_modules << SchemaArtifacts::RuntimeMetadata::Extension.new(extension_module, defined_at, extension_config) nil end |
#results ⇒ Object
Returns the results of the schema definition.
294 295 296 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 294 def results @results ||= Results.new(@state) end |
#scalar_type(name) {|SchemaElements::ScalarType| ... } ⇒ void
This method returns an undefined value.
Defines a GraphQL scalar type. ElasticGraph itself uses this to define a few
common scalar types (e.g. Date
and DateTime
), but it is also available to you to use to define your own custom scalar types.
243 244 245 246 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 243 def scalar_type(name, &block) @state.register_scalar_type @factory.new_scalar_type(name.to_s, &block) nil end |
#union_type(name) {|SchemaElements::UnionType| ... } ⇒ void
This method returns an undefined value.
Defines a GraphQL union type. Use it to define an abstract supertype with one or more concrete subtypes. Each subtype must be an SchemaElements::ObjectType, but they do not have to share any fields in common.
224 225 226 227 |
# File 'elasticgraph-schema_definition/lib/elastic_graph/schema_definition/api.rb', line 224 def union_type(name, &block) @state.register_object_interface_or_union_type @factory.new_union_type(name.to_s, &block) nil end |