Class: ElasticGraph::GraphQL::Schema
- Inherits:
-
Object
- Object
- ElasticGraph::GraphQL::Schema
- Defined in:
- lib/elastic_graph/graphql/schema.rb,
lib/elastic_graph/graphql/schema/type.rb,
lib/elastic_graph/graphql/schema/field.rb,
lib/elastic_graph/graphql/schema/arguments.rb,
lib/elastic_graph/graphql/schema/enum_value.rb,
lib/elastic_graph/graphql/schema/relation_join.rb
Defined Under Namespace
Modules: Arguments Classes: EnumValue, Field, LazyResolverAdapter, RelationJoin, Type
Constant Summary collapse
- BUILT_IN_TYPE_NAMES =
( scalar_types = ::GraphQL::Schema::BUILT_IN_TYPES.keys # Int, ID, String, etc introspection_types = ::GraphQL::Schema.types.keys # __Type, __Schema, etc scalar_types.to_set.union(introspection_types) )
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#defined_types ⇒ Object
readonly
Returns the value of attribute defined_types.
-
#element_names ⇒ Object
readonly
Returns the value of attribute element_names.
-
#graphql_schema ⇒ Object
readonly
Returns the value of attribute graphql_schema.
-
#runtime_metadata ⇒ Object
readonly
Returns the value of attribute runtime_metadata.
Instance Method Summary collapse
- #document_type_stored_in(index_definition_name) ⇒ Object
- #enum_value_named(type_name, enum_value_name) ⇒ Object
- #field_named(type_name, field_name) ⇒ Object
-
#indexed_document_types ⇒ Object
The list of user-defined types that are indexed document types.
-
#initialize(graphql_schema_string:, config:, runtime_metadata:, index_definitions_by_graphql_type:, graphql_gem_plugins:, &build_resolver) ⇒ Schema
constructor
A new instance of Schema.
- #to_s ⇒ Object (also: #inspect)
- #type_from(graphql_type) ⇒ Object
-
#type_named(type_name) ⇒ Object
Note: this does not support “wrapped” types (e.g. ‘Int!` or `[Int]` compared to `Int`), as the graphql schema object does not give us an index of those by name.
Constructor Details
#initialize(graphql_schema_string:, config:, runtime_metadata:, index_definitions_by_graphql_type:, graphql_gem_plugins:, &build_resolver) ⇒ Schema
Returns a new instance of Schema.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/elastic_graph/graphql/schema.rb', line 34 def initialize( graphql_schema_string:, config:, runtime_metadata:, index_definitions_by_graphql_type:, graphql_gem_plugins:, &build_resolver ) @element_names = .schema_element_names @config = config = @types_by_graphql_type = Hash.new do |hash, key| hash[key] = Type.new( self, key, index_definitions_by_graphql_type[key.graphql_name] || [], .object_types_by_name[key.graphql_name], .enum_types_by_name[key.graphql_name] ) end @types_by_name = Hash.new { |hash, key| hash[key] = lookup_type_by_name(key) } @build_resolver = build_resolver # Note: as part of loading the schema, the GraphQL gem may use the resolver (such # when a directive has a custom scalar) so we must wait to instantiate the schema # as late as possible here. If we do this before initializing some of the instance # variables above we'll get `NoMethodError` on `nil`. @graphql_schema = ::GraphQL::Schema.from_definition( graphql_schema_string, default_resolve: LazyResolverAdapter.new(method(:resolver)), using: graphql_gem_plugins ) # Pre-load all defined types so that all field extras can get configured as part # of loading the schema, before we execute the first query. @defined_types = build_defined_types_array(@graphql_schema) end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
32 33 34 |
# File 'lib/elastic_graph/graphql/schema.rb', line 32 def config @config end |
#defined_types ⇒ Object (readonly)
Returns the value of attribute defined_types.
32 33 34 |
# File 'lib/elastic_graph/graphql/schema.rb', line 32 def defined_types @defined_types end |
#element_names ⇒ Object (readonly)
Returns the value of attribute element_names.
32 33 34 |
# File 'lib/elastic_graph/graphql/schema.rb', line 32 def element_names @element_names end |
#graphql_schema ⇒ Object (readonly)
Returns the value of attribute graphql_schema.
32 33 34 |
# File 'lib/elastic_graph/graphql/schema.rb', line 32 def graphql_schema @graphql_schema end |
#runtime_metadata ⇒ Object (readonly)
Returns the value of attribute runtime_metadata.
32 33 34 |
# File 'lib/elastic_graph/graphql/schema.rb', line 32 def end |
Instance Method Details
#document_type_stored_in(index_definition_name) ⇒ Object
86 87 88 89 90 91 92 93 94 |
# File 'lib/elastic_graph/graphql/schema.rb', line 86 def document_type_stored_in(index_definition_name) indexed_document_types_by_index_definition_name.fetch(index_definition_name) do if index_definition_name.include?(ROLLOVER_INDEX_INFIX_MARKER) raise ArgumentError, "`#{index_definition_name}` is the name of a rollover index; pass the name of the parent index definition instead." else raise NotFoundError, "The index definition `#{index_definition_name}` does not appear to exist. Is it misspelled?" end end end |
#enum_value_named(type_name, enum_value_name) ⇒ Object
100 101 102 |
# File 'lib/elastic_graph/graphql/schema.rb', line 100 def enum_value_named(type_name, enum_value_name) type_named(type_name).enum_value_named(enum_value_name) end |
#field_named(type_name, field_name) ⇒ Object
96 97 98 |
# File 'lib/elastic_graph/graphql/schema.rb', line 96 def field_named(type_name, field_name) type_named(type_name).field_named(field_name) end |
#indexed_document_types ⇒ Object
The list of user-defined types that are indexed document types. (Indexed aggregation types will not be included in this.)
105 106 107 |
# File 'lib/elastic_graph/graphql/schema.rb', line 105 def indexed_document_types @indexed_document_types ||= defined_types.select(&:indexed_document?) end |
#to_s ⇒ Object Also known as: inspect
109 110 111 |
# File 'lib/elastic_graph/graphql/schema.rb', line 109 def to_s "#<#{self.class.name} 0x#{__id__.to_s(16)} indexed_document_types=#{indexed_document_types.map(&:name).sort.to_s.delete(":")}>" end |
#type_from(graphql_type) ⇒ Object
74 75 76 |
# File 'lib/elastic_graph/graphql/schema.rb', line 74 def type_from(graphql_type) @types_by_graphql_type[graphql_type] end |
#type_named(type_name) ⇒ Object
Note: this does not support “wrapped” types (e.g. ‘Int!` or `[Int]` compared to `Int`), as the graphql schema object does not give us an index of those by name. You can still get type objects for wrapped types, but you need to get it from a field object of that type.
82 83 84 |
# File 'lib/elastic_graph/graphql/schema.rb', line 82 def type_named(type_name) @types_by_name[type_name.to_s] end |