Class: GraphQL::Schema

Inherits:
Object
  • Object
show all
Extended by:
Forwardable, Member::AcceptsDefinition
Includes:
Define::InstanceDefinable
Defined in:
lib/graphql/schema.rb,
lib/graphql/schema/enum.rb,
lib/graphql/schema/list.rb,
lib/graphql/schema/field.rb,
lib/graphql/schema/union.rb,
lib/graphql/schema/finder.rb,
lib/graphql/schema/loader.rb,
lib/graphql/schema/member.rb,
lib/graphql/schema/object.rb,
lib/graphql/schema/scalar.rb,
lib/graphql/schema/warden.rb,
lib/graphql/schema/printer.rb,
lib/graphql/schema/timeout.rb,
lib/graphql/schema/wrapper.rb,
lib/graphql/schema/argument.rb,
lib/graphql/schema/mutation.rb,
lib/graphql/schema/non_null.rb,
lib/graphql/schema/resolver.rb,
lib/graphql/schema/directive.rb,
lib/graphql/schema/interface.rb,
lib/graphql/schema/null_mask.rb,
lib/graphql/schema/traversal.rb,
lib/graphql/schema/enum_value.rb,
lib/graphql/schema/validation.rb,
lib/graphql/schema/input_object.rb,
lib/graphql/schema/subscription.rb,
lib/graphql/schema/member/scoped.rb,
lib/graphql/schema/built_in_types.rb,
lib/graphql/schema/directive/skip.rb,
lib/graphql/schema/possible_types.rb,
lib/graphql/schema/base_64_encoder.rb,
lib/graphql/schema/field_extension.rb,
lib/graphql/schema/late_bound_type.rb,
lib/graphql/schema/member/has_path.rb,
lib/graphql/schema/type_expression.rb,
lib/graphql/schema/middleware_chain.rb,
lib/graphql/schema/directive/feature.rb,
lib/graphql/schema/directive/include.rb,
lib/graphql/schema/member/build_type.rb,
lib/graphql/schema/member/has_fields.rb,
lib/graphql/schema/rescue_middleware.rb,
lib/graphql/schema/default_type_error.rb,
lib/graphql/schema/invalid_type_error.rb,
lib/graphql/schema/timeout_middleware.rb,
lib/graphql/schema/unique_within_type.rb,
lib/graphql/schema/catchall_middleware.rb,
lib/graphql/schema/default_parse_error.rb,
lib/graphql/schema/directive/transform.rb,
lib/graphql/schema/introspection_system.rb,
lib/graphql/schema/member/has_arguments.rb,
lib/graphql/schema/build_from_definition.rb,
lib/graphql/schema/field/scope_extension.rb,
lib/graphql/schema/member/instrumentation.rb,
lib/graphql/schema/member/relay_shortcuts.rb,
lib/graphql/schema/relay_classic_mutation.rb,
lib/graphql/schema/member/base_dsl_methods.rb,
lib/graphql/schema/member/accepts_definition.rb,
lib/graphql/schema/member/graphql_type_names.rb,
lib/graphql/schema/resolver/has_payload_type.rb,
lib/graphql/schema/field/connection_extension.rb,
lib/graphql/schema/member/type_system_helpers.rb,
lib/graphql/schema/member/cached_graphql_definition.rb,
lib/graphql/schema/build_from_definition/resolve_map.rb,
lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb

Overview

Extend this class to define GraphQL enums in your schema.

By default, GraphQL enum values are translated into Ruby strings. You can provide a custom value with the value: keyword.

Examples:

# equivalent to
# enum PizzaTopping {
#   MUSHROOMS
#   ONIONS
#   PEPPERS
# }
class PizzaTopping < GraphQL::Enum
  value :MUSHROOMS
  value :ONIONS
  value :PEPPERS
end

Defined Under Namespace

Modules: Base64Encoder, BuildFromDefinition, CatchallMiddleware, DefaultParseError, DefaultTypeError, Interface, Loader, MethodWrappers, NullMask, TypeExpression, UniqueWithinType Classes: Argument, CyclicalDefinitionError, Directive, Enum, EnumValue, Field, FieldExtension, Finder, InputObject, IntrospectionSystem, InvalidDocumentError, InvalidTypeError, LateBoundType, List, Member, MiddlewareChain, Mutation, NonNull, Object, PossibleTypes, Printer, RelayClassicMutation, RescueMiddleware, Resolver, Scalar, Subscription, Timeout, TimeoutMiddleware, Traversal, Union, Validation, Warden, Wrapper

Constant Summary collapse

DYNAMIC_FIELDS =
["__type", "__typename", "__schema"]
Context =
GraphQL::Query::Context
BUILT_IN_TYPES =
{
  "Int" => INT_TYPE,
  "String" => STRING_TYPE,
  "Float" => FLOAT_TYPE,
  "Boolean" => BOOLEAN_TYPE,
  "ID" => ID_TYPE,
}

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Define::InstanceDefinable

#metadata, #redefine

Constructor Details

#initializeSchema

Returns a new instance of Schema



166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/graphql/schema.rb', line 166

def initialize
  @tracers = []
  @definition_error = nil
  @orphan_types = []
  @directives = self.class.default_directives
  @static_validator = GraphQL::StaticValidation::Validator.new(schema: self)
  @middleware = MiddlewareChain.new(final_step: GraphQL::Execution::Execute::FieldResolveStep)
  @query_analyzers = []
  @multiplex_analyzers = []
  @resolve_type_proc = nil
  @object_from_id_proc = nil
  @id_from_object_proc = nil
  @type_error_proc = DefaultTypeError
  @parse_error_proc = DefaultParseError
  @instrumenters = Hash.new { |h, k| h[k] = [] }
  @lazy_methods = GraphQL::Execution::Lazy::LazyMethodMap.new
  @lazy_methods.set(GraphQL::Execution::Lazy, :value)
  @cursor_encoder = Base64Encoder
  # Default to the built-in execution strategy:
  @analysis_engine = GraphQL::Analysis
  @query_execution_strategy = self.class.default_execution_strategy
  @mutation_execution_strategy = self.class.default_execution_strategy
  @subscription_execution_strategy = self.class.default_execution_strategy
  @default_mask = GraphQL::Schema::NullMask
  @rebuilding_artifacts = false
  @context_class = GraphQL::Query::Context
  @introspection_namespace = nil
  @introspection_system = nil
  @interpreter = false
  @error_bubbling = false
  @disable_introspection_entry_points = false
end

Class Attribute Details

.default_execution_strategyObject



912
913
914
915
916
917
918
# File 'lib/graphql/schema.rb', line 912

def default_execution_strategy
  if superclass <= GraphQL::Schema
    superclass.default_execution_strategy
  else
    @default_execution_strategy ||= GraphQL::Execution::Execute
  end
end

Instance Attribute Details

#analysis_engineObject

Returns the value of attribute analysis_engine



117
118
119
# File 'lib/graphql/schema.rb', line 117

def analysis_engine
  @analysis_engine
end

#ast_nodeObject

Returns the value of attribute ast_node



117
118
119
# File 'lib/graphql/schema.rb', line 117

def ast_node
  @ast_node
end

#context_classClass

Returns Instantiated for each query

Returns:

  • (Class)

    Instantiated for each query

See Also:

  • The parent class of these classes


145
146
147
# File 'lib/graphql/schema.rb', line 145

def context_class
  @context_class
end

#cursor_encoderObject

Returns the value of attribute cursor_encoder



117
118
119
# File 'lib/graphql/schema.rb', line 117

def cursor_encoder
  @cursor_encoder
end

#default_mask<#call(member, ctx)>

Returns A callable for filtering members of the schema

Returns:

  • (<#call(member, ctx)>)

    A callable for filtering members of the schema

See Also:

  • for query-specific filters with `except:`


141
142
143
# File 'lib/graphql/schema.rb', line 141

def default_mask
  @default_mask
end

#default_max_page_sizeObject

Returns the value of attribute default_max_page_size



117
118
119
# File 'lib/graphql/schema.rb', line 117

def default_max_page_size
  @default_max_page_size
end

#directivesObject

Returns the value of attribute directives



117
118
119
# File 'lib/graphql/schema.rb', line 117

def directives
  @directives
end

#disable_introspection_entry_pointsObject

[Boolean] True if this object disables the introspection entry point fields



148
149
150
# File 'lib/graphql/schema.rb', line 148

def disable_introspection_entry_points
  @disable_introspection_entry_points
end

#error_bubblingObject

[Boolean] True if this object bubbles validation errors up from a field into its parent InputObject, if there is one.



130
131
132
# File 'lib/graphql/schema.rb', line 130

def error_bubbling
  @error_bubbling
end

#id_from_object_procObject (readonly)

Returns the value of attribute id_from_object_proc



164
165
166
# File 'lib/graphql/schema.rb', line 164

def id_from_object_proc
  @id_from_object_proc
end

#instrumentersObject

Returns the value of attribute instrumenters



117
118
119
# File 'lib/graphql/schema.rb', line 117

def instrumenters
  @instrumenters
end

#interpreter=(value) ⇒ Object (writeonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



205
206
207
# File 'lib/graphql/schema.rb', line 205

def interpreter=(value)
  @interpreter = value
end

#introspection_namespaceObject

Returns the value of attribute introspection_namespace



117
118
119
# File 'lib/graphql/schema.rb', line 117

def introspection_namespace
  @introspection_namespace
end

#lazy_methodsObject

Returns the value of attribute lazy_methods



117
118
119
# File 'lib/graphql/schema.rb', line 117

def lazy_methods
  @lazy_methods
end

#max_complexityObject

Returns the value of attribute max_complexity



117
118
119
# File 'lib/graphql/schema.rb', line 117

def max_complexity
  @max_complexity
end

#max_depthObject

Returns the value of attribute max_depth



117
118
119
# File 'lib/graphql/schema.rb', line 117

def max_depth
  @max_depth
end

#middlewareMiddlewareChain

Returns MiddlewareChain which is applied to fields during execution

Returns:

  • (MiddlewareChain)

    MiddlewareChain which is applied to fields during execution



137
138
139
# File 'lib/graphql/schema.rb', line 137

def middleware
  @middleware
end

#multiplex_analyzersObject

Returns the value of attribute multiplex_analyzers



117
118
119
# File 'lib/graphql/schema.rb', line 117

def multiplex_analyzers
  @multiplex_analyzers
end

#mutationObject

Returns the value of attribute mutation



117
118
119
# File 'lib/graphql/schema.rb', line 117

def mutation
  @mutation
end

#mutation_execution_strategyObject

Returns the value of attribute mutation_execution_strategy



117
118
119
# File 'lib/graphql/schema.rb', line 117

def mutation_execution_strategy
  @mutation_execution_strategy
end

#object_from_id_procObject (readonly)

Returns the value of attribute object_from_id_proc



164
165
166
# File 'lib/graphql/schema.rb', line 164

def object_from_id_proc
  @object_from_id_proc
end

#orphan_typesObject

Returns the value of attribute orphan_types



117
118
119
# File 'lib/graphql/schema.rb', line 117

def orphan_types
  @orphan_types
end

#queryObject

Returns the value of attribute query



117
118
119
# File 'lib/graphql/schema.rb', line 117

def query
  @query
end

#query_analyzersObject

Returns the value of attribute query_analyzers



117
118
119
# File 'lib/graphql/schema.rb', line 117

def query_analyzers
  @query_analyzers
end

#query_execution_strategyObject

Returns the value of attribute query_execution_strategy



117
118
119
# File 'lib/graphql/schema.rb', line 117

def query_execution_strategy
  @query_execution_strategy
end

#raise_definition_errorObject

Returns the value of attribute raise_definition_error



117
118
119
# File 'lib/graphql/schema.rb', line 117

def raise_definition_error
  @raise_definition_error
end

#resolve_type_procObject (readonly)

Returns the value of attribute resolve_type_proc



164
165
166
# File 'lib/graphql/schema.rb', line 164

def resolve_type_proc
  @resolve_type_proc
end

#static_validatorObject (readonly)

Returns the value of attribute static_validator



164
165
166
# File 'lib/graphql/schema.rb', line 164

def static_validator
  @static_validator
end

#subscriptionObject

Returns the value of attribute subscription



117
118
119
# File 'lib/graphql/schema.rb', line 117

def subscription
  @subscription
end

#subscription_execution_strategyObject

Returns the value of attribute subscription_execution_strategy



117
118
119
# File 'lib/graphql/schema.rb', line 117

def subscription_execution_strategy
  @subscription_execution_strategy
end

#subscriptionsGraphQL::Subscriptions

Single, long-lived instance of the provided subscriptions class, if there is one.



134
135
136
# File 'lib/graphql/schema.rb', line 134

def subscriptions
  @subscriptions
end

#tracersArray<#trace(key, data)> (readonly)

Returns Tracers applied to every query

Returns:

  • (Array<#trace(key, data)>)

    Tracers applied to every query

See Also:

  • for query-specific tracers


160
161
162
# File 'lib/graphql/schema.rb', line 160

def tracers
  @tracers
end

Class Method Details

.accessible?(member, context) ⇒ Boolean

Returns:

  • (Boolean)


955
956
957
# File 'lib/graphql/schema.rb', line 955

def accessible?(member, context)
  call_on_type_class(member, :accessible?, context, default: true)
end

.context_class(new_context_class = nil) ⇒ Object



920
921
922
923
924
925
926
# File 'lib/graphql/schema.rb', line 920

def context_class(new_context_class = nil)
  if new_context_class
    @context_class = new_context_class
  else
    @context_class || GraphQL::Query::Context
  end
end

.cursor_encoder(new_encoder = nil) ⇒ Object



837
838
839
840
841
842
# File 'lib/graphql/schema.rb', line 837

def cursor_encoder(new_encoder = nil)
  if new_encoder
    @cursor_encoder = new_encoder
  end
  @cursor_encoder || Base64Encoder
end

.default_directivesObject



1035
1036
1037
1038
1039
1040
1041
# File 'lib/graphql/schema.rb', line 1035

def default_directives
  {
    "include" => GraphQL::Directive::IncludeDirective,
    "skip" => GraphQL::Directive::SkipDirective,
    "deprecated" => GraphQL::Directive::DeprecatedDirective,
  }
end

.default_max_page_size(new_default_max_page_size = nil) ⇒ Object



844
845
846
847
848
849
850
# File 'lib/graphql/schema.rb', line 844

def default_max_page_size(new_default_max_page_size = nil)
  if new_default_max_page_size
    @default_max_page_size = new_default_max_page_size
  else
    @default_max_page_size
  end
end

.directive(new_directive) ⇒ Object



1031
1032
1033
# File 'lib/graphql/schema.rb', line 1031

def directive(new_directive)
  directives[new_directive.graphql_name] = new_directive
end

.directives(new_directives = nil) ⇒ Object



1023
1024
1025
1026
1027
1028
1029
# File 'lib/graphql/schema.rb', line 1023

def directives(new_directives = nil)
  if new_directives
    @directives = new_directives.reduce({}) { |m, d| m[d.name] = d; m }
  end

  @directives ||= default_directives
end

.disable_introspection_entry_pointsObject



900
901
902
# File 'lib/graphql/schema.rb', line 900

def disable_introspection_entry_points
  @disable_introspection_entry_points = true
end

.error_bubbling(new_error_bubbling = nil) ⇒ Object



884
885
886
887
888
889
890
# File 'lib/graphql/schema.rb', line 884

def error_bubbling(new_error_bubbling = nil)
  if !new_error_bubbling.nil?
    @error_bubbling = new_error_bubbling
  else
    @error_bubbling
  end
end

.from_definition(definition_or_path, default_resolve: BuildFromDefinition::DefaultResolve, parser: BuildFromDefinition::DefaultParser) ⇒ GraphQL::Schema

Create schema from an IDL schema or file containing an IDL definition.

Parameters:

  • definition_or_path (String)

    A schema definition string, or a path to a file containing the definition

  • default_resolve (<#call(type, field, obj, args, ctx)>)

    A callable for handling field resolution

  • parser (Object)

    An object for handling definition string parsing (must respond to parse)

Returns:



638
639
640
641
642
643
644
645
646
# File 'lib/graphql/schema.rb', line 638

def self.from_definition(definition_or_path, default_resolve: BuildFromDefinition::DefaultResolve, parser: BuildFromDefinition::DefaultParser)
  # If the file ends in `.graphql`, treat it like a filepath
  definition = if definition_or_path.end_with?(".graphql")
    File.read(definition_or_path)
  else
    definition_or_path
  end
  GraphQL::Schema::BuildFromDefinition.from_definition(definition, default_resolve: default_resolve, parser: parser)
end

.from_introspection(introspection_result) ⇒ GraphQL::Schema

Create schema with the result of an introspection query.

Parameters:

Returns:



629
630
631
# File 'lib/graphql/schema.rb', line 629

def self.from_introspection(introspection_result)
  GraphQL::Schema::Loader.load(introspection_result)
end

.graphql_definitionObject



726
727
728
# File 'lib/graphql/schema.rb', line 726

def graphql_definition
  @graphql_definition ||= to_graphql
end

.id_from_object(object, type, ctx) ⇒ Object

Raises:

  • (NotImplementedError)


947
948
949
# File 'lib/graphql/schema.rb', line 947

def id_from_object(object, type, ctx)
  raise NotImplementedError, "#{self.name}.id_from_object(object, type, ctx) must be implemented to create global ids (tried to create an id for `#{object.inspect}`)"
end

.inaccessible_fields(error) ⇒ AnalysisError?

This hook is called when a client tries to access one or more fields that fail the accessible? check.

By default, an error is added to the response. Override this hook to track metrics or return a different error to the client.

Parameters:

  • error (InaccessibleFieldsError)

    The analysis error for this check

Returns:



967
968
969
# File 'lib/graphql/schema.rb', line 967

def inaccessible_fields(error)
  error
end

.instrument(instrument_step, instrumenter, options = {}) ⇒ Object



1014
1015
1016
1017
1018
1019
1020
1021
# File 'lib/graphql/schema.rb', line 1014

def instrument(instrument_step, instrumenter, options = {})
  step = if instrument_step == :field && options[:after_built_ins]
    :field_after_built_ins
  else
    instrument_step
  end
  defined_instrumenters[step] << instrumenter
end

.introspection(new_introspection_namespace = nil) ⇒ Object



829
830
831
832
833
834
835
# File 'lib/graphql/schema.rb', line 829

def introspection(new_introspection_namespace = nil)
  if new_introspection_namespace
    @introspection = new_introspection_namespace
  else
    @introspection
  end
end

.lazy_resolve(lazy_class, value_method) ⇒ Object



1010
1011
1012
# File 'lib/graphql/schema.rb', line 1010

def lazy_resolve(lazy_class, value_method)
  lazy_classes[lazy_class] = value_method
end

.max_complexity(max_complexity = nil) ⇒ Object



876
877
878
879
880
881
882
# File 'lib/graphql/schema.rb', line 876

def max_complexity(max_complexity = nil)
  if max_complexity
    @max_complexity = max_complexity
  else
    @max_complexity
  end
end

.max_depth(new_max_depth = nil) ⇒ Object



892
893
894
895
896
897
898
# File 'lib/graphql/schema.rb', line 892

def max_depth(new_max_depth = nil)
  if new_max_depth
    @max_depth = new_max_depth
  else
    @max_depth
  end
end

.middleware(new_middleware = nil) ⇒ Object



1054
1055
1056
1057
1058
1059
1060
# File 'lib/graphql/schema.rb', line 1054

def middleware(new_middleware = nil)
  if new_middleware
    defined_middleware << new_middleware
  else
    graphql_definition.middleware
  end
end

.multiplex_analyzer(new_analyzer) ⇒ Object



1062
1063
1064
# File 'lib/graphql/schema.rb', line 1062

def multiplex_analyzer(new_analyzer)
  defined_multiplex_analyzers << new_analyzer
end

.mutation(new_mutation_object = nil) ⇒ Object



813
814
815
816
817
818
819
# File 'lib/graphql/schema.rb', line 813

def mutation(new_mutation_object = nil)
  if new_mutation_object
    @mutation_object = new_mutation_object
  else
    @mutation_object.respond_to?(:graphql_definition) ? @mutation_object.graphql_definition : @mutation_object
  end
end

.mutation_execution_strategy(new_mutation_execution_strategy = nil) ⇒ Object



860
861
862
863
864
865
866
# File 'lib/graphql/schema.rb', line 860

def mutation_execution_strategy(new_mutation_execution_strategy = nil)
  if new_mutation_execution_strategy
    @mutation_execution_strategy = new_mutation_execution_strategy
  else
    @mutation_execution_strategy || self.default_execution_strategy
  end
end

.object_from_id(node_id, ctx) ⇒ Object

Raises:

  • (NotImplementedError)


943
944
945
# File 'lib/graphql/schema.rb', line 943

def object_from_id(node_id, ctx)
  raise NotImplementedError, "#{self.name}.object_from_id(node_id, ctx) must be implemented to load by ID (tried to load from id `#{node_id}`)"
end

.orphan_types(*new_orphan_types) ⇒ Object



904
905
906
907
908
909
910
# File 'lib/graphql/schema.rb', line 904

def orphan_types(*new_orphan_types)
  if new_orphan_types.any?
    @orphan_types = new_orphan_types.flatten
  else
    @orphan_types || []
  end
end

.pluginsObject



734
735
736
# File 'lib/graphql/schema.rb', line 734

def plugins
  @plugins ||= []
end

.query(new_query_object = nil) ⇒ Object



805
806
807
808
809
810
811
# File 'lib/graphql/schema.rb', line 805

def query(new_query_object = nil)
  if new_query_object
    @query_object = new_query_object
  else
    @query_object.respond_to?(:graphql_definition) ? @query_object.graphql_definition : @query_object
  end
end

.query_analyzer(new_analyzer) ⇒ Object



1047
1048
1049
1050
1051
1052
# File 'lib/graphql/schema.rb', line 1047

def query_analyzer(new_analyzer)
  if new_analyzer == GraphQL::Authorization::Analyzer
    warn("The Authorization query analyzer is deprecated. Authorizing at query runtime is generally a better idea.")
  end
  defined_query_analyzers << new_analyzer
end

.query_execution_strategy(new_query_execution_strategy = nil) ⇒ Object



852
853
854
855
856
857
858
# File 'lib/graphql/schema.rb', line 852

def query_execution_strategy(new_query_execution_strategy = nil)
  if new_query_execution_strategy
    @query_execution_strategy = new_query_execution_strategy
  else
    @query_execution_strategy || self.default_execution_strategy
  end
end

.rescue_from(*err_classes, &handler_block) ⇒ Object



928
929
930
931
932
933
# File 'lib/graphql/schema.rb', line 928

def rescue_from(*err_classes, &handler_block)
  @rescues ||= {}
  err_classes.each do |err_class|
    @rescues[err_class] = handler_block
  end
end

.resolve_type(type, obj, ctx) ⇒ Object



935
936
937
938
939
940
941
# File 'lib/graphql/schema.rb', line 935

def resolve_type(type, obj, ctx)
  if type.kind.object?
    type
  else
    raise NotImplementedError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
  end
end

.subscription(new_subscription_object = nil) ⇒ Object



821
822
823
824
825
826
827
# File 'lib/graphql/schema.rb', line 821

def subscription(new_subscription_object = nil)
  if new_subscription_object
    @subscription_object = new_subscription_object
  else
    @subscription_object.respond_to?(:graphql_definition) ? @subscription_object.graphql_definition : @subscription_object
  end
end

.subscription_execution_strategy(new_subscription_execution_strategy = nil) ⇒ Object



868
869
870
871
872
873
874
# File 'lib/graphql/schema.rb', line 868

def subscription_execution_strategy(new_subscription_execution_strategy = nil)
  if new_subscription_execution_strategy
    @subscription_execution_strategy = new_subscription_execution_strategy
  else
    @subscription_execution_strategy || self.default_execution_strategy
  end
end

.sync_lazy(value) ⇒ Object

Override this method to handle lazy objects in a custom way.

Parameters:

Returns:

  • (Object)

    A GraphQL-ready (non-lazy) object



1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
# File 'lib/graphql/schema.rb', line 1154

def self.sync_lazy(value)
  if block_given?
    # This was already hit by the instance, just give it back
    yield(value)
  else
    # This was called directly on the class, hit the instance
    # which has the lazy method map
    self.graphql_definition.sync_lazy(value)
  end
end

.to_graphqlObject



738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
# File 'lib/graphql/schema.rb', line 738

def to_graphql
  schema_defn = self.new
  schema_defn.raise_definition_error = true
  schema_defn.query = query
  schema_defn.mutation = mutation
  schema_defn.subscription = subscription
  schema_defn.max_complexity = max_complexity
  schema_defn.error_bubbling = error_bubbling
  schema_defn.max_depth = max_depth
  schema_defn.default_max_page_size = default_max_page_size
  schema_defn.orphan_types = orphan_types
  schema_defn.disable_introspection_entry_points = @disable_introspection_entry_points

  prepped_dirs = {}
  directives.each { |k, v| prepped_dirs[k] = v.graphql_definition}
  schema_defn.directives = prepped_dirs
  schema_defn.introspection_namespace = introspection
  schema_defn.resolve_type = method(:resolve_type)
  schema_defn.object_from_id = method(:object_from_id)
  schema_defn.id_from_object = method(:id_from_object)
  schema_defn.type_error = method(:type_error)
  schema_defn.context_class = context_class
  schema_defn.cursor_encoder = cursor_encoder
  schema_defn.tracers.concat(defined_tracers)
  schema_defn.query_analyzers.concat(defined_query_analyzers)

  schema_defn.middleware.concat(defined_middleware)
  schema_defn.multiplex_analyzers.concat(defined_multiplex_analyzers)
  schema_defn.query_execution_strategy = query_execution_strategy
  schema_defn.mutation_execution_strategy = mutation_execution_strategy
  schema_defn.subscription_execution_strategy = subscription_execution_strategy
  defined_instrumenters.each do |step, insts|
    insts.each do |inst|
      schema_defn.instrumenters[step] << inst
    end
  end
  lazy_classes.each do |lazy_class, value_method|
    schema_defn.lazy_methods.set(lazy_class, value_method)
  end
  if @rescues
    @rescues.each do |err_class, handler|
      schema_defn.rescue_from(err_class, &handler)
    end
  end

  if plugins.any?
    schema_plugins = plugins
    # TODO don't depend on .define
    schema_defn = schema_defn.redefine do
      schema_plugins.each do |plugin, options|
        if options.any?
          use(plugin, **options)
        else
          use(plugin)
        end
      end
    end
  end
  # Do this after `plugins` since Interpreter is a plugin
  if schema_defn.query_execution_strategy != GraphQL::Execution::Interpreter
    schema_defn.instrumenters[:query] << GraphQL::Schema::Member::Instrumentation
  end
  schema_defn.send(:rebuild_artifacts)

  schema_defn
end

.tracer(new_tracer) ⇒ Object



1043
1044
1045
# File 'lib/graphql/schema.rb', line 1043

def tracer(new_tracer)
  defined_tracers << new_tracer
end

.type_error(type_err, ctx) ⇒ Object



1006
1007
1008
# File 'lib/graphql/schema.rb', line 1006

def type_error(type_err, ctx)
  DefaultTypeError.call(type_err, ctx)
end

.unauthorized_field(unauthorized_error) ⇒ Field

This hook is called when a field fails an authorized? check.

By default, this hook implements the same behavior as unauthorized_object.

Whatever value is returned from this method will be used instead of the unauthorized field . If an error is raised, then nil will be used.

If you want to add an error to the "errors" key, raise a ExecutionError in this hook.

Parameters:

Returns:

  • (Field)

    The returned field will be put in the GraphQL response



1002
1003
1004
# File 'lib/graphql/schema.rb', line 1002

def unauthorized_field(unauthorized_error)
  unauthorized_object(unauthorized_error)
end

.unauthorized_object(unauthorized_error) ⇒ Object

This hook is called when an object fails an authorized? check. You might report to your bug tracker here, so you can correct the field resolvers not to return unauthorized objects.

By default, this hook just replaces the unauthorized object with nil.

Whatever value is returned from this method will be used instead of the unauthorized object (accessible as unauthorized_error.object). If an error is raised, then nil will be used.

If you want to add an error to the "errors" key, raise a ExecutionError in this hook.

Parameters:

Returns:

  • (Object)

    The returned object will be put in the GraphQL response



986
987
988
# File 'lib/graphql/schema.rb', line 986

def unauthorized_object(unauthorized_error)
  nil
end

.use(plugin, options = {}) ⇒ Object



730
731
732
# File 'lib/graphql/schema.rb', line 730

def use(plugin, options = {})
  plugins << [plugin, options]
end

.visible?(member, context) ⇒ Boolean

Returns:

  • (Boolean)


951
952
953
# File 'lib/graphql/schema.rb', line 951

def visible?(member, context)
  call_on_type_class(member, :visible?, context, default: true)
end

Instance Method Details

#after_lazy(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Call the given block at the right time, either: - Right away, if value is not registered with lazy_resolve - After resolving value, if it’s registered with lazy_resolve (eg, Promise)



1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
# File 'lib/graphql/schema.rb', line 1136

def after_lazy(value)
  if lazy?(value)
    GraphQL::Execution::Lazy.new do
      result = sync_lazy(value)
      # The returned result might also be lazy, so check it, too
      after_lazy(result) do |final_result|
        yield(final_result) if block_given?
      end
    end
  else
    yield(value) if block_given?
  end
end

#as_json(only: nil, except: nil, context: {}) ⇒ Hash

Return the Hash response of Introspection::INTROSPECTION_QUERY.

Parameters:

  • context (Hash)
  • only (<#call(member, ctx)>)
  • except (<#call(member, ctx)>)

Returns:

  • (Hash)

    GraphQL result



681
682
683
# File 'lib/graphql/schema.rb', line 681

def as_json(only: nil, except: nil, context: {})
  execute(Introspection::INTROSPECTION_QUERY, only: only, except: except, context: context).to_h
end

#check_resolved_type(type, object, ctx = :__undefined__) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This is a compatibility hack so that instance-level and class-level methods can get correctness checks without calling one another



496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
# File 'lib/graphql/schema.rb', line 496

def check_resolved_type(type, object, ctx = :__undefined__)
  if ctx == :__undefined__
    # Old method signature
    ctx = object
    object = type
    type = nil
  end

  if object.is_a?(GraphQL::Schema::Object)
    object = object.object
  end

  if type.respond_to?(:graphql_definition)
    type = type.graphql_definition
  end

  # Prefer a type-local function; fall back to the schema-level function
  type_proc = type && type.resolve_type_proc
  type_result = if type_proc
    type_proc.call(object, ctx)
  else
    yield(type, object, ctx)
  end

  if type_result.nil?
    nil
  else
    after_lazy(type_result) do |resolved_type_result|
      if resolved_type_result.respond_to?(:graphql_definition)
        resolved_type_result = resolved_type_result.graphql_definition
      end
      if !resolved_type_result.is_a?(GraphQL::BaseType)
        type_str = "#{resolved_type_result} (#{resolved_type_result.class.name})"
        raise "resolve_type(#{object}) returned #{type_str}, but it should return a GraphQL type"
      else
        resolved_type_result
      end
    end
  end
end

#default_filterObject



154
155
156
# File 'lib/graphql/schema.rb', line 154

def default_filter
  GraphQL::Filter.new(except: default_mask)
end

#define(**kwargs, &block) ⇒ Object



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/graphql/schema.rb', line 271

def define(**kwargs, &block)
  super
  ensure_defined
  # Assert that all necessary configs are present:
  validation_error = Validation.validate(self)
  validation_error && raise(NotImplementedError, validation_error)
  rebuild_artifacts

  @definition_error = nil
  nil
rescue StandardError => err
  if @raise_definition_error || err.is_a?(CyclicalDefinitionError)
    raise
  else
    # Raise this error _later_ to avoid messing with Rails constant loading
    @definition_error = err
  end
  nil
end

#execute(query_str = nil, **kwargs) ⇒ Hash

Execute a query on itself. Raises an error if the schema definition is invalid.

Returns:

  • (Hash)

    query result, ready to be serialized as JSON

See Also:

  • for arguments.


346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
# File 'lib/graphql/schema.rb', line 346

def execute(query_str = nil, **kwargs)
  if query_str
    kwargs[:query] = query_str
  end
  # Some of the query context _should_ be passed to the multiplex, too
  multiplex_context = if (ctx = kwargs[:context])
    {
      backtrace: ctx[:backtrace],
      tracers: ctx[:tracers],
    }
  else
    {}
  end
  # Since we're running one query, don't run a multiplex-level complexity analyzer
  all_results = multiplex([kwargs], max_complexity: nil, context: multiplex_context)
  all_results[0]
end

#execution_strategy_for_operation(operation) ⇒ Object



464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/graphql/schema.rb', line 464

def execution_strategy_for_operation(operation)
  case operation
  when "query"
    query_execution_strategy
  when "mutation"
    mutation_execution_strategy
  when "subscription"
    subscription_execution_strategy
  else
    raise ArgumentError, "unknown operation type: #{operation}"
  end
end

#find(path) ⇒ GraphQL::BaseType, ...

Search for a schema member using a string path Schema.find(“Ensemble.musicians”)

Examples:

Finding a Field

Parameters:

  • path (String)

    A dot-separated path to the member

Returns:

Raises:

See Also:

  • for more examples


396
397
398
399
# File 'lib/graphql/schema.rb', line 396

def find(path)
  rebuild_artifacts unless defined?(@finder)
  @find_cache[path] ||= @finder.find(path)
end

#get_field(parent_type, field_name) ⇒ GraphQL::Field?

Resolve field named field_name for type parent_type. Handles dynamic fields __typename, __type and __schema, too

Parameters:

Returns:

See Also:

  • Restricted access to members of a schema


407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
# File 'lib/graphql/schema.rb', line 407

def get_field(parent_type, field_name)
  with_definition_error_check do
    parent_type_name = case parent_type
    when GraphQL::BaseType
      parent_type.name
    when String
      parent_type
    else
      raise "Unexpected parent_type: #{parent_type}"
    end

    defined_field = @instrumented_field_map[parent_type_name][field_name]
    if defined_field
      defined_field
    elsif parent_type == query && (entry_point_field = introspection_system.entry_point(name: field_name))
      entry_point_field
    elsif (dynamic_field = introspection_system.dynamic_field(name: field_name))
      dynamic_field
    else
      nil
    end
  end
end

#get_fields(type) ⇒ Hash<String, GraphQL::Field>

Fields for this type, after instrumentation is applied

Returns:



433
434
435
# File 'lib/graphql/schema.rb', line 433

def get_fields(type)
  @instrumented_field_map[type.graphql_name]
end

#id_from_object(object, type, ctx) ⇒ String

Get a unique identifier from this object

Parameters:

Returns:

  • (String)

    a unique identifier for object which clients can use to refetch it



613
614
615
616
617
618
619
# File 'lib/graphql/schema.rb', line 613

def id_from_object(object, type, ctx)
  if @id_from_object_proc.nil?
    raise(NotImplementedError, "Can't generate an ID for #{object.inspect} of type #{type}, schema's `id_from_object` must be defined")
  else
    @id_from_object_proc.call(object, type, ctx)
  end
end

#id_from_object=(new_proc) ⇒ Object

Parameters:

  • new_proc (#call)

    A new callable for generating unique IDs



622
623
624
# File 'lib/graphql/schema.rb', line 622

def id_from_object=(new_proc)
  @id_from_object_proc = new_proc
end

#initialize_copy(other) ⇒ Object



211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/graphql/schema.rb', line 211

def initialize_copy(other)
  super
  @orphan_types = other.orphan_types.dup
  @directives = other.directives.dup
  @static_validator = GraphQL::StaticValidation::Validator.new(schema: self)
  @middleware = other.middleware.dup
  @query_analyzers = other.query_analyzers.dup
  @multiplex_analyzers = other.multiplex_analyzers.dup
  @tracers = other.tracers.dup
  @possible_types = GraphQL::Schema::PossibleTypes.new(self)

  @lazy_methods = other.lazy_methods.dup

  @instrumenters = Hash.new { |h, k| h[k] = [] }
  other.instrumenters.each do |key, insts|
    @instrumenters[key].concat(insts)
  end

  if other.rescues?
    @rescue_middleware = other.rescue_middleware
  end

  # This will be rebuilt when it's requested
  # or during a later `define` call
  @types = nil
  @introspection_system = nil
end

#inspectObject



207
208
209
# File 'lib/graphql/schema.rb', line 207

def inspect
  "#<#{self.class.name} ...>"
end

#instrument(instrumentation_type, instrumenter) ⇒ void

This method returns an undefined value.

Attach instrumenter to this schema for instrumenting events of instrumentation_type.

Parameters:

  • instrumentation_type (Symbol)
  • instrumenter


295
296
297
298
299
300
# File 'lib/graphql/schema.rb', line 295

def instrument(instrumentation_type, instrumenter)
  @instrumenters[instrumentation_type] << instrumenter
  if instrumentation_type == :field
    rebuild_artifacts
  end
end

#interpreter?Boolean

Returns True if using the new Execution::Interpreter

Returns:



200
201
202
# File 'lib/graphql/schema.rb', line 200

def interpreter?
  @interpreter
end

#introspection_systemObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



320
321
322
323
324
325
# File 'lib/graphql/schema.rb', line 320

def introspection_system
  @introspection_system ||= begin
    rebuild_artifacts
    @introspection_system
  end
end

#lazy?(obj) ⇒ Boolean

Returns True if this object should be lazily resolved

Returns:

  • (Boolean)

    True if this object should be lazily resolved



657
658
659
# File 'lib/graphql/schema.rb', line 657

def lazy?(obj)
  !!lazy_method_name(obj)
end

#lazy_method_name(obj) ⇒ Symbol?

Returns The method name to lazily resolve obj, or nil if obj’s class wasn’t registered wtih #lazy_resolve.

Returns:

  • (Symbol, nil)

    The method name to lazily resolve obj, or nil if obj’s class wasn’t registered wtih #lazy_resolve.



652
653
654
# File 'lib/graphql/schema.rb', line 652

def lazy_method_name(obj)
  @lazy_methods.get(obj)
end

#multiplex(queries, **kwargs) ⇒ Array<Hash>

Execute several queries on itself. Raises an error if the schema definition is invalid.

Examples:

Run several queries at once

context = { ... }
queries = [
  { query: params[:query_1], variables: params[:variables_1], context: context },
  { query: params[:query_2], variables: params[:variables_2], context: context },
]
results = MySchema.multiplex(queries)
render json: {
  result_1: results[0],
  result_2: results[1],
}

Parameters:

  • queries (Array<Hash>)

    Keyword arguments for each query

  • context (Hash)

    Multiplex-level context

Returns:

  • (Array<Hash>)

    One result for each query in the input

See Also:

  • for query keyword arguments
  • for multiplex keyword arguments


382
383
384
385
386
# File 'lib/graphql/schema.rb', line 382

def multiplex(queries, **kwargs)
  with_definition_error_check {
    GraphQL::Execution::Multiplex.run_all(self, queries, **kwargs)
  }
end

#object_from_id(id, ctx) ⇒ Any

Fetch an application object by its unique id

Parameters:

  • id (String)

    A unique identifier, provided previously by this GraphQL schema

  • ctx (GraphQL::Query::Context)

    The context for the current query

Returns:

  • (Any)

    The application object identified by id



546
547
548
549
550
551
552
# File 'lib/graphql/schema.rb', line 546

def object_from_id(id, ctx)
  if @object_from_id_proc.nil?
    raise(NotImplementedError, "Can't fetch an object for id \"#{id}\" because the schema's `object_from_id (id, ctx) -> { ... }` function is not defined")
  else
    @object_from_id_proc.call(id, ctx)
  end
end

#object_from_id=(new_proc) ⇒ Object

Parameters:

  • new_proc (#call)

    A new callable for fetching objects by ID



555
556
557
# File 'lib/graphql/schema.rb', line 555

def object_from_id=(new_proc)
  @object_from_id_proc = new_proc
end

#parse_error(err, ctx) ⇒ Object

A function to call when #execute receives an invalid query string

Parameters:

Returns:

  • void

See Also:

  • is the default behavior.


599
600
601
# File 'lib/graphql/schema.rb', line 599

def parse_error(err, ctx)
  @parse_error_proc.call(err, ctx)
end

#parse_error=(new_proc) ⇒ Object

Parameters:

  • new_proc (#call)

    A new callable for handling parse errors during execution



604
605
606
# File 'lib/graphql/schema.rb', line 604

def parse_error=(new_proc)
  @parse_error_proc = new_proc
end

#possible_types(type_defn) ⇒ Array<GraphQL::ObjectType>

Returns types which belong to type_defn in this schema

Parameters:

Returns:

See Also:

  • Restricted access to members of a schema


444
445
446
447
# File 'lib/graphql/schema.rb', line 444

def possible_types(type_defn)
  @possible_types ||= GraphQL::Schema::PossibleTypes.new(self)
  @possible_types.possible_types(type_defn)
end

#references_to(type_name) ⇒ Hash

Returns a list of Arguments and Fields referencing a certain type

Parameters:

  • type_name (String)

Returns:

  • (Hash)


330
331
332
333
# File 'lib/graphql/schema.rb', line 330

def references_to(type_name)
  rebuild_artifacts unless defined?(@type_reference_map)
  @type_reference_map.fetch(type_name, [])
end

#remove_handler(*args, &block) ⇒ Object



243
244
245
# File 'lib/graphql/schema.rb', line 243

def remove_handler(*args, &block)
  rescue_middleware.remove_handler(*args, &block)
end

#rescue_from(*args, &block) ⇒ Object



239
240
241
# File 'lib/graphql/schema.rb', line 239

def rescue_from(*args, &block)
  rescue_middleware.rescue_from(*args, &block)
end

#resolve_type(type, object, ctx = :__undefined__) ⇒ GraphQL::ObjectType

Determine the GraphQL type for a given object. This is required for unions and interfaces (including Relay’s Node interface)

Parameters:

  • type (GraphQL::UnionType, GraphQL:InterfaceType)

    the abstract type which is being resolved

  • object (Any)

    An application object which GraphQL is currently resolving on

  • ctx (GraphQL::Query::Context) (defaults to: :__undefined__)

    The context for the current query

Returns:

See Also:

  • Restricted access to members of a schema


484
485
486
487
488
489
490
491
# File 'lib/graphql/schema.rb', line 484

def resolve_type(type, object, ctx = :__undefined__)
  check_resolved_type(type, object, ctx) do |ok_type, ok_object, ok_ctx|
    if @resolve_type_proc.nil?
      raise(NotImplementedError, "Can't determine GraphQL type for: #{ok_object.inspect}, define `resolve_type (type, obj, ctx) -> { ... }` inside `Schema.define`.")
    end
    @resolve_type_proc.call(ok_type, ok_object, ok_ctx)
  end
end

#resolve_type=(new_resolve_type_proc) ⇒ Object



537
538
539
540
# File 'lib/graphql/schema.rb', line 537

def resolve_type=(new_resolve_type_proc)
  callable = GraphQL::BackwardsCompatibility.wrap_arity(new_resolve_type_proc, from: 2, to: 3, last: true, name: "Schema#resolve_type(type, obj, ctx)")
  @resolve_type_proc = callable
end

#root_type_for_operation(operation) ⇒ GraphQL::ObjectType?

Returns:

See Also:

  • Resticted access to root types


451
452
453
454
455
456
457
458
459
460
461
462
# File 'lib/graphql/schema.rb', line 451

def root_type_for_operation(operation)
  case operation
  when "query"
    query
  when "mutation"
    mutation
  when "subscription"
    subscription
  else
    raise ArgumentError, "unknown operation type: #{operation}"
  end
end

#root_typesArray<GraphQL::BaseType>

Returns The root types of this schema

Returns:



303
304
305
306
307
308
# File 'lib/graphql/schema.rb', line 303

def root_types
  @root_types ||= begin
    rebuild_artifacts
    @root_types
  end
end

#sync_lazy(value) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
# File 'lib/graphql/schema.rb', line 1167

def sync_lazy(value)
  self.class.sync_lazy(value) { |v|
    lazy_method = lazy_method_name(v)
    if lazy_method
      synced_value = value.public_send(lazy_method)
      sync_lazy(synced_value)
    else
      v
    end
  }
end

#to_definition(only: nil, except: nil, context: {}) ⇒ String

Return the GraphQL IDL for the schema

Parameters:

  • context (Hash)
  • only (<#call(member, ctx)>)
  • except (<#call(member, ctx)>)

Returns:

  • (String)


666
667
668
# File 'lib/graphql/schema.rb', line 666

def to_definition(only: nil, except: nil, context: {})
  GraphQL::Schema::Printer.print_schema(self, only: only, except: except, context: context)
end

#to_documentGraphQL::Language::Document

Return the GraphQL::Language::Document IDL AST for the schema

Returns:

  • (GraphQL::Language::Document)


672
673
674
# File 'lib/graphql/schema.rb', line 672

def to_document
  GraphQL::Language::DocumentFromSchemaDefinition.new(self).document
end

#to_json(*args) ⇒ String

Returns the JSON response of Introspection::INTROSPECTION_QUERY.

Returns:

  • (String)

See Also:

  • GraphQL::Schema.{{#as_json}


688
689
690
# File 'lib/graphql/schema.rb', line 688

def to_json(*args)
  JSON.pretty_generate(as_json(*args))
end

#type_error(err, ctx) ⇒ Object

When we encounter a type error during query execution, we call this hook.

You can use this hook to write a log entry, add a ExecutionError to the response (with ctx.add_error) or raise an exception and halt query execution.

Examples:

A nil is encountered by a non-null field

type_error ->(err, query_ctx) {
  err.is_a?(GraphQL::InvalidNullError) # => true
}

An object doesn’t resolve to one of a UnionType’s members

type_error ->(err, query_ctx) {
  err.is_a?(GraphQL::UnresolvedTypeError) # => true
}

Parameters:

  • err (GraphQL::TypeError)

    The error encountered during execution

  • ctx (GraphQL::Query::Context)

    The context for the field where the error occurred

Returns:

  • void

See Also:

  • is the default behavior.


579
580
581
# File 'lib/graphql/schema.rb', line 579

def type_error(err, ctx)
  @type_error_proc.call(err, ctx)
end

#type_error=(new_proc) ⇒ Object

Parameters:

  • new_proc (#call)

    A new callable for handling type errors during execution



584
585
586
# File 'lib/graphql/schema.rb', line 584

def type_error=(new_proc)
  @type_error_proc = new_proc
end

#type_from_ast(ast_node) ⇒ Object



437
438
439
# File 'lib/graphql/schema.rb', line 437

def type_from_ast(ast_node)
  GraphQL::Schema::TypeExpression.build_type(self.types, ast_node)
end

#typesGraphQL::Schema::TypeMap

Returns { name => type } pairs of types in this schema

Returns:

  • (GraphQL::Schema::TypeMap)

    { name => type } pairs of types in this schema

See Also:

  • Restricted access to members of a schema


312
313
314
315
316
317
# File 'lib/graphql/schema.rb', line 312

def types
  @types ||= begin
    rebuild_artifacts
    @types
  end
end

#union_memberships(type) ⇒ Array<GraphQL::UnionType>

Returns a list of Union types in which a type is a member

Parameters:

Returns:



338
339
340
341
# File 'lib/graphql/schema.rb', line 338

def union_memberships(type)
  rebuild_artifacts unless defined?(@union_memberships)
  @union_memberships.fetch(type.name, [])
end

#using_ast_analysis?Boolean

Returns:

  • (Boolean)


247
248
249
# File 'lib/graphql/schema.rb', line 247

def using_ast_analysis?
  @analysis_engine == GraphQL::Analysis::AST
end

#validate(string_or_document, rules: nil, context: nil) ⇒ Array<GraphQL::StaticValidation::Error >

Validate a query string according to this schema.

Parameters:

Returns:



257
258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/graphql/schema.rb', line 257

def validate(string_or_document, rules: nil, context: nil)
  doc = if string_or_document.is_a?(String)
    GraphQL.parse(string_or_document)
  else
    string_or_document
  end
  query = GraphQL::Query.new(self, document: doc, context: context)
  validator_opts = { schema: self }
  rules && (validator_opts[:rules] = rules)
  validator = GraphQL::StaticValidation::Validator.new(validator_opts)
  res = validator.validate(query)
  res[:errors]
end