Class: GraphQL::Schema
- Inherits:
-
Object
- Object
- GraphQL::Schema
- Extended by:
- Forwardable, Define::InstanceDefinable::DeprecatedDefine, FindInheritedValue, LazyHandlingMethods, Member::AcceptsDefinition, Member::HasAstNode
- Includes:
- Define::InstanceDefinable, LazyHandlingMethods
- 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/validator.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/type_membership.rb,
lib/graphql/schema/middleware_chain.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/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/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_validators.rb,
lib/graphql/schema/member/instrumentation.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/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/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/member/cached_graphql_definition.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
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.
Defined Under Namespace
Modules: Base64Encoder, BuildFromDefinition, CatchallMiddleware, DefaultParseError, DefaultTypeError, FindInheritedValue, Interface, LazyHandlingMethods, Loader, NullMask, ResolveTypeWithType, TypeExpression, UniqueWithinType Classes: Argument, CyclicalDefinitionError, Directive, DuplicateTypeNamesError, 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, TypeMembership, Union, UnresolvedLateBoundTypeError, Validation, Validator, Warden, Wrapper
Constant Summary collapse
- DYNAMIC_FIELDS =
["__type", "__typename", "__schema"].freeze
- 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
-
.analysis_engine ⇒ Object
-
.connections ⇒ GraphQL::Pagination::Connections
If installed.
-
.dataloader_class ⇒ Object
private
-
.default_execution_strategy ⇒ Object
-
.error_bubbling(new_error_bubbling = nil) ⇒ Object
-
.interpreter ⇒ Object
writeonly
Sets the attribute interpreter.
-
.max_complexity(max_complexity = nil) ⇒ Object
-
.max_depth(new_max_depth = nil) ⇒ Object
-
.subscriptions ⇒ GraphQL::Subscriptions
-
.validate_timeout(new_validate_timeout = nil) ⇒ Object
Instance Attribute Summary collapse
-
#analysis_engine ⇒ Object
Returns the value of attribute analysis_engine.
-
#ast_node ⇒ Object
Returns the value of attribute ast_node.
-
#connections ⇒ Object
Returns the value of attribute connections.
-
#context_class ⇒ Class
Instantiated for each query.
-
#cursor_encoder ⇒ Object
Returns the value of attribute cursor_encoder.
-
#default_mask ⇒ <#call(member, ctx)>
A callable for filtering members of the schema.
-
#default_max_page_size ⇒ Object
Returns the value of attribute default_max_page_size.
-
#directives ⇒ Object
Returns the value of attribute directives.
-
#disable_introspection_entry_points ⇒ Object
[Boolean] True if this object disables the introspection entry point fields.
-
#disable_schema_introspection_entry_point ⇒ Object
[Boolean] True if this object disables the __schema introspection entry point field.
-
#disable_type_introspection_entry_point ⇒ Object
[Boolean] True if this object disables the __type introspection entry point field.
-
#error_bubbling ⇒ Object
[Boolean] True if this object bubbles validation errors up from a field into its parent InputObject, if there is one.
-
#id_from_object_proc ⇒ Object
readonly
Returns the value of attribute id_from_object_proc.
-
#instrumenters ⇒ Object
Returns the value of attribute instrumenters.
-
#introspection_namespace ⇒ Object
Returns the value of attribute introspection_namespace.
-
#lazy_methods ⇒ Object
Returns the value of attribute lazy_methods.
-
#max_complexity ⇒ Object
Returns the value of attribute max_complexity.
-
#max_depth ⇒ Object
Returns the value of attribute max_depth.
-
#middleware ⇒ MiddlewareChain
MiddlewareChain which is applied to fields during execution.
-
#multiplex_analyzers ⇒ Object
Returns the value of attribute multiplex_analyzers.
-
#mutation ⇒ Object
Returns the value of attribute mutation.
-
#mutation_execution_strategy ⇒ Object
Returns the value of attribute mutation_execution_strategy.
-
#object_from_id_proc ⇒ Object
readonly
Returns the value of attribute object_from_id_proc.
-
#orphan_types ⇒ Object
Returns the value of attribute orphan_types.
-
#query ⇒ Object
Returns the value of attribute query.
-
#query_analyzers ⇒ Object
Returns the value of attribute query_analyzers.
-
#query_execution_strategy ⇒ Object
Returns the value of attribute query_execution_strategy.
-
#raise_definition_error ⇒ Object
Returns the value of attribute raise_definition_error.
-
#resolve_type_proc ⇒ Object
readonly
Returns the value of attribute resolve_type_proc.
-
#static_validator ⇒ Object
readonly
Returns the value of attribute static_validator.
-
#subscription ⇒ Object
Returns the value of attribute subscription.
-
#subscription_execution_strategy ⇒ Object
Returns the value of attribute subscription_execution_strategy.
-
#subscriptions ⇒ GraphQL::Subscriptions
Single, long-lived instance of the provided subscriptions class, if there is one.
-
#tracers ⇒ Array<#trace(key, data)>
readonly
Tracers applied to every query.
-
#validate_timeout ⇒ Object
Returns the value of attribute validate_timeout.
Class Method Summary collapse
-
.accessible?(member, ctx) ⇒ Boolean
-
.add_subscription_extension_if_necessary ⇒ Object
private
-
.as_json(only: nil, except: nil, context: {}) ⇒ Hash
Return the Hash response of Introspection::INTROSPECTION_QUERY.
-
.context_class(new_context_class = nil) ⇒ Object
-
.cursor_encoder(new_encoder = nil) ⇒ Object
-
.default_analysis_engine ⇒ Object
-
.default_directives ⇒ Object
-
.default_filter ⇒ Object
-
.default_mask(new_mask = nil) ⇒ Object
-
.default_max_page_size(new_default_max_page_size = nil) ⇒ Object
-
.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_handler ⇒ GraphQL::Execution::Errors
-
.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) ⇒ GraphQL::Schema
Create schema with the result of an introspection query.
-
.get_field(type_or_name, field_name) ⇒ Object
-
.get_fields(type) ⇒ Object
-
.get_type(type_name) ⇒ Module?
A type, or nil if there’s no type called
type_name
. -
.graphql_definition ⇒ Object
-
.id_from_object(object, type, ctx) ⇒ Object
-
.inaccessible_fields(error) ⇒ AnalysisError?
This hook is called when a client tries to access one or more fields that fail the
accessible?
check. -
.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_resolve(lazy_class, value_method) ⇒ Object
-
.middleware(new_middleware = nil) ⇒ 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
-
.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
-
.static_validator ⇒ Object
-
.subscription(new_subscription_object = nil) ⇒ Object
-
.subscription_execution_strategy(new_subscription_execution_strategy = nil) ⇒ Object
-
.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_graphql ⇒ Object
-
.to_json(**args) ⇒ String
Returns the JSON response of Introspection::INTROSPECTION_QUERY.
-
.tracer(new_tracer) ⇒ Object
-
.tracers ⇒ Object
-
.type_error(type_err, ctx) ⇒ Object
-
.type_from_ast(ast_node, context: nil) ⇒ Object
-
.types ⇒ 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
-
.visible?(member, ctx) ⇒ Boolean
Instance Method Summary collapse
-
#accessible?(member, context) ⇒ Boolean
-
#as_json(only: nil, except: nil, context: {}) ⇒ Hash
Return the Hash response of Introspection::INTROSPECTION_QUERY.
-
#call_on_type_class(member, method_name, context, default:) ⇒ Object
Given this schema member, find the class-based definition object whose
method_name
should be treated as an application hook. -
#check_resolved_type(type, object, ctx = :__undefined__) ⇒ Object
private
This is a compatibility hack so that instance-level and class-level methods can get correctness checks without calling one another.
-
#dataloader_class ⇒ Object
-
#default_filter ⇒ Object
-
#deprecated_define(**kwargs, &block) ⇒ Object
-
#disable_introspection_entry_points? ⇒ Boolean
-
#disable_schema_introspection_entry_point? ⇒ Boolean
-
#disable_type_introspection_entry_point? ⇒ Boolean
-
#execute(query_str = nil, **kwargs) ⇒ Hash
Execute a query on itself.
-
#execution_strategy_for_operation(operation) ⇒ Object
-
#find(path) ⇒ GraphQL::BaseType, ...
Search for a schema member using a string path Schema.find(“Ensemble.musicians”).
-
#get_field(parent_type, field_name) ⇒ GraphQL::Field?
Resolve field named
field_name
for typeparent_type
. -
#get_fields(type) ⇒ Hash<String, GraphQL::Field>
Fields for this type, after instrumentation is applied.
-
#get_type(type_name) ⇒ Object
-
#id_from_object(object, type, ctx) ⇒ String
Get a unique identifier from this object.
-
#id_from_object=(new_proc) ⇒ Object
-
#initialize ⇒ Schema
constructor
A new instance of Schema.
-
#initialize_copy(other) ⇒ Object
-
#inspect ⇒ Object
-
#instrument(instrumentation_type, instrumenter) ⇒ void
Attach
instrumenter
to this schema for instrumenting events ofinstrumentation_type
. -
#interpreter? ⇒ Boolean
True if using the new Execution::Interpreter.
-
#introspection_system ⇒ Object
private
-
#multiplex(queries, **kwargs) ⇒ Array<Hash>
Execute several queries on itself.
-
#new_connections? ⇒ Boolean
-
#object_from_id(id, ctx) ⇒ Any
Fetch an application object by its unique id.
-
#object_from_id=(new_proc) ⇒ Object
-
#parse_error(err, ctx) ⇒ Object
A function to call when #execute receives an invalid query string.
-
#parse_error=(new_proc) ⇒ Object
-
#possible_types(type_defn, context = GraphQL::Query::NullContext) ⇒ Array<GraphQL::ObjectType>
Types which belong to
type_defn
in this schema. -
#references_to(type_name = nil) ⇒ Hash
Returns a list of Arguments and Fields referencing a certain type.
-
#remove_handler(*args, &block) ⇒ Object
-
#rescue_from(*args, &block) ⇒ Object
-
#resolve_type(type, object, ctx = :__undefined__) ⇒ GraphQL::ObjectType
Determine the GraphQL type for a given object.
-
#resolve_type=(new_resolve_type_proc) ⇒ Object
-
#root_type_for_operation(operation) ⇒ GraphQL::ObjectType?
-
#root_types ⇒ Array<GraphQL::BaseType>
The root types of this schema.
-
#to_definition(only: nil, except: nil, context: {}) ⇒ String
Return the GraphQL IDL for the schema.
-
#to_document(only: nil, except: nil, context: {}) ⇒ GraphQL::Language::Document
Return the GraphQL::Language::Document IDL AST for the schema.
-
#to_json(*args) ⇒ String
Returns the JSON response of Introspection::INTROSPECTION_QUERY.
-
#type_error(err, ctx) ⇒ Object
When we encounter a type error during query execution, we call this hook.
-
#type_error=(new_proc) ⇒ Object
-
#type_from_ast(ast_node, context:) ⇒ Object
-
#types ⇒ GraphQL::Schema::TypeMap
{ name => type }
pairs of types in this schema. -
#union_memberships(type) ⇒ Array<GraphQL::UnionType>
Returns a list of Union types in which a type is a member.
-
#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, context) ⇒ Boolean
Methods included from Define::InstanceDefinable::DeprecatedDefine
Methods included from LazyHandlingMethods
after_any_lazies, after_lazy, lazy?, lazy_method_name, sync_lazy
Methods included from Define::InstanceDefinable
Constructor Details
#initialize ⇒ Schema
Returns a new instance of Schema.
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
# File 'lib/graphql/schema.rb', line 266 def initialize @tracers = [] @definition_error = nil @orphan_types = [] @directives = {} self.class.default_directives.each do |name, dir| @directives[name] = dir.graphql_definition end @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 # For schema instances, default to legacy runtime modules @analysis_engine = GraphQL::Analysis @query_execution_strategy = GraphQL::Execution::Execute @mutation_execution_strategy = GraphQL::Execution::Execute @subscription_execution_strategy = GraphQL::Execution::Execute @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 @disable_schema_introspection_entry_point = false @disable_type_introspection_entry_point = false end |
Class Attribute Details
.analysis_engine ⇒ Object
1310 1311 1312 |
# File 'lib/graphql/schema.rb', line 1310 def analysis_engine @analysis_engine || find_inherited_value(:analysis_engine, self.default_analysis_engine) end |
.connections ⇒ GraphQL::Pagination::Connections
Returns if installed.
1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 |
# File 'lib/graphql/schema.rb', line 1030 def connections if defined?(@connections) @connections else inherited_connections = find_inherited_value(:connections, nil) # This schema is part of an inheritance chain which is using new connections, # make a new instance, so we don't pollute the upstream one. 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.
1162 1163 1164 |
# File 'lib/graphql/schema.rb', line 1162 def dataloader_class @dataloader_class || GraphQL::Dataloader::NullDataloader end |
.default_execution_strategy ⇒ Object
1401 1402 1403 1404 1405 1406 1407 |
# File 'lib/graphql/schema.rb', line 1401 def default_execution_strategy if superclass <= GraphQL::Schema superclass.default_execution_strategy else @default_execution_strategy ||= GraphQL::Execution::Interpreter end end |
.error_bubbling(new_error_bubbling = nil) ⇒ Object
1326 1327 1328 1329 1330 1331 1332 |
# File 'lib/graphql/schema.rb', line 1326 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 (writeonly)
Sets the attribute interpreter
1324 1325 1326 |
# File 'lib/graphql/schema.rb', line 1324 def interpreter=(value) @interpreter = value end |
.max_complexity(max_complexity = nil) ⇒ Object
1298 1299 1300 1301 1302 1303 1304 1305 1306 |
# File 'lib/graphql/schema.rb', line 1298 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
1338 1339 1340 1341 1342 1343 1344 1345 1346 |
# File 'lib/graphql/schema.rb', line 1338 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 |
.subscriptions ⇒ GraphQL::Subscriptions
872 873 874 |
# File 'lib/graphql/schema.rb', line 872 def subscriptions @subscriptions end |
.validate_timeout(new_validate_timeout = nil) ⇒ Object
1286 1287 1288 1289 1290 1291 1292 1293 1294 |
# File 'lib/graphql/schema.rb', line 1286 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 |
Instance Attribute Details
#analysis_engine ⇒ Object
Returns the value of attribute analysis_engine.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def analysis_engine @analysis_engine end |
#ast_node ⇒ Object
Returns the value of attribute ast_node.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def ast_node @ast_node end |
#connections ⇒ Object
Returns the value of attribute connections.
853 854 855 |
# File 'lib/graphql/schema.rb', line 853 def connections @connections end |
#context_class ⇒ Class
Returns Instantiated for each query.
227 228 229 |
# File 'lib/graphql/schema.rb', line 227 def context_class @context_class end |
#cursor_encoder ⇒ Object
Returns the value of attribute cursor_encoder.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def cursor_encoder @cursor_encoder end |
#default_mask ⇒ <#call(member, ctx)>
Returns A callable for filtering members of the schema.
223 224 225 |
# File 'lib/graphql/schema.rb', line 223 def default_mask @default_mask end |
#default_max_page_size ⇒ Object
Returns the value of attribute default_max_page_size.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def default_max_page_size @default_max_page_size end |
#directives ⇒ Object
Returns the value of attribute directives.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def directives @directives end |
#disable_introspection_entry_points ⇒ Object
[Boolean] True if this object disables the introspection entry point fields
230 231 232 |
# File 'lib/graphql/schema.rb', line 230 def disable_introspection_entry_points @disable_introspection_entry_points end |
#disable_schema_introspection_entry_point ⇒ Object
[Boolean] True if this object disables the __schema introspection entry point field
237 238 239 |
# File 'lib/graphql/schema.rb', line 237 def disable_schema_introspection_entry_point @disable_schema_introspection_entry_point end |
#disable_type_introspection_entry_point ⇒ Object
[Boolean] True if this object disables the __type introspection entry point field
244 245 246 |
# File 'lib/graphql/schema.rb', line 244 def disable_type_introspection_entry_point @disable_type_introspection_entry_point end |
#error_bubbling ⇒ Object
[Boolean] True if this object bubbles validation errors up from a field into its parent InputObject, if there is one.
212 213 214 |
# File 'lib/graphql/schema.rb', line 212 def error_bubbling @error_bubbling end |
#id_from_object_proc ⇒ Object (readonly)
Returns the value of attribute id_from_object_proc.
264 265 266 |
# File 'lib/graphql/schema.rb', line 264 def id_from_object_proc @id_from_object_proc end |
#instrumenters ⇒ Object
Returns the value of attribute instrumenters.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def instrumenters @instrumenters end |
#introspection_namespace ⇒ Object
Returns the value of attribute introspection_namespace.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def introspection_namespace @introspection_namespace end |
#lazy_methods ⇒ Object
Returns the value of attribute lazy_methods.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def lazy_methods @lazy_methods end |
#max_complexity ⇒ Object
Returns the value of attribute max_complexity.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def max_complexity @max_complexity end |
#max_depth ⇒ Object
Returns the value of attribute max_depth.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def max_depth @max_depth end |
#middleware ⇒ MiddlewareChain
Returns MiddlewareChain which is applied to fields during execution.
219 220 221 |
# File 'lib/graphql/schema.rb', line 219 def middleware @middleware end |
#multiplex_analyzers ⇒ Object
Returns the value of attribute multiplex_analyzers.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def multiplex_analyzers @multiplex_analyzers end |
#mutation ⇒ Object
Returns the value of attribute mutation.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def mutation @mutation end |
#mutation_execution_strategy ⇒ Object
Returns the value of attribute mutation_execution_strategy.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def mutation_execution_strategy @mutation_execution_strategy end |
#object_from_id_proc ⇒ Object (readonly)
Returns the value of attribute object_from_id_proc.
264 265 266 |
# File 'lib/graphql/schema.rb', line 264 def object_from_id_proc @object_from_id_proc end |
#orphan_types ⇒ Object
Returns the value of attribute orphan_types.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def orphan_types @orphan_types end |
#query ⇒ Object
Returns the value of attribute query.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def query @query end |
#query_analyzers ⇒ Object
Returns the value of attribute query_analyzers.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def query_analyzers @query_analyzers end |
#query_execution_strategy ⇒ Object
Returns the value of attribute query_execution_strategy.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def query_execution_strategy @query_execution_strategy end |
#raise_definition_error ⇒ Object
Returns the value of attribute raise_definition_error.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def raise_definition_error @raise_definition_error end |
#resolve_type_proc ⇒ Object (readonly)
Returns the value of attribute resolve_type_proc.
264 265 266 |
# File 'lib/graphql/schema.rb', line 264 def resolve_type_proc @resolve_type_proc end |
#static_validator ⇒ Object (readonly)
Returns the value of attribute static_validator.
264 265 266 |
# File 'lib/graphql/schema.rb', line 264 def static_validator @static_validator end |
#subscription ⇒ Object
Returns the value of attribute subscription.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def subscription @subscription end |
#subscription_execution_strategy ⇒ Object
Returns the value of attribute subscription_execution_strategy.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def subscription_execution_strategy @subscription_execution_strategy end |
#subscriptions ⇒ GraphQL::Subscriptions
Single, long-lived instance of the provided subscriptions class, if there is one.
216 217 218 |
# File 'lib/graphql/schema.rb', line 216 def subscriptions @subscriptions end |
#tracers ⇒ Array<#trace(key, data)> (readonly)
Returns Tracers applied to every query.
260 261 262 |
# File 'lib/graphql/schema.rb', line 260 def tracers @tracers end |
#validate_timeout ⇒ Object
Returns the value of attribute validate_timeout.
199 200 201 |
# File 'lib/graphql/schema.rb', line 199 def validate_timeout @validate_timeout end |
Class Method Details
.accessible?(member, ctx) ⇒ Boolean
1483 1484 1485 |
# File 'lib/graphql/schema.rb', line 1483 def accessible?(member, ctx) member.type_class.accessible?(ctx) end |
.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.
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 |
# File 'lib/graphql/schema.rb', line 1693 def add_subscription_extension_if_necessary if interpreter? && !defined?(@subscription_extension_added) && subscription && self.subscriptions @subscription_extension_added = true if subscription.singleton_class.ancestors.include?(Subscriptions::SubscriptionRoot) GraphQL::Deprecation.warn("`extend Subscriptions::SubscriptionRoot` is no longer required; you may remove it from #{self}'s `subscription` root type (#{subscription}).") else subscription.fields.each do |name, field| field.extension(Subscriptions::DefaultSubscriptionResolveExtension) end end end end |
.as_json(only: nil, except: nil, context: {}) ⇒ Hash
Return the Hash response of Introspection::INTROSPECTION_QUERY.
886 887 888 |
# File 'lib/graphql/schema.rb', line 886 def as_json(only: nil, except: nil, context: {}) execute(Introspection.query(include_deprecated_args: true), only: only, except: except, context: context).to_h end |
.context_class(new_context_class = nil) ⇒ Object
1417 1418 1419 1420 1421 1422 1423 |
# File 'lib/graphql/schema.rb', line 1417 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
1245 1246 1247 1248 1249 1250 |
# File 'lib/graphql/schema.rb', line 1245 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
1409 1410 1411 1412 1413 1414 1415 |
# File 'lib/graphql/schema.rb', line 1409 def default_analysis_engine if superclass <= GraphQL::Schema superclass.default_analysis_engine else @default_analysis_engine ||= GraphQL::Analysis::AST end end |
.default_directives ⇒ Object
1591 1592 1593 1594 1595 1596 1597 |
# File 'lib/graphql/schema.rb', line 1591 def default_directives @default_directives ||= { "include" => GraphQL::Schema::Directive::Include, "skip" => GraphQL::Schema::Directive::Skip, "deprecated" => GraphQL::Schema::Directive::Deprecated, }.freeze end |
.default_filter ⇒ Object
917 918 919 |
# File 'lib/graphql/schema.rb', line 917 def default_filter GraphQL::Filter.new(except: default_mask) end |
.default_mask(new_mask = nil) ⇒ Object
921 922 923 924 925 926 927 |
# File 'lib/graphql/schema.rb', line 921 def default_mask(new_mask = nil) if new_mask @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
1252 1253 1254 1255 1256 1257 1258 |
# File 'lib/graphql/schema.rb', line 1252 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 |
.directive(new_directive) ⇒ Object
Attach a single directive to this schema
1584 1585 1586 1587 1588 1589 |
# File 'lib/graphql/schema.rb', line 1584 def directive(new_directive) own_directives[new_directive.graphql_name] ||= begin add_type_and_traverse(new_directive, root: false) new_directive end end |
.directives(*new_directives) ⇒ Object
Add several directives at once
1573 1574 1575 1576 1577 1578 1579 |
# File 'lib/graphql/schema.rb', line 1573 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
1348 1349 1350 1351 1352 |
# File 'lib/graphql/schema.rb', line 1348 def disable_introspection_entry_points @disable_introspection_entry_points = true # TODO: this clears the cache made in `def types`. But this is not a great solution. @introspection_system = nil end |
.disable_introspection_entry_points? ⇒ Boolean
1366 1367 1368 1369 1370 1371 1372 |
# File 'lib/graphql/schema.rb', line 1366 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
1354 1355 1356 1357 1358 |
# File 'lib/graphql/schema.rb', line 1354 def disable_schema_introspection_entry_point @disable_schema_introspection_entry_point = true # TODO: this clears the cache made in `def types`. But this is not a great solution. @introspection_system = nil end |
.disable_schema_introspection_entry_point? ⇒ Boolean
1374 1375 1376 1377 1378 1379 1380 |
# File 'lib/graphql/schema.rb', line 1374 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
1360 1361 1362 1363 1364 |
# File 'lib/graphql/schema.rb', line 1360 def disable_type_introspection_entry_point @disable_type_introspection_entry_point = true # TODO: this clears the cache made in `def types`. But this is not a great solution. @introspection_system = nil end |
.disable_type_introspection_entry_point? ⇒ Boolean
1382 1383 1384 1385 1386 1387 1388 |
# File 'lib/graphql/schema.rb', line 1382 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_handler ⇒ GraphQL::Execution::Errors
1549 1550 1551 |
# File 'lib/graphql/schema.rb', line 1549 def error_handler @error_handler ||= GraphQL::Execution::Errors.new(self) end |
.execute(query_str = nil, **kwargs) ⇒ Hash
Execute a query on itself.
1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 |
# File 'lib/graphql/schema.rb', line 1639 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 |
.find(path) ⇒ Object
905 906 907 908 909 910 911 |
# File 'lib/graphql/schema.rb', line 905 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.
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 |
# File 'lib/graphql/schema.rb', line 793 def self.from_definition(definition_or_path, default_resolve: nil, parser: GraphQL.default_parser, using: {}) # If the file ends in `.graphql`, treat it like a filepath if definition_or_path.end_with?(".graphql") GraphQL::Schema::BuildFromDefinition.from_definition_path( definition_or_path, default_resolve: default_resolve, parser: parser, using: using, ) else GraphQL::Schema::BuildFromDefinition.from_definition( definition_or_path, default_resolve: default_resolve, parser: parser, using: using, ) end end |
.from_introspection(introspection_result) ⇒ GraphQL::Schema
Create schema with the result of an introspection query.
783 784 785 |
# File 'lib/graphql/schema.rb', line 783 def self.from_introspection(introspection_result) GraphQL::Schema::Loader.load(introspection_result) end |
.get_field(type_or_name, field_name) ⇒ Object
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 |
# File 'lib/graphql/schema.rb', line 1200 def get_field(type_or_name, field_name) parent_type = case type_or_name when LateBoundType get_type(type_or_name.name) when String get_type(type_or_name) when Module type_or_name else raise ArgumentError, "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)) 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) ⇒ Object
1223 1224 1225 |
# File 'lib/graphql/schema.rb', line 1223 def get_fields(type) type.fields end |
.get_type(type_name) ⇒ Module?
Returns A type, or nil if there’s no type called type_name
.
1020 1021 1022 1023 1024 |
# File 'lib/graphql/schema.rb', line 1020 def get_type(type_name) own_types[type_name] || introspection_system.types[type_name] || find_inherited_value(:types, EMPTY_HASH)[type_name] end |
.graphql_definition ⇒ Object
913 914 915 |
# File 'lib/graphql/schema.rb', line 913 def graphql_definition @graphql_definition ||= to_graphql end |
.id_from_object(object, type, ctx) ⇒ Object
1475 1476 1477 |
# File 'lib/graphql/schema.rb', line 1475 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 |
.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.
1495 1496 1497 |
# File 'lib/graphql/schema.rb', line 1495 def inaccessible_fields(error) error end |
.inherited(child_class) ⇒ Object
rubocop:enable Lint/DuplicateMethods
1463 1464 1465 1466 1467 1468 1469 |
# File 'lib/graphql/schema.rb', line 1463 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
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 |
# File 'lib/graphql/schema.rb', line 1557 def instrument(instrument_step, instrumenter, = {}) if instrument_step == :field GraphQL::Deprecation.warn "Field instrumentation (#{instrumenter.inspect}) will be removed in GraphQL-Ruby 2.0, please upgrade to field extensions: https://graphql-ruby.org/type_definitions/field_extensions.html" end step = if instrument_step == :field && [:after_built_ins] :field_after_built_ins else instrument_step end own_instrumenters[step] << instrumenter end |
.instrumenters ⇒ Object
1685 1686 1687 1688 1689 1690 |
# File 'lib/graphql/schema.rb', line 1685 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
1318 1319 1320 1321 1322 |
# File 'lib/graphql/schema.rb', line 1318 def interpreter? query_execution_strategy == GraphQL::Execution::Interpreter && mutation_execution_strategy == GraphQL::Execution::Interpreter && subscription_execution_strategy == GraphQL::Execution::Interpreter end |
.introspection(new_introspection_namespace = nil) ⇒ Object
1227 1228 1229 1230 1231 1232 1233 1234 1235 |
# File 'lib/graphql/schema.rb', line 1227 def introspection(new_introspection_namespace = nil) if new_introspection_namespace @introspection = new_introspection_namespace # reset this cached value: @introspection_system = nil else @introspection || find_inherited_value(:introspection) end end |
.introspection_system ⇒ Object
1237 1238 1239 1240 1241 1242 1243 |
# File 'lib/graphql/schema.rb', line 1237 def introspection_system if !@introspection_system @introspection_system = Schema::IntrospectionSystem.new(self) @introspection_system.resolve_late_bindings end @introspection_system end |
.lazy_resolve(lazy_class, value_method) ⇒ Object
1553 1554 1555 |
# File 'lib/graphql/schema.rb', line 1553 def lazy_resolve(lazy_class, value_method) lazy_methods.set(lazy_class, value_method) end |
.middleware(new_middleware = nil) ⇒ Object
1618 1619 1620 1621 1622 1623 1624 1625 1626 |
# File 'lib/graphql/schema.rb', line 1618 def middleware(new_middleware = nil) if new_middleware GraphQL::Deprecation.warn "Middleware will be removed in GraphQL-Ruby 2.0, please upgrade to Field Extensions: https://graphql-ruby.org/type_definitions/field_extensions.html" own_middleware << new_middleware else # TODO make sure this is cached when running a query MiddlewareChain.new(steps: all_middleware, final_step: GraphQL::Execution::Execute::FieldResolveStep) end end |
.multiplex(queries, **kwargs) ⇒ Array<Hash>
Execute several queries on itself, concurrently.
1676 1677 1678 1679 1680 1681 1682 1683 |
# File 'lib/graphql/schema.rb', line 1676 def multiplex(queries, **kwargs) schema = if interpreter? self else graphql_definition end GraphQL::Execution::Multiplex.run_all(schema, queries, **kwargs) end |
.multiplex_analyzer(new_analyzer) ⇒ Object
1628 1629 1630 |
# File 'lib/graphql/schema.rb', line 1628 def multiplex_analyzer(new_analyzer) own_multiplex_analyzers << new_analyzer end |
.multiplex_analyzers ⇒ Object
1632 1633 1634 |
# File 'lib/graphql/schema.rb', line 1632 def multiplex_analyzers find_inherited_value(:multiplex_analyzers, EMPTY_ARRAY) + own_multiplex_analyzers end |
.mutation(new_mutation_object = nil) ⇒ Object
1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 |
# File 'lib/graphql/schema.rb', line 1063 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
1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/graphql/schema.rb', line 1268 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
1045 1046 1047 |
# File 'lib/graphql/schema.rb', line 1045 def new_connections? !!connections end |
.object_from_id(node_id, ctx) ⇒ Object
1471 1472 1473 |
# File 'lib/graphql/schema.rb', line 1471 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
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 |
# File 'lib/graphql/schema.rb', line 1390 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) @orphan_types = new_orphan_types 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
1544 1545 1546 |
# File 'lib/graphql/schema.rb', line 1544 def parse_error(parse_err, ctx) ctx.errors.push(parse_err) end |
.plugins ⇒ Object
942 943 944 |
# File 'lib/graphql/schema.rb', line 942 def plugins find_inherited_value(:plugins, EMPTY_ARRAY) + own_plugins end |
.possible_types(type = nil, context = GraphQL::Query::NullContext) ⇒ Hash<String, Module>, Array<Module>
1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 |
# File 'lib/graphql/schema.rb', line 1114 def possible_types(type = nil, context = GraphQL::Query::NullContext) if type # TODO duck-typing `.possible_types` would probably be nicer here 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| # Use `.graphql_name` comparison to match legacy vs class-based types. # When we don't need to support legacy `.define` types, use `.include?(type)` instead. possible_type.interfaces(context).any? { |interface| interface.graphql_name == type.graphql_name } 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
1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 |
# File 'lib/graphql/schema.rb', line 1049 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
1607 1608 1609 1610 1611 1612 |
# File 'lib/graphql/schema.rb', line 1607 def query_analyzer(new_analyzer) if new_analyzer == GraphQL::Authorization::Analyzer GraphQL::Deprecation.warn("The Authorization query analyzer is deprecated. Authorizing at query runtime is generally a better idea.") end own_query_analyzers << new_analyzer end |
.query_analyzers ⇒ Object
1614 1615 1616 |
# File 'lib/graphql/schema.rb', line 1614 def query_analyzers find_inherited_value(:query_analyzers, EMPTY_ARRAY) + own_query_analyzers end |
.query_execution_strategy(new_query_execution_strategy = nil) ⇒ Object
1260 1261 1262 1263 1264 1265 1266 |
# File 'lib/graphql/schema.rb', line 1260 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
1706 1707 1708 |
# File 'lib/graphql/schema.rb', line 1706 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
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 |
# File 'lib/graphql/schema.rb', line 1168 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 # `@own_references_to` can be quite large for big schemas, # and generally speaking, we won't inherit any values. # So optimize the most common case -- don't create a duplicate Hash. 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
1425 1426 1427 1428 1429 |
# File 'lib/graphql/schema.rb', line 1425 def rescue_from(*err_classes, &handler_block) err_classes.each do |err_class| error_handler.rescue_from(err_class, handler_block) end end |
.resolve_type(type, obj, ctx) ⇒ Object
1454 1455 1456 1457 1458 1459 1460 |
# File 'lib/graphql/schema.rb', line 1454 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?
1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 |
# File 'lib/graphql/schema.rb', line 1094 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
1107 1108 1109 |
# File 'lib/graphql/schema.rb', line 1107 def root_types @root_types end |
.static_validator ⇒ Object
929 930 931 |
# File 'lib/graphql/schema.rb', line 929 def static_validator GraphQL::StaticValidation::Validator.new(schema: self) end |
.subscription(new_subscription_object = nil) ⇒ Object
1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 |
# File 'lib/graphql/schema.rb', line 1077 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
1276 1277 1278 1279 1280 1281 1282 |
# File 'lib/graphql/schema.rb', line 1276 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 |
.to_definition(only: nil, except: nil, context: {}) ⇒ String
Return the GraphQL IDL for the schema
895 896 897 |
# File 'lib/graphql/schema.rb', line 895 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
901 902 903 |
# File 'lib/graphql/schema.rb', line 901 def to_document GraphQL::Language::DocumentFromSchemaDefinition.new(self).document end |
.to_graphql ⇒ Object
946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 |
# File 'lib/graphql/schema.rb', line 946 def to_graphql schema_defn = self.new schema_defn.raise_definition_error = true schema_defn.query = query && query.graphql_definition schema_defn.mutation = mutation && mutation.graphql_definition schema_defn.subscription = subscription && subscription.graphql_definition schema_defn.validate_timeout = validate_timeout 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.map(&:graphql_definition) schema_defn.disable_introspection_entry_points = disable_introspection_entry_points? schema_defn.disable_schema_introspection_entry_point = disable_schema_introspection_entry_point? schema_defn.disable_type_introspection_entry_point = disable_type_introspection_entry_point? 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(tracers) schema_defn.query_analyzers.concat(query_analyzers) schema_defn.analysis_engine = analysis_engine schema_defn.middleware.concat(all_middleware) schema_defn.multiplex_analyzers.concat(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 schema_defn.default_mask = default_mask instrumenters.each do |step, insts| insts.each do |inst| schema_defn.instrumenters[step] << inst end end lazy_methods.each do |lazy_class, value_method| schema_defn.lazy_methods.set(lazy_class, value_method) end error_handler.each_rescue do |err_class, handler| schema_defn.rescue_from(err_class, &handler) end schema_defn.subscriptions ||= self.subscriptions if !schema_defn.interpreter? schema_defn.instrumenters[:query] << GraphQL::Schema::Member::Instrumentation end if new_connections? schema_defn.connections = self.connections end schema_defn.send(:rebuild_artifacts) schema_defn end |
.to_json(**args) ⇒ String
Returns the JSON response of Introspection::INTROSPECTION_QUERY.
877 878 879 |
# File 'lib/graphql/schema.rb', line 877 def to_json(**args) JSON.pretty_generate(as_json(**args)) end |
.tracer(new_tracer) ⇒ Object
1599 1600 1601 |
# File 'lib/graphql/schema.rb', line 1599 def tracer(new_tracer) own_tracers << new_tracer end |
.tracers ⇒ Object
1603 1604 1605 |
# File 'lib/graphql/schema.rb', line 1603 def tracers find_inherited_value(:tracers, EMPTY_ARRAY) + own_tracers end |
.type_error(type_err, ctx) ⇒ Object
1534 1535 1536 |
# File 'lib/graphql/schema.rb', line 1534 def type_error(type_err, ctx) DefaultTypeError.call(type_err, ctx) end |
.type_from_ast(ast_node, context: nil) ⇒ Object
1195 1196 1197 1198 |
# File 'lib/graphql/schema.rb', line 1195 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 ⇒ Hash<String => Class>
Build a map of { name => type }
and return it
1014 1015 1016 |
# File 'lib/graphql/schema.rb', line 1014 def types non_introspection_types.merge(introspection_system.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.
1530 1531 1532 |
# File 'lib/graphql/schema.rb', line 1530 def () () 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.
1514 1515 1516 |
# File 'lib/graphql/schema.rb', line 1514 def () nil end |
.union_memberships(type = nil) ⇒ Object
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 |
# File 'lib/graphql/schema.rb', line 1145 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
933 934 935 936 937 938 939 940 |
# File 'lib/graphql/schema.rb', line 933 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
1314 1315 1316 |
# File 'lib/graphql/schema.rb', line 1314 def using_ast_analysis? analysis_engine == GraphQL::Analysis::AST end |
.visible?(member, ctx) ⇒ Boolean
1479 1480 1481 |
# File 'lib/graphql/schema.rb', line 1479 def visible?(member, ctx) member.type_class.visible?(ctx) end |
Instance Method Details
#accessible?(member, context) ⇒ Boolean
743 744 745 |
# File 'lib/graphql/schema.rb', line 743 def accessible?(member, context) call_on_type_class(member, :accessible?, context, default: true) end |
#as_json(only: nil, except: nil, context: {}) ⇒ Hash
Return the Hash response of Introspection::INTROSPECTION_QUERY.
838 839 840 |
# File 'lib/graphql/schema.rb', line 838 def as_json(only: nil, except: nil, context: {}) execute(Introspection.query(include_deprecated_args: true), only: only, except: except, context: context).to_h end |
#call_on_type_class(member, method_name, context, default:) ⇒ Object
Given this schema member, find the class-based definition object
whose method_name
should be treated as an application hook
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 |
# File 'lib/graphql/schema.rb', line 721 def call_on_type_class(member, method_name, context, default:) member = if member.respond_to?(:type_class) member.type_class else member end if member.respond_to?(:relay_node_type) && (t = member.relay_node_type) member = t end if member.respond_to?(method_name) member.public_send(method_name, context) else default end 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
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 |
# File 'lib/graphql/schema.rb', line 618 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 |
#dataloader_class ⇒ Object
1975 1976 1977 |
# File 'lib/graphql/schema.rb', line 1975 def dataloader_class self.class.dataloader_class end |
#default_filter ⇒ Object
254 255 256 |
# File 'lib/graphql/schema.rb', line 254 def default_filter GraphQL::Filter.new(except: default_mask) end |
#deprecated_define(**kwargs, &block) ⇒ Object
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 |
# File 'lib/graphql/schema.rb', line 375 def deprecated_define(**kwargs, &block) super ensure_defined # Assert that all necessary configs are present: validation_error = Validation.validate(self) validation_error && raise(GraphQL::RequiredImplementationMissingError, validation_error) rebuild_artifacts @definition_error = nil nil rescue StandardError => err if @raise_definition_error || err.is_a?(CyclicalDefinitionError) || err.is_a?(GraphQL::RequiredImplementationMissingError) raise else # Raise this error _later_ to avoid messing with Rails constant loading @definition_error = err end nil end |
#disable_introspection_entry_points? ⇒ Boolean
232 233 234 |
# File 'lib/graphql/schema.rb', line 232 def disable_introspection_entry_points? !!@disable_introspection_entry_points end |
#disable_schema_introspection_entry_point? ⇒ Boolean
239 240 241 |
# File 'lib/graphql/schema.rb', line 239 def disable_schema_introspection_entry_point? !!@disable_schema_introspection_entry_point end |
#disable_type_introspection_entry_point? ⇒ Boolean
246 247 248 |
# File 'lib/graphql/schema.rb', line 246 def disable_type_introspection_entry_point? !!@disable_type_introspection_entry_point end |
#execute(query_str = nil, **kwargs) ⇒ Hash
Execute a query on itself. Raises an error if the schema definition is invalid.
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
# File 'lib/graphql/schema.rb', line 458 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
586 587 588 589 590 591 592 593 594 595 596 597 |
# File 'lib/graphql/schema.rb', line 586 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”)
508 509 510 511 |
# File 'lib/graphql/schema.rb', line 508 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
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 |
# File 'lib/graphql/schema.rb', line 519 def get_field(parent_type, field_name) with_definition_error_check do parent_type_name = case parent_type when GraphQL::BaseType, Class, Module parent_type.graphql_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
545 546 547 |
# File 'lib/graphql/schema.rb', line 545 def get_fields(type) @instrumented_field_map[type.graphql_name] end |
#get_type(type_name) ⇒ Object
423 424 425 |
# File 'lib/graphql/schema.rb', line 423 def get_type(type_name) @types[type_name] end |
#id_from_object(object, type, ctx) ⇒ String
Get a unique identifier from this object
767 768 769 770 771 772 773 |
# File 'lib/graphql/schema.rb', line 767 def id_from_object(object, type, ctx) if @id_from_object_proc.nil? raise(GraphQL::RequiredImplementationMissingError, "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
776 777 778 |
# File 'lib/graphql/schema.rb', line 776 def id_from_object=(new_proc) @id_from_object_proc = new_proc end |
#initialize_copy(other) ⇒ Object
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 |
# File 'lib/graphql/schema.rb', line 315 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 |
#inspect ⇒ Object
311 312 313 |
# File 'lib/graphql/schema.rb', line 311 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
.
399 400 401 402 403 404 |
# File 'lib/graphql/schema.rb', line 399 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.
305 306 307 308 309 |
# File 'lib/graphql/schema.rb', line 305 def interpreter? query_execution_strategy == GraphQL::Execution::Interpreter && mutation_execution_strategy == GraphQL::Execution::Interpreter && subscription_execution_strategy == GraphQL::Execution::Interpreter end |
#introspection_system ⇒ 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.
428 429 430 431 432 433 |
# File 'lib/graphql/schema.rb', line 428 def introspection_system @introspection_system ||= begin rebuild_artifacts @introspection_system end end |
#multiplex(queries, **kwargs) ⇒ Array<Hash>
Execute several queries on itself. Raises an error if the schema definition is invalid.
494 495 496 497 498 |
# File 'lib/graphql/schema.rb', line 494 def multiplex(queries, **kwargs) with_definition_error_check { GraphQL::Execution::Multiplex.run_all(self, queries, **kwargs) } end |
#new_connections? ⇒ Boolean
849 850 851 |
# File 'lib/graphql/schema.rb', line 849 def new_connections? !!connections end |
#object_from_id(id, ctx) ⇒ Any
Fetch an application object by its unique id
668 669 670 671 672 673 674 |
# File 'lib/graphql/schema.rb', line 668 def object_from_id(id, ctx) if @object_from_id_proc.nil? raise(GraphQL::RequiredImplementationMissingError, "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
677 678 679 |
# File 'lib/graphql/schema.rb', line 677 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
753 754 755 |
# File 'lib/graphql/schema.rb', line 753 def parse_error(err, ctx) @parse_error_proc.call(err, ctx) end |
#parse_error=(new_proc) ⇒ Object
758 759 760 |
# File 'lib/graphql/schema.rb', line 758 def parse_error=(new_proc) @parse_error_proc = new_proc end |
#possible_types(type_defn, context = GraphQL::Query::NullContext) ⇒ Array<GraphQL::ObjectType>
Returns types which belong to type_defn
in this schema.
557 558 559 560 561 562 563 564 565 566 567 568 569 |
# File 'lib/graphql/schema.rb', line 557 def possible_types(type_defn, context = GraphQL::Query::NullContext) if context == GraphQL::Query::NullContext @possible_types ||= GraphQL::Schema::PossibleTypes.new(self) @possible_types.possible_types(type_defn, context) else # Use the incoming context to cache this instance -- # if it were cached on the schema, we'd have a memory leak # https://github.com/rmosolgo/graphql-ruby/issues/2878 ns = context.namespace(:possible_types) per_query_possible_types = ns[:possible_types] ||= GraphQL::Schema::PossibleTypes.new(self) per_query_possible_types.possible_types(type_defn, context) end end |
#references_to(type_name = nil) ⇒ Hash
Returns a list of Arguments and Fields referencing a certain type
438 439 440 441 442 443 444 445 |
# File 'lib/graphql/schema.rb', line 438 def references_to(type_name = nil) rebuild_artifacts unless defined?(@type_reference_map) if type_name @type_reference_map.fetch(type_name, []) else @type_reference_map end end |
#remove_handler(*args, &block) ⇒ Object
347 348 349 |
# File 'lib/graphql/schema.rb', line 347 def remove_handler(*args, &block) rescue_middleware.remove_handler(*args, &block) end |
#rescue_from(*args, &block) ⇒ Object
343 344 345 |
# File 'lib/graphql/schema.rb', line 343 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)
606 607 608 609 610 611 612 613 |
# File 'lib/graphql/schema.rb', line 606 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(GraphQL::RequiredImplementationMissingError, "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
659 660 661 662 |
# File 'lib/graphql/schema.rb', line 659 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?
573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/graphql/schema.rb', line 573 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 ⇒ Array<GraphQL::BaseType>
Returns The root types of this schema.
407 408 409 410 411 412 |
# File 'lib/graphql/schema.rb', line 407 def root_types @root_types ||= begin rebuild_artifacts @root_types end end |
#to_definition(only: nil, except: nil, context: {}) ⇒ String
Return the GraphQL IDL for the schema
820 821 822 |
# File 'lib/graphql/schema.rb', line 820 def to_definition(only: nil, except: nil, context: {}) GraphQL::Schema::Printer.print_schema(self, only: only, except: except, context: context) end |
#to_document(only: nil, except: nil, context: {}) ⇒ GraphQL::Language::Document
Return the GraphQL::Language::Document IDL AST for the schema
829 830 831 |
# File 'lib/graphql/schema.rb', line 829 def to_document(only: nil, except: nil, context: {}) GraphQL::Language::DocumentFromSchemaDefinition.new(self, only: only, except: except, context: context).document end |
#to_json(*args) ⇒ String
Returns the JSON response of Introspection::INTROSPECTION_QUERY.
845 846 847 |
# File 'lib/graphql/schema.rb', line 845 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.
701 702 703 |
# File 'lib/graphql/schema.rb', line 701 def type_error(err, ctx) @type_error_proc.call(err, ctx) end |
#type_error=(new_proc) ⇒ Object
706 707 708 |
# File 'lib/graphql/schema.rb', line 706 def type_error=(new_proc) @type_error_proc = new_proc end |
#type_from_ast(ast_node, context:) ⇒ Object
549 550 551 |
# File 'lib/graphql/schema.rb', line 549 def type_from_ast(ast_node, context:) GraphQL::Schema::TypeExpression.build_type(self, ast_node) end |
#types ⇒ GraphQL::Schema::TypeMap
Returns { name => type }
pairs of types in this schema.
416 417 418 419 420 421 |
# File 'lib/graphql/schema.rb', line 416 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
450 451 452 453 |
# File 'lib/graphql/schema.rb', line 450 def union_memberships(type) rebuild_artifacts unless defined?(@union_memberships) @union_memberships.fetch(type.name, []) end |
#using_ast_analysis? ⇒ Boolean
351 352 353 |
# File 'lib/graphql/schema.rb', line 351 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.
361 362 363 364 365 366 367 368 369 370 371 372 373 |
# File 'lib/graphql/schema.rb', line 361 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) res[:errors] end |
#visible?(member, context) ⇒ Boolean
739 740 741 |
# File 'lib/graphql/schema.rb', line 739 def visible?(member, context) call_on_type_class(member, :visible?, context, default: true) end |