Class: GraphQL::Schema
- Inherits:
-
Object
show all
- Extended by:
- FindInheritedValue, Member::HasAstNode
- 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/addition.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/validator.rb,
lib/graphql/schema/enum_value.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/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/type_membership.rb,
lib/graphql/schema/directive/one_of.rb,
lib/graphql/schema/directive/feature.rb,
lib/graphql/schema/directive/flagged.rb,
lib/graphql/schema/directive/include.rb,
lib/graphql/schema/member/build_type.rb,
lib/graphql/schema/member/has_fields.rb,
lib/graphql/schema/invalid_type_error.rb,
lib/graphql/schema/unique_within_type.rb,
lib/graphql/schema/directive/transform.rb,
lib/graphql/schema/member/has_ast_node.rb,
lib/graphql/schema/directive/deprecated.rb,
lib/graphql/schema/find_inherited_value.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/has_directives.rb,
lib/graphql/schema/member/has_interfaces.rb,
lib/graphql/schema/member/has_validators.rb,
lib/graphql/schema/member/relay_shortcuts.rb,
lib/graphql/schema/member/validates_input.rb,
lib/graphql/schema/relay_classic_mutation.rb,
lib/graphql/schema/member/base_dsl_methods.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/validator/format_validator.rb,
lib/graphql/schema/validator/length_validator.rb,
lib/graphql/schema/validator/required_validator.rb,
lib/graphql/schema/member/has_deprecation_reason.rb,
lib/graphql/schema/validator/exclusion_validator.rb,
lib/graphql/schema/validator/inclusion_validator.rb,
lib/graphql/schema/validator/allow_null_validator.rb,
lib/graphql/schema/validator/allow_blank_validator.rb,
lib/graphql/schema/member/has_unresolved_type_error.rb,
lib/graphql/schema/validator/numericality_validator.rb,
lib/graphql/schema/build_from_definition/resolve_map.rb,
lib/graphql/schema/build_from_definition/resolve_map/default_resolve.rb more...
Overview
A GraphQL schema which may be queried with Query.
The Schema contains:
- types for exposing your application
- query analyzers for assessing incoming queries (including max depth & max complexity restrictions)
- execution strategies for running incoming queries
Schemas start with root types, Schema.query, Schema.mutation and Schema.subscription.
The schema will traverse the tree of fields & types, using those as starting points.
Any undiscoverable types may be provided with the types
configuration.
Schemas can restrict large incoming queries with max_depth
and max_complexity
configurations.
(These configurations can be overridden by specific calls to Schema.execute)
Schemas can specify how queries should be executed against them.
query_execution_strategy
, mutation_execution_strategy
and subscription_execution_strategy
each apply to corresponding root types.
Defined Under Namespace
Modules: Base64Encoder, BuildFromDefinition, FindInheritedValue, Interface, Loader, NullMask, ResolveTypeWithType, TypeExpression, UniqueWithinType
Classes: Addition, Argument, Directive, DuplicateNamesError, Enum, EnumValue, Field, FieldExtension, Finder, InputObject, IntrospectionSystem, InvalidDocumentError, InvalidTypeError, LateBoundType, List, Member, Mutation, NonNull, Object, Printer, RelayClassicMutation, Resolver, Scalar, Subscription, Timeout, TypeMembership, Union, UnresolvedLateBoundTypeError, Validator, Warden, Wrapper
Constant Summary
collapse
- NEW_HANDLER_HASH =
->(h, k) {
h[k] = {
class: k,
handler: nil,
subclass_handlers: Hash.new(&NEW_HANDLER_HASH),
}
}
- BUILT_IN_TYPES =
{
"Int" => GraphQL::Types::Int,
"String" => GraphQL::Types::String,
"Float" => GraphQL::Types::Float,
"Boolean" => GraphQL::Types::Boolean,
"ID" => GraphQL::Types::ID,
}
Class Attribute Summary collapse
#ast_node
Class Method Summary
collapse
-
.add_subscription_extension_if_necessary ⇒ Object
private
-
.after_any_lazies(maybe_lazies) ⇒ Object
private
Return a lazy if any of maybe_lazies
are lazy, otherwise, call the block eagerly and return the result.
-
.after_lazy(value, &block) ⇒ Object
private
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
).
-
.as_json(only: nil, except: nil, context: {}, include_deprecated_args: true, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false, include_is_one_of: false) ⇒ Hash
-
.context_class(new_context_class = nil) ⇒ Object
-
.cursor_encoder(new_encoder = nil) ⇒ Object
-
.default_analysis_engine ⇒ Object
-
.default_directives ⇒ Object
-
.default_execution_strategy ⇒ Object
-
.default_filter ⇒ Object
-
.default_mask(new_mask = nil) ⇒ Object
-
.default_max_page_size(new_default_max_page_size = nil) ⇒ Object
-
.default_page_size(new_default_page_size = nil) ⇒ Object
-
.deprecated_graphql_definition ⇒ Object
-
.description(new_description = nil) ⇒ String?
-
.directive(new_directive) ⇒ Object
Attach a single directive to this schema.
-
.directives(*new_directives) ⇒ Object
Add several directives at once.
-
.disable_introspection_entry_points ⇒ Object
-
.disable_introspection_entry_points? ⇒ Boolean
-
.disable_schema_introspection_entry_point ⇒ Object
-
.disable_schema_introspection_entry_point? ⇒ Boolean
-
.disable_type_introspection_entry_point ⇒ Object
-
.disable_type_introspection_entry_point? ⇒ Boolean
-
.error_handlers ⇒ Object
-
.execute(query_str = nil, **kwargs) ⇒ Hash
Execute a query on itself.
-
.find(path) ⇒ Object
-
.from_definition(definition_or_path, default_resolve: nil, parser: GraphQL.default_parser, using: {}) ⇒ Class
Create schema from an IDL schema or file containing an IDL definition.
-
.from_introspection(introspection_result) ⇒ Class<GraphQL::Schema>
Create schema with the result of an introspection query.
-
.get_field(type_or_name, field_name, context = GraphQL::Query::NullContext) ⇒ Object
-
.get_fields(type, context = GraphQL::Query::NullContext) ⇒ Object
-
.get_type(type_name, context = GraphQL::Query::NullContext) ⇒ Module?
A type, or nil if there’s no type called type_name
.
-
.handle_or_reraise(context, err) ⇒ Object
private
-
.id_from_object(object, type, ctx) ⇒ Object
-
.inherited(child_class) ⇒ Object
rubocop:enable Lint/DuplicateMethods.
-
.instrument(instrument_step, instrumenter, options = {}) ⇒ Object
-
.instrumenters ⇒ Object
-
.interpreter? ⇒ Boolean
-
.introspection(new_introspection_namespace = nil) ⇒ Object
-
.introspection_system ⇒ Object
-
.lazy?(obj) ⇒ Boolean
True if this object should be lazily resolved.
-
.lazy_method_name(obj) ⇒ Symbol?
The method name to lazily resolve obj
, or nil if obj
’s class wasn’t registered with #lazy_resolve.
-
.lazy_resolve(lazy_class, value_method) ⇒ Object
-
.multiplex(queries, **kwargs) ⇒ Array<Hash>
Execute several queries on itself, concurrently.
-
.multiplex_analyzer(new_analyzer) ⇒ Object
-
.multiplex_analyzers ⇒ Object
-
.mutation(new_mutation_object = nil) ⇒ Object
-
.mutation_execution_strategy(new_mutation_execution_strategy = nil) ⇒ Object
-
.new_connections? ⇒ Boolean
-
.new_trace(**options) ⇒ Object
-
.object_from_id(node_id, ctx) ⇒ Object
-
.orphan_types(*new_orphan_types) ⇒ Object
-
.parse_error(parse_err, ctx) ⇒ Object
A function to call when #execute receives an invalid query string.
-
.plugins ⇒ Object
-
.possible_types(type = nil, context = GraphQL::Query::NullContext) ⇒ Hash<String, Module>, Array<Module>
-
.query(new_query_object = nil) ⇒ Object
-
.query_analyzer(new_analyzer) ⇒ Object
-
.query_analyzers ⇒ Object
-
.query_execution_strategy(new_query_execution_strategy = nil) ⇒ Object
-
.query_stack_error(query, err) ⇒ Object
-
.references_to(to_type = nil, from: nil) ⇒ Object
-
.rescue_from(*err_classes, &handler_block) ⇒ Object
-
.resolve_type(type, obj, ctx) ⇒ Object
-
.root_type_for_operation(operation) ⇒ GraphQL::ObjectType?
-
.root_types ⇒ Object
-
.sanitized_printer(new_sanitized_printer = nil) ⇒ Object
-
.schema_directive(dir_class, **options) ⇒ Object
-
.schema_directives ⇒ Object
-
.static_validator ⇒ Object
-
.subscription(new_subscription_object = nil) ⇒ Object
-
.subscription_execution_strategy(new_subscription_execution_strategy = nil) ⇒ Object
-
.subscriptions(inherited: true) ⇒ GraphQL::Subscriptions
-
.subscriptions=(new_implementation) ⇒ Object
-
.sync_lazy(value) ⇒ Object
private
Override this method to handle lazy objects in a custom way.
-
.to_definition(only: nil, except: nil, context: {}) ⇒ String
Return the GraphQL IDL for the schema.
-
.to_document ⇒ GraphQL::Language::Document
Return the GraphQL::Language::Document IDL AST for the schema.
-
.to_json(**args) ⇒ String
-
.trace_class(new_class = nil) ⇒ Object
-
.trace_class_for(mode) ⇒ Class
Return the trace class to use for this mode, looking one up on the superclass if this Schema doesn’t have one defined.
-
.trace_mode(mode_name, trace_class) ⇒ Object
Configure trace_class
to be used whenever context: { trace_mode: mode_name }
is requested.
-
.trace_options ⇒ Object
-
.trace_with(trace_mod, **options) ⇒ void
Mix trace_mod
into this schema’s Trace
class so that its methods will be called at runtime.
-
.tracer(new_tracer) ⇒ Object
-
.tracers ⇒ Object
-
.type_error(type_error, ctx) ⇒ Object
-
.type_from_ast(ast_node, context: nil) ⇒ Object
-
.types(context = GraphQL::Query::NullContext) ⇒ Hash<String => Class>
Build a map of { name => type }
and return it.
-
.unauthorized_field(unauthorized_error) ⇒ Field
This hook is called when a field fails an authorized?
check.
-
.unauthorized_object(unauthorized_error) ⇒ Object
This hook is called when an object fails an authorized?
check.
-
.union_memberships(type = nil) ⇒ Object
-
.use(plugin, **kwargs) ⇒ Object
-
.using_ast_analysis? ⇒ Boolean
-
.validate(string_or_document, rules: nil, context: nil) ⇒ Array<GraphQL::StaticValidation::Error >
Validate a query string according to this schema.
-
.visible?(member, ctx) ⇒ Boolean
inherited
Class Attribute Details
.analysis_engine ⇒ Object
657
658
659
|
# File 'lib/graphql/schema.rb', line 657
def analysis_engine
@analysis_engine || find_inherited_value(:analysis_engine, self.default_analysis_engine)
end
|
342
343
344
345
346
347
348
349
350
351
352
353
354
355
|
# File 'lib/graphql/schema.rb', line 342
def connections
if defined?(@connections)
@connections
else
inherited_connections = find_inherited_value(:connections, nil)
if inherited_connections
@connections = Pagination::Connections.new(schema: self)
else
nil
end
end
end
|
.dataloader_class ⇒ 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.
.error_bubbling(new_error_bubbling = nil) ⇒ Object
671
672
673
674
675
676
677
|
# File 'lib/graphql/schema.rb', line 671
def error_bubbling(new_error_bubbling = nil)
if !new_error_bubbling.nil?
@error_bubbling = new_error_bubbling
else
@error_bubbling.nil? ? find_inherited_value(:error_bubbling) : @error_bubbling
end
end
|
.interpreter=(value) ⇒ Object
Sets the attribute interpreter
669
670
671
|
# File 'lib/graphql/schema.rb', line 669
def interpreter=(value)
@interpreter = value
end
|
.max_complexity(max_complexity = nil) ⇒ Object
645
646
647
648
649
650
651
652
653
|
# File 'lib/graphql/schema.rb', line 645
def max_complexity(max_complexity = nil)
if max_complexity
@max_complexity = max_complexity
elsif defined?(@max_complexity)
@max_complexity
else
find_inherited_value(:max_complexity)
end
end
|
.max_depth(new_max_depth = nil) ⇒ Object
683
684
685
686
687
688
689
690
691
|
# File 'lib/graphql/schema.rb', line 683
def max_depth(new_max_depth = nil)
if new_max_depth
@max_depth = new_max_depth
elsif defined?(@max_depth)
@max_depth
else
find_inherited_value(:max_depth)
end
end
|
.validate_max_errors(new_validate_max_errors = nil) ⇒ Object
633
634
635
636
637
638
639
640
641
|
# File 'lib/graphql/schema.rb', line 633
def validate_max_errors(new_validate_max_errors = nil)
if new_validate_max_errors
@validate_max_errors = new_validate_max_errors
elsif defined?(@validate_max_errors)
@validate_max_errors
else
find_inherited_value(:validate_max_errors)
end
end
|
.validate_timeout(new_validate_timeout = nil) ⇒ Object
604
605
606
607
608
609
610
611
612
|
# File 'lib/graphql/schema.rb', line 604
def validate_timeout(new_validate_timeout = nil)
if new_validate_timeout
@validate_timeout = new_validate_timeout
elsif defined?(@validate_timeout)
@validate_timeout
else
find_inherited_value(:validate_timeout)
end
end
|
Class Method Details
.add_subscription_extension_if_necessary ⇒ 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.
[View source]
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
|
# File 'lib/graphql/schema.rb', line 1080
def add_subscription_extension_if_necessary
if !defined?(@subscription_extension_added) && subscription && self.subscriptions
@subscription_extension_added = true
subscription.all_field_definitions.each do |field|
if !field.extensions.any? { |ext| ext.is_a?(Subscriptions::DefaultSubscriptionResolveExtension) }
field.extension(Subscriptions::DefaultSubscriptionResolveExtension)
end
end
end
end
|
.after_any_lazies(maybe_lazies) ⇒ 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.
Return a lazy if any of maybe_lazies
are lazy,
otherwise, call the block eagerly and return the result.
[View source]
1139
1140
1141
1142
1143
1144
1145
1146
1147
|
# File 'lib/graphql/schema.rb', line 1139
def after_any_lazies(maybe_lazies)
if maybe_lazies.any? { |l| lazy?(l) }
GraphQL::Execution::Lazy.all(maybe_lazies).then do |result|
yield result
end
else
yield maybe_lazies
end
end
|
.after_lazy(value, &block) ⇒ 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
)
[View source]
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
|
# File 'lib/graphql/schema.rb', line 1099
def after_lazy(value, &block)
if lazy?(value)
GraphQL::Execution::Lazy.new do
result = sync_lazy(value)
after_lazy(result, &block)
end
else
yield(value) if block_given?
end
end
|
.as_json(only: nil, except: nil, context: {}, include_deprecated_args: true, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false, include_is_one_of: false) ⇒ Hash
[View source]
200
201
202
203
204
205
206
207
208
209
210
|
# File 'lib/graphql/schema.rb', line 200
def as_json(only: nil, except: nil, context: {}, include_deprecated_args: true, include_schema_description: false, include_is_repeatable: false, include_specified_by_url: false, include_is_one_of: false)
introspection_query = Introspection.query(
include_deprecated_args: include_deprecated_args,
include_schema_description: include_schema_description,
include_is_repeatable: include_is_repeatable,
include_is_one_of: include_is_one_of,
include_specified_by_url: include_specified_by_url,
)
execute(introspection_query, only: only, except: except, context: context).to_h
end
|
.context_class(new_context_class = nil) ⇒ Object
[View source]
761
762
763
764
765
766
767
|
# File 'lib/graphql/schema.rb', line 761
def context_class(new_context_class = nil)
if new_context_class
@context_class = new_context_class
else
@context_class || find_inherited_value(:context_class, GraphQL::Query::Context)
end
end
|
.cursor_encoder(new_encoder = nil) ⇒ Object
[View source]
555
556
557
558
559
560
|
# File 'lib/graphql/schema.rb', line 555
def cursor_encoder(new_encoder = nil)
if new_encoder
@cursor_encoder = new_encoder
end
@cursor_encoder || find_inherited_value(:cursor_encoder, Base64Encoder)
end
|
.default_analysis_engine ⇒ Object
[View source]
753
754
755
756
757
758
759
|
# File 'lib/graphql/schema.rb', line 753
def default_analysis_engine
if superclass <= GraphQL::Schema
superclass.default_analysis_engine
else
@default_analysis_engine ||= GraphQL::Analysis::AST
end
end
|
.default_execution_strategy ⇒ Object
[View source]
745
746
747
748
749
750
751
|
# File 'lib/graphql/schema.rb', line 745
def default_execution_strategy
if superclass <= GraphQL::Schema
superclass.default_execution_strategy
else
@default_execution_strategy ||= GraphQL::Execution::Interpreter
end
end
|
.default_mask(new_mask = nil) ⇒ Object
[View source]
250
251
252
253
254
255
256
257
258
|
# File 'lib/graphql/schema.rb', line 250
def default_mask(new_mask = nil)
if new_mask
line = caller(2, 10).find { |l| !l.include?("lib/graphql") }
GraphQL::Deprecation.warn("GraphQL::Filter and Schema.mask are deprecated and will be removed in v2.1.0. Implement `visible?` on your schema members instead (https://graphql-ruby.org/authorization/visibility.html).\n #{line}")
@own_default_mask = new_mask
else
@own_default_mask || find_inherited_value(:default_mask, Schema::NullMask)
end
end
|
.default_max_page_size(new_default_max_page_size = nil) ⇒ Object
[View source]
562
563
564
565
566
567
568
|
# File 'lib/graphql/schema.rb', line 562
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 || find_inherited_value(:default_max_page_size)
end
end
|
.default_page_size(new_default_page_size = nil) ⇒ Object
[View source]
570
571
572
573
574
575
576
|
# File 'lib/graphql/schema.rb', line 570
def default_page_size(new_default_page_size = nil)
if new_default_page_size
@default_page_size = new_default_page_size
else
@default_page_size || find_inherited_value(:default_page_size)
end
end
|
.deprecated_graphql_definition ⇒ Object
[View source]
133
134
135
|
# File 'lib/graphql/schema.rb', line 133
def deprecated_graphql_definition
graphql_definition(silence_deprecation_warning: true)
end
|
.description(new_description = nil) ⇒ String?
[View source]
228
229
230
231
232
233
234
235
236
|
# File 'lib/graphql/schema.rb', line 228
def description(new_description = nil)
if new_description
@description = new_description
elsif defined?(@description)
@description
else
find_inherited_value(:description, nil)
end
end
|
.directive(new_directive) ⇒ Object
Attach a single directive to this schema
[View source]
950
951
952
|
# File 'lib/graphql/schema.rb', line 950
def directive(new_directive)
add_type_and_traverse(new_directive, root: false)
end
|
.directives(*new_directives) ⇒ Object
Add several directives at once
[View source]
939
940
941
942
943
944
945
|
# File 'lib/graphql/schema.rb', line 939
def directives(*new_directives)
if new_directives.any?
new_directives.flatten.each { |d| directive(d) }
end
find_inherited_value(:directives, default_directives).merge(own_directives)
end
|
.disable_introspection_entry_points ⇒ Object
[View source]
693
694
695
696
697
|
# File 'lib/graphql/schema.rb', line 693
def disable_introspection_entry_points
@disable_introspection_entry_points = true
@introspection_system = nil
end
|
.disable_introspection_entry_points? ⇒ Boolean
[View source]
711
712
713
714
715
716
717
|
# File 'lib/graphql/schema.rb', line 711
def disable_introspection_entry_points?
if instance_variable_defined?(:@disable_introspection_entry_points)
@disable_introspection_entry_points
else
find_inherited_value(:disable_introspection_entry_points?, false)
end
end
|
.disable_schema_introspection_entry_point ⇒ Object
[View source]
699
700
701
702
703
|
# File 'lib/graphql/schema.rb', line 699
def disable_schema_introspection_entry_point
@disable_schema_introspection_entry_point = true
@introspection_system = nil
end
|
.disable_schema_introspection_entry_point? ⇒ Boolean
[View source]
719
720
721
722
723
724
725
|
# File 'lib/graphql/schema.rb', line 719
def disable_schema_introspection_entry_point?
if instance_variable_defined?(:@disable_schema_introspection_entry_point)
@disable_schema_introspection_entry_point
else
find_inherited_value(:disable_schema_introspection_entry_point?, false)
end
end
|
.disable_type_introspection_entry_point ⇒ Object
[View source]
705
706
707
708
709
|
# File 'lib/graphql/schema.rb', line 705
def disable_type_introspection_entry_point
@disable_type_introspection_entry_point = true
@introspection_system = nil
end
|
.disable_type_introspection_entry_point? ⇒ Boolean
[View source]
727
728
729
730
731
732
733
|
# File 'lib/graphql/schema.rb', line 727
def disable_type_introspection_entry_point?
if instance_variable_defined?(:@disable_type_introspection_entry_point)
@disable_type_introspection_entry_point
else
find_inherited_value(:disable_type_introspection_entry_point?, false)
end
end
|
.error_handlers ⇒ Object
[View source]
783
784
785
786
787
788
789
|
# File 'lib/graphql/schema.rb', line 783
def error_handlers
@error_handlers ||= {
class: nil,
handler: nil,
subclass_handlers: Hash.new(&NEW_HANDLER_HASH),
}
end
|
.execute(query_str = nil, **kwargs) ⇒ Hash
Execute a query on itself.
[View source]
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
|
# File 'lib/graphql/schema.rb', line 1030
def execute(query_str = nil, **kwargs)
if query_str
kwargs[:query] = query_str
end
multiplex_context = if (ctx = kwargs[:context])
{
backtrace: ctx[:backtrace],
tracers: ctx[:tracers],
dataloader: ctx[:dataloader],
}
else
{}
end
all_results = multiplex([kwargs], max_complexity: nil, context: multiplex_context)
all_results[0]
end
|
.find(path) ⇒ Object
[View source]
238
239
240
241
242
243
244
|
# File 'lib/graphql/schema.rb', line 238
def find(path)
if !@finder
@find_cache = {}
@finder ||= GraphQL::Schema::Finder.new(self)
end
@find_cache[path] ||= @finder.find(path)
end
|
.from_definition(definition_or_path, default_resolve: nil, parser: GraphQL.default_parser, using: {}) ⇒ Class
Create schema from an IDL schema or file containing an IDL definition.
[View source]
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
# File 'lib/graphql/schema.rb', line 112
def from_definition(definition_or_path, default_resolve: nil, parser: GraphQL.default_parser, using: {})
if definition_or_path.end_with?(".graphql") || definition_or_path.end_with?(".graphqls")
GraphQL::Schema::BuildFromDefinition.from_definition_path(
self,
definition_or_path,
default_resolve: default_resolve,
parser: parser,
using: using,
)
else
GraphQL::Schema::BuildFromDefinition.from_definition(
self,
definition_or_path,
default_resolve: default_resolve,
parser: parser,
using: using,
)
end
end
|
.from_introspection(introspection_result) ⇒ Class<GraphQL::Schema>
Create schema with the result of an introspection query.
[View source]
102
103
104
|
# File 'lib/graphql/schema.rb', line 102
def from_introspection(introspection_result)
GraphQL::Schema::Loader.load(introspection_result)
end
|
.get_field(type_or_name, field_name, context = GraphQL::Query::NullContext) ⇒ Object
[View source]
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
|
# File 'lib/graphql/schema.rb', line 510
def get_field(type_or_name, field_name, context = GraphQL::Query::NullContext)
parent_type = case type_or_name
when LateBoundType
get_type(type_or_name.name, context)
when String
get_type(type_or_name, context)
when Module
type_or_name
else
raise GraphQL::InvariantError, "Unexpected field owner for #{field_name.inspect}: #{type_or_name.inspect} (#{type_or_name.class})"
end
if parent_type.kind.fields? && (field = parent_type.get_field(field_name, context))
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
|
.get_fields(type, context = GraphQL::Query::NullContext) ⇒ Object
[View source]
533
534
535
|
# File 'lib/graphql/schema.rb', line 533
def get_fields(type, context = GraphQL::Query::NullContext)
type.fields(context)
end
|
.get_type(type_name, context = GraphQL::Query::NullContext) ⇒ Module?
Returns A type, or nil if there’s no type called type_name
.
[View source]
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
|
# File 'lib/graphql/schema.rb', line 307
def get_type(type_name, context = GraphQL::Query::NullContext)
local_entry = own_types[type_name]
type_defn = case local_entry
when nil
nil
when Array
visible_t = nil
warden = Warden.from_context(context)
local_entry.each do |t|
if warden.visible_type?(t, context)
if visible_t.nil?
visible_t = t
else
raise DuplicateNamesError.new(
duplicated_name: type_name, duplicated_definition_1: visible_t.inspect, duplicated_definition_2: t.inspect
)
end
end
end
visible_t
when Module
local_entry
else
raise "Invariant: unexpected own_types[#{type_name.inspect}]: #{local_entry.inspect}"
end
type_defn ||
introspection_system.types[type_name] || (superclass.respond_to?(:get_type) ? superclass.get_type(type_name, context) : nil)
end
|
.handle_or_reraise(context, err) ⇒ 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.
[View source]
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
|
# File 'lib/graphql/schema.rb', line 792
def handle_or_reraise(context, err)
handler = Execution::Errors.find_handler_for(self, err.class)
if handler
obj = context[:current_object]
args = context[:current_arguments]
args = args && args.respond_to?(:keyword_arguments) ? args.keyword_arguments : nil
field = context[:current_field]
if obj.is_a?(GraphQL::Schema::Object)
obj = obj.object
end
handler[:handler].call(err, obj, args, context, field)
else
raise err
end
end
|
.id_from_object(object, type, ctx) ⇒ Object
[View source]
856
857
858
|
# File 'lib/graphql/schema.rb', line 856
def id_from_object(object, type, ctx)
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.id_from_object(object, type, ctx) must be implemented to create global ids (tried to create an id for `#{object.inspect}`)"
end
|
.inherited(child_class) ⇒ Object
rubocop:enable Lint/DuplicateMethods
[View source]
844
845
846
847
848
849
850
|
# File 'lib/graphql/schema.rb', line 844
def inherited(child_class)
if self == GraphQL::Schema
child_class.directives(default_directives.values)
end
child_class.singleton_class.prepend(ResolveTypeWithType)
super
end
|
.instrument(instrument_step, instrumenter, options = {}) ⇒ Object
[View source]
933
934
935
|
# File 'lib/graphql/schema.rb', line 933
def instrument(instrument_step, instrumenter, options = {})
own_instrumenters[instrument_step] << instrumenter
end
|
.instrumenters ⇒ Object
[View source]
1072
1073
1074
1075
1076
1077
|
# File 'lib/graphql/schema.rb', line 1072
def instrumenters
inherited_instrumenters = find_inherited_value(:instrumenters) || Hash.new { |h,k| h[k] = [] }
inherited_instrumenters.merge(own_instrumenters) do |_step, inherited, own|
inherited + own
end
end
|
.interpreter? ⇒ Boolean
[View source]
665
666
667
|
# File 'lib/graphql/schema.rb', line 665
def interpreter?
true
end
|
.introspection(new_introspection_namespace = nil) ⇒ Object
[View source]
537
538
539
540
541
542
543
544
545
|
# File 'lib/graphql/schema.rb', line 537
def introspection(new_introspection_namespace = nil)
if new_introspection_namespace
@introspection = new_introspection_namespace
@introspection_system = nil
else
@introspection || find_inherited_value(:introspection)
end
end
|
.introspection_system ⇒ Object
[View source]
547
548
549
550
551
552
553
|
# File 'lib/graphql/schema.rb', line 547
def introspection_system
if !@introspection_system
@introspection_system = Schema::IntrospectionSystem.new(self)
@introspection_system.resolve_late_bindings
end
@introspection_system
end
|
.lazy?(obj) ⇒ Boolean
Returns True if this object should be lazily resolved.
[View source]
1131
1132
1133
|
# File 'lib/graphql/schema.rb', line 1131
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 with #lazy_resolve.
[View source]
1126
1127
1128
|
# File 'lib/graphql/schema.rb', line 1126
def lazy_method_name(obj)
lazy_methods.get(obj)
end
|
.lazy_resolve(lazy_class, value_method) ⇒ Object
[View source]
929
930
931
|
# File 'lib/graphql/schema.rb', line 929
def lazy_resolve(lazy_class, value_method)
lazy_methods.set(lazy_class, value_method)
end
|
.multiplex(queries, **kwargs) ⇒ Array<Hash>
Execute several queries on itself, concurrently.
[View source]
.multiplex_analyzer(new_analyzer) ⇒ Object
[View source]
1011
1012
1013
|
# File 'lib/graphql/schema.rb', line 1011
def multiplex_analyzer(new_analyzer)
own_multiplex_analyzers << new_analyzer
end
|
.multiplex_analyzers ⇒ Object
[View source]
1015
1016
1017
|
# File 'lib/graphql/schema.rb', line 1015
def multiplex_analyzers
find_inherited_value(:multiplex_analyzers, EMPTY_ARRAY) + own_multiplex_analyzers
end
|
.mutation(new_mutation_object = nil) ⇒ Object
[View source]
375
376
377
378
379
380
381
382
383
384
385
386
387
|
# File 'lib/graphql/schema.rb', line 375
def mutation(new_mutation_object = nil)
if new_mutation_object
if @mutation_object
raise GraphQL::Error, "Second definition of `mutation(...)` (#{new_mutation_object.inspect}) is invalid, already configured with #{@mutation_object.inspect}"
else
@mutation_object = new_mutation_object
add_type_and_traverse(new_mutation_object, root: true)
nil
end
else
@mutation_object || find_inherited_value(:mutation)
end
end
|
.mutation_execution_strategy(new_mutation_execution_strategy = nil) ⇒ Object
[View source]
586
587
588
589
590
591
592
|
# File 'lib/graphql/schema.rb', line 586
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 || find_inherited_value(:mutation_execution_strategy, self.default_execution_strategy)
end
end
|
.new_connections? ⇒ Boolean
[View source]
357
358
359
|
# File 'lib/graphql/schema.rb', line 357
def new_connections?
!!connections
end
|
.new_trace(**options) ⇒ Object
[View source]
992
993
994
995
996
997
998
999
1000
1001
|
# File 'lib/graphql/schema.rb', line 992
def new_trace(**options)
options = trace_options.merge(options)
trace_mode = if (target = options[:query] || options[:multiplex]) && target.context[:backtrace]
:default_backtrace
else
:default
end
trace = trace_class_for(trace_mode).new(**options)
trace
end
|
.object_from_id(node_id, ctx) ⇒ Object
[View source]
852
853
854
|
# File 'lib/graphql/schema.rb', line 852
def object_from_id(node_id, ctx)
raise GraphQL::RequiredImplementationMissingError, "#{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
[View source]
735
736
737
738
739
740
741
742
743
|
# File 'lib/graphql/schema.rb', line 735
def orphan_types(*new_orphan_types)
if new_orphan_types.any?
new_orphan_types = new_orphan_types.flatten
add_type_and_traverse(new_orphan_types, root: false)
own_orphan_types.concat(new_orphan_types.flatten)
end
find_inherited_value(:orphan_types, EMPTY_ARRAY) + own_orphan_types
end
|
.parse_error(parse_err, ctx) ⇒ Object
A function to call when #execute receives an invalid query string
The default is to add the error to context.errors
[View source]
925
926
927
|
# File 'lib/graphql/schema.rb', line 925
def parse_error(parse_err, ctx)
ctx.errors.push(parse_err)
end
|
[View source]
273
274
275
|
# File 'lib/graphql/schema.rb', line 273
def plugins
find_inherited_value(:plugins, EMPTY_ARRAY) + own_plugins
end
|
.possible_types(type = nil, context = GraphQL::Query::NullContext) ⇒ Hash<String, Module>, Array<Module>
[View source]
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
|
# File 'lib/graphql/schema.rb', line 426
def possible_types(type = nil, context = GraphQL::Query::NullContext)
if type
if type.kind.union?
type.possible_types(context: context)
else
stored_possible_types = own_possible_types[type.graphql_name]
visible_possible_types = if stored_possible_types && type.kind.interface?
stored_possible_types.select do |possible_type|
possible_type.interfaces(context).include?(type)
end
else
stored_possible_types
end
visible_possible_types ||
introspection_system.possible_types[type.graphql_name] ||
(
superclass.respond_to?(:possible_types) ?
superclass.possible_types(type, context) :
EMPTY_ARRAY
)
end
else
find_inherited_value(:possible_types, EMPTY_HASH)
.merge(own_possible_types)
.merge(introspection_system.possible_types)
end
end
|
.query(new_query_object = nil) ⇒ Object
[View source]
361
362
363
364
365
366
367
368
369
370
371
372
373
|
# File 'lib/graphql/schema.rb', line 361
def query(new_query_object = nil)
if new_query_object
if @query_object
raise GraphQL::Error, "Second definition of `query(...)` (#{new_query_object.inspect}) is invalid, already configured with #{@query_object.inspect}"
else
@query_object = new_query_object
add_type_and_traverse(new_query_object, root: true)
nil
end
else
@query_object || find_inherited_value(:query)
end
end
|
.query_analyzer(new_analyzer) ⇒ Object
[View source]
1003
1004
1005
|
# File 'lib/graphql/schema.rb', line 1003
def query_analyzer(new_analyzer)
own_query_analyzers << new_analyzer
end
|
.query_analyzers ⇒ Object
[View source]
1007
1008
1009
|
# File 'lib/graphql/schema.rb', line 1007
def query_analyzers
find_inherited_value(:query_analyzers, EMPTY_ARRAY) + own_query_analyzers
end
|
.query_execution_strategy(new_query_execution_strategy = nil) ⇒ Object
[View source]
578
579
580
581
582
583
584
|
# File 'lib/graphql/schema.rb', line 578
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 || find_inherited_value(:query_execution_strategy, self.default_execution_strategy)
end
end
|
.query_stack_error(query, err) ⇒ Object
[View source]
1091
1092
1093
|
# File 'lib/graphql/schema.rb', line 1091
def query_stack_error(query, err)
query.context.errors.push(GraphQL::ExecutionError.new("This query is too large to execute."))
end
|
.references_to(to_type = nil, from: nil) ⇒ Object
[View source]
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
|
# File 'lib/graphql/schema.rb', line 478
def references_to(to_type = nil, from: nil)
@own_references_to ||= Hash.new { |h, k| h[k] = [] }
if to_type
if !to_type.is_a?(String)
to_type = to_type.graphql_name
end
if from
@own_references_to[to_type] << from
else
own_refs = @own_references_to[to_type]
inherited_refs = find_inherited_value(:references_to, EMPTY_HASH)[to_type] || EMPTY_ARRAY
own_refs + inherited_refs
end
else
inherited_value = find_inherited_value(:references_to, EMPTY_HASH)
if inherited_value.any?
inherited_value.merge(@own_references_to)
else
@own_references_to
end
end
end
|
.rescue_from(*err_classes, &handler_block) ⇒ Object
[View source]
769
770
771
772
773
|
# File 'lib/graphql/schema.rb', line 769
def rescue_from(*err_classes, &handler_block)
err_classes.each do |err_class|
Execution::Errors.register_rescue_from(err_class, error_handlers[:subclass_handlers], handler_block)
end
end
|
.resolve_type(type, obj, ctx) ⇒ Object
[View source]
835
836
837
838
839
840
841
|
# File 'lib/graphql/schema.rb', line 835
def resolve_type(type, obj, ctx)
if type.kind.object?
type
else
raise GraphQL::RequiredImplementationMissingError, "#{self.name}.resolve_type(type, obj, ctx) must be implemented to use Union types or Interface types (tried to resolve: #{type.name})"
end
end
|
.root_type_for_operation(operation) ⇒ GraphQL::ObjectType?
[View source]
406
407
408
409
410
411
412
413
414
415
416
417
|
# File 'lib/graphql/schema.rb', line 406
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_types ⇒ Object
[View source]
419
420
421
|
# File 'lib/graphql/schema.rb', line 419
def root_types
@root_types
end
|
.sanitized_printer(new_sanitized_printer = nil) ⇒ Object
[View source]
1019
1020
1021
1022
1023
1024
1025
|
# File 'lib/graphql/schema.rb', line 1019
def sanitized_printer(new_sanitized_printer = nil)
if new_sanitized_printer
@own_sanitized_printer = new_sanitized_printer
else
@own_sanitized_printer || GraphQL::Language::SanitizedPrinter
end
end
|
.schema_directive(dir_class, **options) ⇒ Object
[View source]
864
865
866
867
|
# File 'lib/graphql/schema.rb', line 864
def schema_directive(dir_class, **options)
@own_schema_directives ||= []
Member::HasDirectives.add_directive(self, @own_schema_directives, dir_class, options)
end
|
.subscription(new_subscription_object = nil) ⇒ Object
[View source]
389
390
391
392
393
394
395
396
397
398
399
400
401
402
|
# File 'lib/graphql/schema.rb', line 389
def subscription(new_subscription_object = nil)
if new_subscription_object
if @subscription_object
raise GraphQL::Error, "Second definition of `subscription(...)` (#{new_subscription_object.inspect}) is invalid, already configured with #{@subscription_object.inspect}"
else
@subscription_object = new_subscription_object
add_subscription_extension_if_necessary
add_type_and_traverse(new_subscription_object, root: true)
nil
end
else
@subscription_object || find_inherited_value(:subscription)
end
end
|
.subscription_execution_strategy(new_subscription_execution_strategy = nil) ⇒ Object
[View source]
594
595
596
597
598
599
600
|
# File 'lib/graphql/schema.rb', line 594
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 || find_inherited_value(:subscription_execution_strategy, self.default_execution_strategy)
end
end
|
[View source]
138
139
140
|
# File 'lib/graphql/schema.rb', line 138
def subscriptions(inherited: true)
defined?(@subscriptions) ? @subscriptions : (inherited ? find_inherited_value(:subscriptions, nil) : nil)
end
|
.subscriptions=(new_implementation) ⇒ Object
[View source]
142
143
144
|
# File 'lib/graphql/schema.rb', line 142
def subscriptions=(new_implementation)
@subscriptions = new_implementation
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.
Override this method to handle lazy objects in a custom way.
[View source]
1115
1116
1117
1118
1119
1120
1121
1122
1123
|
# File 'lib/graphql/schema.rb', line 1115
def sync_lazy(value)
lazy_method = lazy_method_name(value)
if lazy_method
synced_value = value.public_send(lazy_method)
sync_lazy(synced_value)
else
value
end
end
|
.to_definition(only: nil, except: nil, context: {}) ⇒ String
Return the GraphQL IDL for the schema
[View source]
217
218
219
|
# File 'lib/graphql/schema.rb', line 217
def to_definition(only: nil, except: nil, context: {})
GraphQL::Schema::Printer.print_schema(self, only: only, except: except, context: context)
end
|
.to_document ⇒ GraphQL::Language::Document
Return the GraphQL::Language::Document IDL AST for the schema
[View source]
.to_json(**args) ⇒ String
[View source]
186
187
188
|
# File 'lib/graphql/schema.rb', line 186
def to_json(**args)
JSON.pretty_generate(as_json(**args))
end
|
.trace_class(new_class = nil) ⇒ Object
[View source]
146
147
148
149
150
151
152
153
154
|
# File 'lib/graphql/schema.rb', line 146
def trace_class(new_class = nil)
if new_class
trace_mode(:default, new_class)
backtrace_class = Class.new(new_class)
backtrace_class.include(GraphQL::Backtrace::Trace)
trace_mode(:default_backtrace, backtrace_class)
end
trace_class_for(:default)
end
|
.trace_class_for(mode) ⇒ Class
Return the trace class to use for this mode, looking one up on the superclass if this Schema doesn’t have one defined.
[View source]
157
158
159
160
161
162
163
164
165
166
167
168
169
|
# File 'lib/graphql/schema.rb', line 157
def trace_class_for(mode)
@trace_modes ||= {}
@trace_modes[mode] ||= begin
base_class = if superclass.respond_to?(:trace_class_for)
superclass.trace_class_for(mode)
elsif mode == :default_backtrace
GraphQL::Backtrace::DefaultBacktraceTrace
else
GraphQL::Tracing::Trace
end
Class.new(base_class)
end
end
|
.trace_mode(mode_name, trace_class) ⇒ Object
Configure trace_class
to be used whenever context: { trace_mode: mode_name }
is requested.
:default
is used when no trace_mode: ...
is requested.
[View source]
176
177
178
179
180
|
# File 'lib/graphql/schema.rb', line 176
def trace_mode(mode_name, trace_class)
@trace_modes ||= {}
@trace_modes[mode_name] = trace_class
nil
end
|
.trace_options ⇒ Object
[View source]
988
989
990
|
# File 'lib/graphql/schema.rb', line 988
def trace_options
@trace_options ||= superclass.respond_to?(:trace_options) ? superclass.trace_options.dup : {}
end
|
.trace_with(trace_mod, **options) ⇒ void
This method returns an undefined value.
Mix trace_mod
into this schema’s Trace
class so that its methods
will be called at runtime.
[View source]
983
984
985
986
|
# File 'lib/graphql/schema.rb', line 983
def trace_with(trace_mod, **options)
trace_options.merge!(options)
trace_class.include(trace_mod)
end
|
.tracer(new_tracer) ⇒ Object
[View source]
963
964
965
966
967
968
969
970
971
|
# File 'lib/graphql/schema.rb', line 963
def tracer(new_tracer)
if defined?(@trace_modes) && !(trace_class_for(:default) < GraphQL::Tracing::LegacyTrace)
raise ArgumentError, "Can't add tracer after configuring a `trace_class`, use GraphQL::Tracing::LegacyTrace to merge legacy tracers into a trace class instead."
else
trace_mode(:default, Class.new(GraphQL::Tracing::LegacyTrace))
end
own_tracers << new_tracer
end
|
[View source]
973
974
975
|
# File 'lib/graphql/schema.rb', line 973
def tracers
find_inherited_value(:tracers, EMPTY_ARRAY) + own_tracers
end
|
.type_from_ast(ast_node, context: nil) ⇒ Object
[View source]
505
506
507
508
|
# File 'lib/graphql/schema.rb', line 505
def type_from_ast(ast_node, context: nil)
type_owner = context ? context.warden : self
GraphQL::Schema::TypeExpression.build_type(type_owner, ast_node)
end
|
.types(context = GraphQL::Query::NullContext) ⇒ Hash<String => Class>
Build a map of { name => type }
and return it
[View source]
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
|
# File 'lib/graphql/schema.rb', line 280
def types(context = GraphQL::Query::NullContext)
all_types = non_introspection_types.merge(introspection_system.types)
visible_types = {}
all_types.each do |k, v|
visible_types[k] =if v.is_a?(Array)
visible_t = nil
v.each do |t|
if t.visible?(context)
if visible_t.nil?
visible_t = t
else
raise DuplicateNamesError.new(
duplicated_name: k, duplicated_definition_1: visible_t.inspect, duplicated_definition_2: t.inspect
)
end
end
end
visible_t
else
v
end
end
visible_types
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.
[View source]
904
905
906
|
# File 'lib/graphql/schema.rb', line 904
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.
[View source]
888
889
890
|
# File 'lib/graphql/schema.rb', line 888
def unauthorized_object(unauthorized_error)
nil
end
|
.union_memberships(type = nil) ⇒ Object
[View source]
455
456
457
458
459
460
461
462
463
464
465
466
467
468
|
# File 'lib/graphql/schema.rb', line 455
def union_memberships(type = nil)
if type
own_um = own_union_memberships.fetch(type.graphql_name, EMPTY_ARRAY)
inherited_um = find_inherited_value(:union_memberships, EMPTY_HASH).fetch(type.graphql_name, EMPTY_ARRAY)
own_um + inherited_um
else
joined_um = own_union_memberships.dup
find_inherited_value(:union_memberhips, EMPTY_HASH).each do |k, v|
um = joined_um[k] ||= []
um.concat(v)
end
joined_um
end
end
|
.use(plugin, **kwargs) ⇒ Object
[View source]
264
265
266
267
268
269
270
271
|
# File 'lib/graphql/schema.rb', line 264
def use(plugin, **kwargs)
if kwargs.any?
plugin.use(self, **kwargs)
else
plugin.use(self)
end
own_plugins << [plugin, kwargs]
end
|
.using_ast_analysis? ⇒ Boolean
[View source]
661
662
663
|
# File 'lib/graphql/schema.rb', line 661
def using_ast_analysis?
true
end
|
.validate(string_or_document, rules: nil, context: nil) ⇒ Array<GraphQL::StaticValidation::Error >
Validate a query string according to this schema.
[View source]
617
618
619
620
621
622
623
624
625
626
627
628
629
|
# File 'lib/graphql/schema.rb', line 617
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, timeout: validate_timeout, max_errors: validate_max_errors)
res[:errors]
end
|
.visible?(member, ctx) ⇒ Boolean
[View source]
860
861
862
|
# File 'lib/graphql/schema.rb', line 860
def visible?(member, ctx)
member.visible?(ctx)
end
|