validate_rules library

Classes

Conflict
ConflictReason
Field name and reason.
ElementComplexity
ExecutableDefinitionsRule
FieldsAndFragmentNames
FragmentsOnCompositeTypesRule
KnownFragmentNamesRule
LoneAnonymousOperationRule
NodeAndDef
Tuple defining a field node in a context.
PairSet
A way to keep track of pairs of things when the ordering of the pair does not matter.
UniqueOperationNamesRule
VariablesAreInputTypesRule

Constants

defKindToExtKind → const Map<Kind, Kind>
A map from type definition to type extension node kind

Properties

costGraphQLDirective GraphQLDirective
The directive definition to specify the query complexity cost associated with a Field or Type
final

Functions

allowedVariableUsage(GraphQLSchema schema, GraphQLType varType, ValueNode? varDefaultValue, GraphQLType locationType, Object? locationDefaultValue) bool
Returns true if the variable is allowed in the location it was found, which includes considering if default values exist for either the variable or the location at which it is located.
collectConflictsBetween(ValidationCtx context, List<Conflict> conflicts, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, bool parentFieldsAreMutuallyExclusive, NodeAndDefCollection fieldMap1, NodeAndDefCollection fieldMap2) → void
Collect all Conflicts between two collections of fields. This is similar to, but different from the collectConflictsWithin function above. This check assumes that collectConflictsWithin has already been called on each provided collection of fields. This is true because this validator traverses each individual selection set.
collectConflictsBetweenFieldsAndFragment(ValidationCtx context, List<Conflict> conflicts, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, bool areMutuallyExclusive, NodeAndDefCollection fieldMap, String fragmentName) → void
Collect all conflicts found between a set of fields and a fragment reference including via spreading in any nested fragments.
collectConflictsBetweenFragments(ValidationCtx context, List<Conflict> conflicts, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, bool areMutuallyExclusive, String fragmentName1, String fragmentName2) → void
Collect all conflicts found between two fragments, including via spreading in any nested fragments.
collectConflictsWithin(ValidationCtx context, List<Conflict> conflicts, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, NodeAndDefCollection fieldMap) → void
Collect all Conflicts "within" one collection of fields.
doTypesConflict(GraphQLType type1, GraphQLType type2) bool
Two types conflict if both types could not apply to a value simultaneously. Composite types are ignored as their individual field types will be compared later recursively. However List and Non-Null types must match.
executableDefinitionsRule(SDLValidationCtx ctx) → Visitor
Executable definitions
extensionKindToTypeName(Kind kind) String
Returns a user facing name for a given type extension node kind
fieldsOnCorrectTypeRule(ValidationCtx context) → TypedVisitor
Fields on correct type
findConflict(ValidationCtx context, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, bool parentFieldsAreMutuallyExclusive, String responseName, NodeAndDef field1, NodeAndDef field2) Conflict?
Determines if there is a conflict between two particular fields, including comparing their sub-fields.
findConflictsBetweenSubSelectionSets(ValidationCtx context, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, bool areMutuallyExclusive, GraphQLNamedType? parentType1, SelectionSetNode selectionSet1, GraphQLNamedType? parentType2, SelectionSetNode selectionSet2) List<Conflict>
Find all conflicts found between two selection sets, including those found via spreading in fragments. Called when determining if conflicts exist between the sub-fields of two overlapping fields.
findConflictsWithinSelectionSet(ValidationCtx context, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, PairSet comparedFragmentPairs, GraphQLNamedType? parentType, SelectionSetNode selectionSet) List<Conflict>
Find all conflicts found "within" a selection set, including those found via spreading in fragments. Called when visiting each SelectionSet in the GraphQL Document.
fragmentsOnCompositeTypesRule(ValidationCtx ctx) → Visitor
Fragments on composite type
getDirectiveLocationForASTPath(List<Node> ancestors) DirectiveLocation?
getFieldsAndFragmentNames(ValidationCtx context, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, GraphQLNamedType? parentType, SelectionSetNode selectionSet) FieldsAndFragmentNames
Given a selection set, return the collection of fields (a mapping of response name to field nodes and definitions) as well as a list of fragment names referenced via fragment spreads.
getReferencedFieldsAndFragmentNames(ValidationCtx context, Map<SelectionSetNode, FieldsAndFragmentNames> cachedFieldsAndFragmentNames, FragmentDefinitionNode fragment) FieldsAndFragmentNames
Given a reference to a fragment, return the represented collection of fields as well as a list of nested fragment names referenced via fragment spreads.
implementInterfaceOnceRule(SDLValidationCtx context) → Visitor
Implement interface once
knownArgumentNamesOnDirectivesRule(SDLValidationCtx context) → TypedVisitor
@internal
knownArgumentNamesRule(ValidationCtx context) → Visitor
Known argument names
knownDirectivesRule(SDLValidationCtx context) → Visitor
Known directives
knownFragmentNamesRule(ValidationCtx ctx) → Visitor
Known fragment names
knownTypeNamesRule(SDLValidationCtx ctx) → Visitor
Known type names
locationsFromFields(List<FieldNode> fieldNodes) List<GraphQLErrorLocation>
loneAnonymousOperationRule(SDLValidationCtx ctx) → Visitor
Lone anonymous operation
loneSchemaDefinitionRule(SDLValidationCtx context) → Visitor
Lone Schema definition
noFragmentCyclesRule(SDLValidationCtx context) → Visitor
No fragment cycles
noUndefinedVariablesRule(ValidationCtx context) → Visitor
No undefined variables
noUnusedFragmentsRule(SDLValidationCtx context) → Visitor
No unused fragments
noUnusedVariablesRule(ValidationCtx context) → Visitor
No unused variables
overlappingFieldsCanBeMergedRule(ValidationCtx context) → Visitor
Overlapping fields can be merged
possibleFragmentSpreadsRule(ValidationCtx context) → Visitor
Possible fragment spread
possibleTypeExtensionsRule(SDLValidationCtx context) → Visitor
Possible type extension
providedRequiredArgumentsOnDirectivesRule(SDLValidationCtx context) → TypedVisitor
@internal
providedRequiredArgumentsRule(ValidationCtx context) → Visitor
Provided required arguments
queryComplexityRuleBuilder({required int maxComplexity, required int maxDepth, int listComplexityMultiplier = 10, int defaultFieldComplexity = 1}) ValidationRule
Returns a ValidationRule that reports errors when the maxComplexity or maxDepth is reached.
sameArguments(List<ArgumentNode> arguments1, List<ArgumentNode> arguments2) bool
sameValue(ValueNode value1, ValueNode value2) bool
scalarLeafsRule(ValidationCtx context) → Visitor
Scalar leafs
singleFieldSubscriptionsRule(ValidationCtx context) → Visitor
Subscriptions must only include a non-introspection field.
subfieldConflicts(List<Conflict> conflicts, String responseName, FieldNode node1, FieldNode node2) Conflict?
Given a series of Conflicts which occurred between two sub-fields, generate a single Conflict.
typeToExtKind(GraphQLType type) → Kind
Returns the extension Kind for a given named GraphQLType
uniqueArgumentDefinitionNamesRule(SDLValidationCtx context) → Visitor
Unique argument definition names
uniqueArgumentNamesRule(SDLValidationCtx context) → Visitor
Unique argument names
uniqueDirectiveNamesRule(SDLValidationCtx context) → Visitor
Unique directive names
uniqueDirectivesPerLocationRule(SDLValidationCtx context) → Visitor
Unique directive names per location
uniqueEnumValueNamesRule(SDLValidationCtx context) → Visitor
Unique enum value names
uniqueFieldDefinitionNamesRule(SDLValidationCtx context) → Visitor
Unique field definition names
uniqueFragmentNamesRule(SDLValidationCtx ctx) → Visitor
Unique fragment names
uniqueInputFieldNamesRule(SDLValidationCtx context) → Visitor
Unique input field names
uniqueOperationNamesRule(SDLValidationCtx ctx) → Visitor
Unique operation names
uniqueOperationTypesRule(SDLValidationCtx context) → Visitor
Unique operation types
uniqueTypeNamesRule(SDLValidationCtx context) → Visitor
Unique type names
uniqueVariableNamesRule(SDLValidationCtx context) → Visitor
Unique variable names
valuesOfCorrectTypeRule(ValidationCtx context) → Visitor
Value literals of correct type
variablesAreInputTypesRule(ValidationCtx ctx) → Visitor
Variables are input types
variablesInAllowedPositionRule(ValidationCtx context) → Visitor
Variables in allowed position

Typedefs

NodeAndDefCollection = Map<String, List<NodeAndDef>>
Map of array of NodeAndDef.