GraphQL class

A Dart implementation of a GraphQL server.

Parses, validates and executes GraphQL requests using the provided GraphQLSchema.

Constructors

GraphQL(GraphQLSchema schema, {bool? introspect, bool? validate, FutureOr<Object?> defaultFieldResolver(Object? parent, Ctx)?, List<GraphQLExtension> extensions = const [], List<ValidationRule> customValidationRules = const [], ScopedMap? globalVariables})
A Dart implementation of a GraphQL server.
GraphQL.fromConfig(GraphQLSchema schema, GraphQLConfig config)
Creates a GraphQL executor from a GraphQLConfig
factory

Properties

baseGlobalVariables ScopedMap
Variables passed to all executed requests
final
customValidationRules List<ValidationRule>
Custom validation rules performed to a request's document before the execution phase
final
defaultFieldResolver → (FutureOr<Object?> Function(Object? parent, Ctx)?)
An optional callback that can be used to resolve fields from objects that are not Maps, when the related field has no resolver.
final
extensions List<GraphQLExtension>
Extensions implement additional functionalities to the server's parsing, validation and execution. For example, extensions for tracing GraphQLTracingExtension, logging, error handling or caching GraphQLPersistedQueries
final
hashCode int
The hash code for this object.
no setterinherited
introspect bool
Whether to introspect the GraphQLSchema
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
schema → GraphQLSchema
The schema used for executing GraphQL requests
final
validate bool
If validate is false, a parsed document is executed without being validated with the provided schema
final

Methods

coerceArgumentValues(SerdeCtx serdeCtx, GraphQLObjectField desiredField, FieldNode field, Map<String, dynamic> variableValues) Map<String, dynamic>
coerceVariableValues(GraphQLSchema schema, OperationDefinitionNode operation, Map<String, dynamic>? variableValues) Map<String, dynamic>
completeValue(ObjectExecutionCtx ctx, String fieldName, GraphQLType fieldType, List<SelectionNode> fields, Object? _result, {required Object pathItem, required Ctx reqCtx}) Future<Object?>
Returns the serialized value of type fieldType from a resolved _result for fieldName given the Object context ctx
createSourceEventStream(ExecutionCtx baseCtx, OperationDefinitionNode subscription, GraphQLSchema schema, Object rootValue) Future<MapEntry<FieldNode, Stream<Object?>>>
executeField<T, P>(List<FieldNode> fields, ObjectExecutionCtx<P> ctx, GraphQLObjectField<T, Object?, P> objectField) Future<T?>
Returns the serialized value of type objectField for the object ctx by coerceArgumentValues, executing the resolver resolveFieldValue and serializing the result completeValue
executeMutation(ExecutionCtx ctx, OperationDefinitionNode mutation, GraphQLSchema schema, Object rootValue) Future<Map<String, dynamic>>
executeQuery(ExecutionCtx ctx, OperationDefinitionNode query, GraphQLSchema schema, Object rootValue) Future<Map<String, dynamic>>
executeRequest(GraphQLSchema schema, DocumentNode document, {Map<String, dynamic>? variableValues, required Object rootValue, required ScopedMap globalVariables, Map<String, dynamic>? extensions, required RequestCtx baseCtx, required OperationDefinitionNode operation}) Future<GraphQLResult>
executeSelectionSet(ExecutionCtx baseCtx, SelectionSetNode selectionSet, GraphQLObjectType<Object?> objectType, Object objectValue, {required bool serial, ObjectExecutionCtx? parentCtx, Object? pathItem}) Future<Map<String, dynamic>>
getDocumentNode(String query, {dynamic sourceUrl, Map<String, Object?>? extensions, required ScopedMap globals, required RequestCtx ctx}) DocumentNode
getOperation(DocumentNode document, String? operationName) → OperationDefinitionNode
mapException(ThrownError error) GraphQLException
mapSourceToResponseEvent(ExecutionCtx streamCtx, MapEntry<FieldNode, Stream<Object?>> sourceStream, OperationDefinitionNode subscription, GraphQLSchema schema, Object rootValue) Stream<GraphQLResult>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
parseAndExecute(String query, {String? operationName, dynamic sourceUrl, Map<String, Object?>? variableValues, Map<String, Object?>? extensions, Object? rootValue, List<ScopedOverride>? scopeOverrides, List<OperationType> validOperationTypes = OperationType.values}) Future<GraphQLResult>
Parses the GraphQL document in query and executes operationName or the only operation in the document if not given.
resolveAbstractType(ObjectExecutionCtx ctx, String fieldName, GraphQLType type, Object result) → GraphQLObjectType
resolveFieldEventStream(ObjectExecutionCtx ctx, GraphQLObjectType subscriptionType, Object rootValue, FieldNode fieldNode, Map<String, dynamic> argumentValues) Future<Stream<Object?>>
resolveFieldValue<T, P>(Ctx<P> fieldCtx) Future<T?>
subscribe(ExecutionCtx baseCtx, OperationDefinitionNode subscription, GraphQLSchema schema, Object rootValue) Future<Stream<GraphQLResult>>
toString() String
A string representation of this object.
inherited
withExtensions<T>(T call(T next(), GraphQLExtension), T next()) → T

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

fromCtx(ScopedHolder scope) GraphQL?
Gets the GraphQL executor from a scope. Always non-null for scopes derived from parseAndExecute
getResolveCtx(ScopedHolder scope) → ExecutionCtx?
Gets the ExecutionCtx of a request from a scope. null when the execution stage hasn't started.