Merge pull request #19239 from APIs-guru/master

[graphql-js] Add individual validation rules and "getDirectiveValues"
This commit is contained in:
Mine Starks
2017-09-01 10:10:48 -07:00
committed by GitHub
31 changed files with 402 additions and 2 deletions

View File

@@ -1 +0,0 @@
execution/values.d.ts

View File

@@ -4,3 +4,5 @@ export {
responsePathAsArray,
ExecutionResult
} from './execute';
export { getDirectiveValues } from './values';

View File

@@ -23,3 +23,16 @@ export function getArgumentValues(
node: FieldNode | DirectiveNode,
variableValues?: { [key: string]: any }
): { [key: string]: any };
/**
* Prepares an object map of argument values given a directive definition
* and a AST node which may contain directives. Optionally also accepts a map
* of variable values.
*
* If the directive does not exist on the node, returns undefined.
*/
export function getDirectiveValues(
directiveDef: GraphQLDirective,
node: { directives?: Array<DirectiveNode> },
variableValues?: { [key: string]: any }
): void | { [key: string]: any };

View File

@@ -1,4 +1,4 @@
// Type definitions for graphql 0.10
// Type definitions for graphql 0.11
// Project: https://www.npmjs.com/package/graphql
// Definitions by: TonyYang <https://github.com/TonyPythoneer>
// Caleb Meredith <https://github.com/calebmer>
@@ -6,6 +6,7 @@
// Firede <https://github.com/firede>
// Kepennar <https://github.com/kepennar>
// Mikhail Novikov <https://github.com/freiksenet>
// Ivan Goncharov <https://github.com/IvanGoncharov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3
@@ -27,6 +28,7 @@ export {
execute,
defaultFieldResolver,
responsePathAsArray,
getDirectiveValues,
ExecutionResult,
} from './execution';
@@ -34,7 +36,37 @@ export {
export {
validate,
ValidationContext,
// All validation rules in the GraphQL Specification.
specifiedRules,
// Individual validation rules.
ArgumentsOfCorrectTypeRule,
DefaultValuesOfCorrectTypeRule,
FieldsOnCorrectTypeRule,
FragmentsOnCompositeTypesRule,
KnownArgumentNamesRule,
KnownDirectivesRule,
KnownFragmentNamesRule,
KnownTypeNamesRule,
LoneAnonymousOperationRule,
NoFragmentCyclesRule,
NoUndefinedVariablesRule,
NoUnusedFragmentsRule,
NoUnusedVariablesRule,
OverlappingFieldsCanBeMergedRule,
PossibleFragmentSpreadsRule,
ProvidedNonNullArgumentsRule,
ScalarLeafsRule,
SingleFieldSubscriptionsRule,
UniqueArgumentNamesRule,
UniqueDirectivesPerLocationRule,
UniqueFragmentNamesRule,
UniqueInputFieldNamesRule,
UniqueOperationNamesRule,
UniqueVariableNamesRule,
VariablesAreInputTypesRule,
VariablesInAllowedPositionRule,
} from './validation';
// Create and format GraphQL errors.

View File

@@ -1,2 +1,132 @@
export { validate, ValidationContext } from './validate';
export { specifiedRules } from './specifiedRules';
// Spec Section: "Argument Values Type Correctness"
export {
ArgumentsOfCorrectType as ArgumentsOfCorrectTypeRule
} from './rules/ArgumentsOfCorrectType';
// Spec Section: "Variable Default Values Are Correctly Typed"
export {
DefaultValuesOfCorrectType as DefaultValuesOfCorrectTypeRule
} from './rules/DefaultValuesOfCorrectType';
// Spec Section: "Field Selections on Objects, Interfaces, and Unions Types"
export {
FieldsOnCorrectType as FieldsOnCorrectTypeRule
} from './rules/FieldsOnCorrectType';
// Spec Section: "Fragments on Composite Types"
export {
FragmentsOnCompositeTypes as FragmentsOnCompositeTypesRule
} from './rules/FragmentsOnCompositeTypes';
// Spec Section: "Argument Names"
export {
KnownArgumentNames as KnownArgumentNamesRule
} from './rules/KnownArgumentNames';
// Spec Section: "Directives Are Defined"
export {
KnownDirectives as KnownDirectivesRule
} from './rules/KnownDirectives';
// Spec Section: "Fragment spread target defined"
export {
KnownFragmentNames as KnownFragmentNamesRule
} from './rules/KnownFragmentNames';
// Spec Section: "Fragment Spread Type Existence"
export {
KnownTypeNames as KnownTypeNamesRule
} from './rules/KnownTypeNames';
// Spec Section: "Lone Anonymous Operation"
export {
LoneAnonymousOperation as LoneAnonymousOperationRule
} from './rules/LoneAnonymousOperation';
// Spec Section: "Fragments must not form cycles"
export {
NoFragmentCycles as NoFragmentCyclesRule
} from './rules/NoFragmentCycles';
// Spec Section: "All Variable Used Defined"
export {
NoUndefinedVariables as NoUndefinedVariablesRule
} from './rules/NoUndefinedVariables';
// Spec Section: "Fragments must be used"
export {
NoUnusedFragments as NoUnusedFragmentsRule
} from './rules/NoUnusedFragments';
// Spec Section: "All Variables Used"
export {
NoUnusedVariables as NoUnusedVariablesRule
} from './rules/NoUnusedVariables';
// Spec Section: "Field Selection Merging"
export {
OverlappingFieldsCanBeMerged as OverlappingFieldsCanBeMergedRule
} from './rules/OverlappingFieldsCanBeMerged';
// Spec Section: "Fragment spread is possible"
export {
PossibleFragmentSpreads as PossibleFragmentSpreadsRule
} from './rules/PossibleFragmentSpreads';
// Spec Section: "Argument Optionality"
export {
ProvidedNonNullArguments as ProvidedNonNullArgumentsRule
} from './rules/ProvidedNonNullArguments';
// Spec Section: "Leaf Field Selections"
export {
ScalarLeafs as ScalarLeafsRule
} from './rules/ScalarLeafs';
// Spec Section: "Subscriptions with Single Root Field"
export {
SingleFieldSubscriptions as SingleFieldSubscriptionsRule
} from './rules/SingleFieldSubscriptions';
// Spec Section: "Argument Uniqueness"
export {
UniqueArgumentNames as UniqueArgumentNamesRule
} from './rules/UniqueArgumentNames';
// Spec Section: "Directives Are Unique Per Location"
export {
UniqueDirectivesPerLocation as UniqueDirectivesPerLocationRule
} from './rules/UniqueDirectivesPerLocation';
// Spec Section: "Fragment Name Uniqueness"
export {
UniqueFragmentNames as UniqueFragmentNamesRule
} from './rules/UniqueFragmentNames';
// Spec Section: "Input Object Field Uniqueness"
export {
UniqueInputFieldNames as UniqueInputFieldNamesRule
} from './rules/UniqueInputFieldNames';
// Spec Section: "Operation Name Uniqueness"
export {
UniqueOperationNames as UniqueOperationNamesRule
} from './rules/UniqueOperationNames';
// Spec Section: "Variable Uniqueness"
export {
UniqueVariableNames as UniqueVariableNamesRule
} from './rules/UniqueVariableNames';
// Spec Section: "Variables are Input Types"
export {
VariablesAreInputTypes as VariablesAreInputTypesRule
} from './rules/VariablesAreInputTypes';
// Spec Section: "All Variable Usages Are Allowed"
export {
VariablesInAllowedPosition as VariablesInAllowedPositionRule
} from './rules/VariablesInAllowedPosition';

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Argument values of correct type
*
* A GraphQL document is only valid if all field argument literal values are
* of the type expected by their position.
*/
export function ArgumentsOfCorrectType(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Variable default values of correct type
*
* A GraphQL document is only valid if all variable default values are of the
* type expected by their definition.
*/
export function DefaultValuesOfCorrectType(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Fields on correct type
*
* A GraphQL document is only valid if all fields selected are defined by the
* parent type, or are an allowed meta field such as __typename.
*/
export function FieldsOnCorrectType(context: ValidationContext): any;

View File

@@ -0,0 +1,10 @@
import { ValidationContext } from '../index';
/**
* Fragments on composite type
*
* Fragments use a type condition to determine if they apply, since fragments
* can only be spread into a composite type (object, interface, or union), the
* type condition must also be a composite type.
*/
export function FragmentsOnCompositeTypes(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Known argument names
*
* A GraphQL field is only valid if all supplied arguments are defined by
* that field.
*/
export function KnownArgumentNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Known directives
*
* A GraphQL document is only valid if all `@directives` are known by the
* schema and legally positioned.
*/
export function KnownDirectives(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Known fragment names
*
* A GraphQL document is only valid if all `...Fragment` fragment spreads refer
* to fragments defined in the same document.
*/
export function KnownFragmentNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Known type names
*
* A GraphQL document is only valid if referenced types (specifically
* variable definitions and fragment conditions) are defined by the type schema.
*/
export function KnownTypeNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Lone anonymous operation
*
* A GraphQL document is only valid if when it contains an anonymous operation
* (the query short-hand) that it contains only that one operation definition.
*/
export function LoneAnonymousOperation(context: ValidationContext): any;

View File

@@ -0,0 +1,3 @@
import { ValidationContext } from '../index';
export function NoFragmentCycles(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* No undefined variables
*
* A GraphQL operation is only valid if all variables encountered, both directly
* and via fragment spreads, are defined by that operation.
*/
export function NoUndefinedVariables(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* No unused fragments
*
* A GraphQL document is only valid if all fragment definitions are spread
* within operations, or spread within other fragments spread within operations.
*/
export function NoUnusedFragments(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* No unused variables
*
* A GraphQL operation is only valid if all variables defined by an operation
* are used, either directly or within a spread fragment.
*/
export function NoUnusedVariables(context: ValidationContext): any;

View File

@@ -0,0 +1,10 @@
import { ValidationContext } from '../index';
/**
* Overlapping fields can be merged
*
* A selection set is only valid if all fields (including spreading any
* fragments) either correspond to distinct response names or can be merged
* without ambiguity.
*/
export function OverlappingFieldsCanBeMerged(context: ValidationContext): any;

View File

@@ -0,0 +1,10 @@
import { ValidationContext } from '../index';
/**
* Possible fragment spread
*
* A fragment spread is only valid if the type condition could ever possibly
* be true: if there is a non-empty intersection of the possible parent types,
* and possible types which pass the type condition.
*/
export function PossibleFragmentSpreads(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Provided required arguments
*
* A field or directive is only valid if all required (non-null) field arguments
* have been provided.
*/
export function ProvidedNonNullArguments(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Scalar leafs
*
* A GraphQL document is valid only if all leaf fields (fields without
* sub selections) are of scalar or enum types.
*/
export function ScalarLeafs(context: ValidationContext): any;

View File

@@ -0,0 +1,8 @@
import { ValidationContext } from '../index';
/**
* Subscriptions must only include one field.
*
* A GraphQL subscription is valid only if it contains a single root field.
*/
export function SingleFieldSubscriptions(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Unique argument names
*
* A GraphQL field or directive is only valid if all supplied arguments are
* uniquely named.
*/
export function UniqueArgumentNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Unique directive names per location
*
* A GraphQL document is only valid if all directives at a given location
* are uniquely named.
*/
export function UniqueDirectivesPerLocation(context: ValidationContext): any;

View File

@@ -0,0 +1,8 @@
import { ValidationContext } from '../index';
/**
* Unique fragment names
*
* A GraphQL document is only valid if all defined fragments have unique names.
*/
export function UniqueFragmentNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Unique input field names
*
* A GraphQL input object value is only valid if all supplied fields are
* uniquely named.
*/
export function UniqueInputFieldNames(context: ValidationContext): any;

View File

@@ -0,0 +1,8 @@
import { ValidationContext } from '../index';
/**
* Unique operation names
*
* A GraphQL document is only valid if all defined operations have unique names.
*/
export function UniqueOperationNames(context: ValidationContext): any;

View File

@@ -0,0 +1,8 @@
import { ValidationContext } from '../index';
/**
* Unique variable names
*
* A GraphQL operation is only valid if all its variables are uniquely named.
*/
export function UniqueVariableNames(context: ValidationContext): any;

View File

@@ -0,0 +1,9 @@
import { ValidationContext } from '../index';
/**
* Variables are input types
*
* A GraphQL operation is only valid if all the variables it defines are of
* input types (scalar, enum, or input object).
*/
export function VariablesAreInputTypes(context: ValidationContext): any;

View File

@@ -0,0 +1,6 @@
import { ValidationContext } from '../index';
/**
* Variables passed to field arguments conform to type
*/
export function VariablesInAllowedPosition(context: ValidationContext): any;