diff --git a/types/graphql/UNUSED_FILES.txt b/types/graphql/UNUSED_FILES.txt deleted file mode 100644 index df0fadfe79..0000000000 --- a/types/graphql/UNUSED_FILES.txt +++ /dev/null @@ -1 +0,0 @@ -execution/values.d.ts \ No newline at end of file diff --git a/types/graphql/execution/index.d.ts b/types/graphql/execution/index.d.ts index be3038be95..82d6bce853 100644 --- a/types/graphql/execution/index.d.ts +++ b/types/graphql/execution/index.d.ts @@ -4,3 +4,5 @@ export { responsePathAsArray, ExecutionResult } from './execute'; + +export { getDirectiveValues } from './values'; diff --git a/types/graphql/execution/values.d.ts b/types/graphql/execution/values.d.ts index 3f6e909ed7..79a0176f8d 100644 --- a/types/graphql/execution/values.d.ts +++ b/types/graphql/execution/values.d.ts @@ -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 }, + variableValues?: { [key: string]: any } +): void | { [key: string]: any }; diff --git a/types/graphql/index.d.ts b/types/graphql/index.d.ts index 971ae5945b..e85060bab5 100644 --- a/types/graphql/index.d.ts +++ b/types/graphql/index.d.ts @@ -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 // Caleb Meredith @@ -6,6 +6,7 @@ // Firede // Kepennar // Mikhail Novikov +// Ivan Goncharov // 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. diff --git a/types/graphql/validation/index.d.ts b/types/graphql/validation/index.d.ts index a3ebc6a208..7f897fe78d 100644 --- a/types/graphql/validation/index.d.ts +++ b/types/graphql/validation/index.d.ts @@ -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'; diff --git a/types/graphql/validation/rules/ArgumentsOfCorrectType.d.ts b/types/graphql/validation/rules/ArgumentsOfCorrectType.d.ts new file mode 100644 index 0000000000..f7247d0a9c --- /dev/null +++ b/types/graphql/validation/rules/ArgumentsOfCorrectType.d.ts @@ -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; diff --git a/types/graphql/validation/rules/DefaultValuesOfCorrectType.d.ts b/types/graphql/validation/rules/DefaultValuesOfCorrectType.d.ts new file mode 100644 index 0000000000..88b3a824f2 --- /dev/null +++ b/types/graphql/validation/rules/DefaultValuesOfCorrectType.d.ts @@ -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; diff --git a/types/graphql/validation/rules/FieldsOnCorrectType.d.ts b/types/graphql/validation/rules/FieldsOnCorrectType.d.ts new file mode 100644 index 0000000000..19609b2b65 --- /dev/null +++ b/types/graphql/validation/rules/FieldsOnCorrectType.d.ts @@ -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; diff --git a/types/graphql/validation/rules/FragmentsOnCompositeTypes.d.ts b/types/graphql/validation/rules/FragmentsOnCompositeTypes.d.ts new file mode 100644 index 0000000000..d6fffd4337 --- /dev/null +++ b/types/graphql/validation/rules/FragmentsOnCompositeTypes.d.ts @@ -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; diff --git a/types/graphql/validation/rules/KnownArgumentNames.d.ts b/types/graphql/validation/rules/KnownArgumentNames.d.ts new file mode 100644 index 0000000000..4477b62a75 --- /dev/null +++ b/types/graphql/validation/rules/KnownArgumentNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/KnownDirectives.d.ts b/types/graphql/validation/rules/KnownDirectives.d.ts new file mode 100644 index 0000000000..68c6acf549 --- /dev/null +++ b/types/graphql/validation/rules/KnownDirectives.d.ts @@ -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; diff --git a/types/graphql/validation/rules/KnownFragmentNames.d.ts b/types/graphql/validation/rules/KnownFragmentNames.d.ts new file mode 100644 index 0000000000..b904f22d89 --- /dev/null +++ b/types/graphql/validation/rules/KnownFragmentNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/KnownTypeNames.d.ts b/types/graphql/validation/rules/KnownTypeNames.d.ts new file mode 100644 index 0000000000..48b15318da --- /dev/null +++ b/types/graphql/validation/rules/KnownTypeNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/LoneAnonymousOperation.d.ts b/types/graphql/validation/rules/LoneAnonymousOperation.d.ts new file mode 100644 index 0000000000..4ce6abcba9 --- /dev/null +++ b/types/graphql/validation/rules/LoneAnonymousOperation.d.ts @@ -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; diff --git a/types/graphql/validation/rules/NoFragmentCycles.d.ts b/types/graphql/validation/rules/NoFragmentCycles.d.ts new file mode 100644 index 0000000000..fed5982fc8 --- /dev/null +++ b/types/graphql/validation/rules/NoFragmentCycles.d.ts @@ -0,0 +1,3 @@ +import { ValidationContext } from '../index'; + +export function NoFragmentCycles(context: ValidationContext): any; diff --git a/types/graphql/validation/rules/NoUndefinedVariables.d.ts b/types/graphql/validation/rules/NoUndefinedVariables.d.ts new file mode 100644 index 0000000000..51d30b8fd1 --- /dev/null +++ b/types/graphql/validation/rules/NoUndefinedVariables.d.ts @@ -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; diff --git a/types/graphql/validation/rules/NoUnusedFragments.d.ts b/types/graphql/validation/rules/NoUnusedFragments.d.ts new file mode 100644 index 0000000000..7f4d431299 --- /dev/null +++ b/types/graphql/validation/rules/NoUnusedFragments.d.ts @@ -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; diff --git a/types/graphql/validation/rules/NoUnusedVariables.d.ts b/types/graphql/validation/rules/NoUnusedVariables.d.ts new file mode 100644 index 0000000000..6eb2d984aa --- /dev/null +++ b/types/graphql/validation/rules/NoUnusedVariables.d.ts @@ -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; diff --git a/types/graphql/validation/rules/OverlappingFieldsCanBeMerged.d.ts b/types/graphql/validation/rules/OverlappingFieldsCanBeMerged.d.ts new file mode 100644 index 0000000000..f21edbd2cb --- /dev/null +++ b/types/graphql/validation/rules/OverlappingFieldsCanBeMerged.d.ts @@ -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; diff --git a/types/graphql/validation/rules/PossibleFragmentSpreads.d.ts b/types/graphql/validation/rules/PossibleFragmentSpreads.d.ts new file mode 100644 index 0000000000..8defb47721 --- /dev/null +++ b/types/graphql/validation/rules/PossibleFragmentSpreads.d.ts @@ -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; diff --git a/types/graphql/validation/rules/ProvidedNonNullArguments.d.ts b/types/graphql/validation/rules/ProvidedNonNullArguments.d.ts new file mode 100644 index 0000000000..4d5334b9fb --- /dev/null +++ b/types/graphql/validation/rules/ProvidedNonNullArguments.d.ts @@ -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; diff --git a/types/graphql/validation/rules/ScalarLeafs.d.ts b/types/graphql/validation/rules/ScalarLeafs.d.ts new file mode 100644 index 0000000000..afdc575671 --- /dev/null +++ b/types/graphql/validation/rules/ScalarLeafs.d.ts @@ -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; diff --git a/types/graphql/validation/rules/SingleFieldSubscriptions.d.ts b/types/graphql/validation/rules/SingleFieldSubscriptions.d.ts new file mode 100644 index 0000000000..01a2654a16 --- /dev/null +++ b/types/graphql/validation/rules/SingleFieldSubscriptions.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueArgumentNames.d.ts b/types/graphql/validation/rules/UniqueArgumentNames.d.ts new file mode 100644 index 0000000000..8cc166d07a --- /dev/null +++ b/types/graphql/validation/rules/UniqueArgumentNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueDirectivesPerLocation.d.ts b/types/graphql/validation/rules/UniqueDirectivesPerLocation.d.ts new file mode 100644 index 0000000000..70ea02cd9c --- /dev/null +++ b/types/graphql/validation/rules/UniqueDirectivesPerLocation.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueFragmentNames.d.ts b/types/graphql/validation/rules/UniqueFragmentNames.d.ts new file mode 100644 index 0000000000..c505968f6a --- /dev/null +++ b/types/graphql/validation/rules/UniqueFragmentNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueInputFieldNames.d.ts b/types/graphql/validation/rules/UniqueInputFieldNames.d.ts new file mode 100644 index 0000000000..cebd71b79b --- /dev/null +++ b/types/graphql/validation/rules/UniqueInputFieldNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueOperationNames.d.ts b/types/graphql/validation/rules/UniqueOperationNames.d.ts new file mode 100644 index 0000000000..5b12cc0eed --- /dev/null +++ b/types/graphql/validation/rules/UniqueOperationNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/UniqueVariableNames.d.ts b/types/graphql/validation/rules/UniqueVariableNames.d.ts new file mode 100644 index 0000000000..ef8712fbc1 --- /dev/null +++ b/types/graphql/validation/rules/UniqueVariableNames.d.ts @@ -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; diff --git a/types/graphql/validation/rules/VariablesAreInputTypes.d.ts b/types/graphql/validation/rules/VariablesAreInputTypes.d.ts new file mode 100644 index 0000000000..df079e52f9 --- /dev/null +++ b/types/graphql/validation/rules/VariablesAreInputTypes.d.ts @@ -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; diff --git a/types/graphql/validation/rules/VariablesInAllowedPosition.d.ts b/types/graphql/validation/rules/VariablesInAllowedPosition.d.ts new file mode 100644 index 0000000000..6d3e513876 --- /dev/null +++ b/types/graphql/validation/rules/VariablesInAllowedPosition.d.ts @@ -0,0 +1,6 @@ +import { ValidationContext } from '../index'; + +/** + * Variables passed to field arguments conform to type + */ +export function VariablesInAllowedPosition(context: ValidationContext): any;