Skip to content

Commit

Permalink
Sync validation TS definitions with flow (#2119)
Browse files Browse the repository at this point in the history
* Sync tstypes/validation TS definitions with Flow
Note: not tstypes/validation/rules yet

* Sync validation/rules TS with Flow
  • Loading branch information
Jackson Kearl authored and IvanGoncharov committed Aug 23, 2019
1 parent 7b9bfda commit 9c3e816
Show file tree
Hide file tree
Showing 36 changed files with 176 additions and 46 deletions.
35 changes: 22 additions & 13 deletions tstypes/validation/ValidationContext.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Maybe from '../tsutils/Maybe';
import { GraphQLError } from '../error';
import { ASTVisitor } from '../language/visitor';
import {
DocumentNode,
OperationDefinitionNode,
Expand All @@ -9,16 +10,15 @@ import {
FragmentDefinitionNode,
} from '../language/ast';
import { GraphQLSchema } from '../type/schema';
import { GraphQLDirective } from '../type/directives';
import {
GraphQLInputType,
GraphQLOutputType,
GraphQLCompositeType,
GraphQLField,
GraphQLArgument,
} from '../type/definition';
import { GraphQLDirective } from '../type/directives';
import { TypeInfo } from '../utilities/TypeInfo';
import { ASTVisitor } from '../language/visitor';

type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode;
type VariableUsage = {
Expand All @@ -40,35 +40,44 @@ export class ASTValidationContext {
getErrors(): ReadonlyArray<GraphQLError>;

getDocument(): DocumentNode;

getFragment(name: string): Maybe<FragmentDefinitionNode>;

getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;

getRecursivelyReferencedFragments(
operation: OperationDefinitionNode,
): ReadonlyArray<FragmentDefinitionNode>;
}

export class SDLValidationContext extends ASTValidationContext {
constructor(ast: DocumentNode, schema?: Maybe<GraphQLSchema>);
constructor(
ast: DocumentNode,
schema: Maybe<GraphQLSchema>,
onError?: (err: GraphQLError) => void,
);

getSchema(): Maybe<GraphQLSchema>;
}

export type SDLValidationRule = (context: SDLValidationContext) => ASTVisitor;

export class ValidationContext extends ASTValidationContext {
constructor(schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo);
constructor(
schema: GraphQLSchema,
ast: DocumentNode,
typeInfo: TypeInfo,
onError?: (err: GraphQLError) => void,
);

getSchema(): GraphQLSchema;

getFragment(name: string): Maybe<FragmentDefinitionNode>;

getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;
getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray<VariableUsage>;

getRecursivelyReferencedFragments(
operation: OperationDefinitionNode,
): ReadonlyArray<FragmentDefinitionNode>;

getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray<VariableUsage>;

getRecursiveVariableUsages(
operation: OperationDefinitionNode,
): ReadonlyArray<VariableUsage>;

getType(): Maybe<GraphQLOutputType>;

getParentType(): Maybe<GraphQLCompositeType>;
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/ExecutableDefinitions.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function nonExecutableDefinitionMessage(defName: string): string;

Expand Down
9 changes: 8 additions & 1 deletion tstypes/validation/rules/FieldsOnCorrectType.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function undefinedFieldMessage(
fieldName: string,
type: string,
suggestedTypeNames: ReadonlyArray<string>,
suggestedFieldNames: ReadonlyArray<string>,
): string;

/**
* Fields on correct type
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/FragmentsOnCompositeTypes.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function inlineFragmentOnNonCompositeErrorMessage(type: string): string;

Expand Down
4 changes: 2 additions & 2 deletions tstypes/validation/rules/KnownArgumentNames.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ export function unknownArgMessage(
argName: string,
fieldName: string,
typeName: string,
suggestedArgs: Array<string>,
suggestedArgs: ReadonlyArray<string>,
): string;

export function unknownDirectiveArgMessage(
argName: string,
directiveName: string,
suggestedArgs: Array<string>,
suggestedArgs: ReadonlyArray<string>,
): string;

/**
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/KnownDirectives.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext, SDLValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext, SDLValidationContext } from '../ValidationContext';

export function unknownDirectiveMessage(directiveName: string): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/KnownFragmentNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function unknownFragmentMessage(fragName: string): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/KnownTypeNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function unknownTypeMessage(
typeName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/LoneAnonymousOperation.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function anonOperationNotAloneMessage(): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/LoneSchemaDefinition.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SDLValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function schemaDefinitionNotAloneMessage(): string;

Expand Down
4 changes: 2 additions & 2 deletions tstypes/validation/rules/NoFragmentCycles.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function cycleErrorMessage(
fragName: string,
spreadNames: Array<string>,
spreadNames: ReadonlyArray<string>,
): string;

export function NoFragmentCycles(context: ValidationContext): ASTVisitor;
2 changes: 1 addition & 1 deletion tstypes/validation/rules/NoUndefinedVariables.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Maybe from '../../tsutils/Maybe';
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function undefinedVarMessage(
varName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/NoUnusedFragments.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function unusedFragMessage(fragName: string): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/NoUnusedVariables.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Maybe from '../../tsutils/Maybe';
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function unusedVariableMessage(
varName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/OverlappingFieldsCanBeMerged.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function fieldsConflictMessage(
responseName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/PossibleFragmentSpreads.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function typeIncompatibleSpreadMessage(
fragName: string,
Expand Down
21 changes: 21 additions & 0 deletions tstypes/validation/rules/PossibleTypeExtensions.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function extendingUnknownTypeMessage(
typeName: string,
suggestedTypes: $ReadOnlyArray<string>,
): string;

export function extendingDifferentTypeKindMessage(
typeName: string,
kind: string,
): string;

/**
* Possible type extension
*
* A type extension is only valid if the type is defined and has the same kind.
*/
export function PossibleTypeExtensions(
context: SDLValidationContext,
): ASTVisitor;
2 changes: 1 addition & 1 deletion tstypes/validation/rules/ProvidedRequiredArguments.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext, SDLValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext, SDLValidationContext } from '../ValidationContext';

export function missingFieldArgMessage(
fieldName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/ScalarLeafs.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ValidationContext } from '../ValidationContext';

export function noSubselectionAllowedMessage(
fieldName: string,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/SingleFieldSubscriptions.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Maybe from '../../tsutils/Maybe';
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function singleFieldOnlyMessage(name: Maybe<string>): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueArgumentNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateArgMessage(argName: string): string;

Expand Down
13 changes: 13 additions & 0 deletions tstypes/validation/rules/UniqueDirectiveNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateDirectiveNameMessage(directiveName: string): string;

export function existedDirectiveNameMessage(directiveName: string): string;

/**
* Unique directive names
*
* A GraphQL document is only valid if all defined directives have unique names.
*/
export function UniqueDirectiveNames(context: SDLValidationContext): ASTVisitor;
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueDirectivesPerLocation.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateDirectiveMessage(directiveName: string): string;

Expand Down
19 changes: 19 additions & 0 deletions tstypes/validation/rules/UniqueEnumValueNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function duplicateEnumValueNameMessage(
typeName: string,
valueName: string,
): string;

export function existedEnumValueNameMessage(
typeName: string,
valueName: string,
): string;

/**
* Unique enum value names
*
* A GraphQL enum type is only valid if all its values are uniquely named.
*/
export function UniqueEnumValueNames(context: SDLValidationContext): ASTVisitor;
21 changes: 21 additions & 0 deletions tstypes/validation/rules/UniqueFieldDefinitionNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function duplicateFieldDefinitionNameMessage(
typeName: string,
fieldName: string,
): string;

export function existedFieldDefinitionNameMessage(
typeName: string,
fieldName: string,
): string;

/**
* Unique field definition names
*
* A GraphQL complex type is only valid if all its fields are uniquely named.
*/
export function UniqueFieldDefinitionNames(
context: SDLValidationContext,
): ASTVisitor;
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueFragmentNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateFragmentNameMessage(fragName: string): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueInputFieldNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateInputFieldMessage(fieldName: string): string;

Expand Down
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueOperationNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateOperationNameMessage(operationName: string): string;

Expand Down
13 changes: 13 additions & 0 deletions tstypes/validation/rules/UniqueOperationTypes.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function duplicateOperationTypeMessage(operation: string): string;

export function existedOperationTypeMessage(operation: string): string;

/**
* Unique operation types
*
* A GraphQL document is only valid if it has only one type per operation.
*/
export function UniqueOperationTypes(context: SDLValidationContext): ASTVisitor;
13 changes: 13 additions & 0 deletions tstypes/validation/rules/UniqueTypeNames.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ASTVisitor } from '../../language/visitor';
import { SDLValidationContext } from '../ValidationContext';

export function duplicateTypeNameMessage(typeName: string): string;

export function existedTypeNameMessage(typeName: string): string;

/**
* Unique type names
*
* A GraphQL document is only valid if all defined types have unique names.
*/
export function UniqueTypeNames(context: SDLValidationContext): ASTVisitor;
2 changes: 1 addition & 1 deletion tstypes/validation/rules/UniqueVariableNames.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ASTValidationContext } from '../ValidationContext';
import { ASTVisitor } from '../../language/visitor';
import { ASTValidationContext } from '../ValidationContext';

export function duplicateVariableMessage(variableName: string): string;

Expand Down
Loading

0 comments on commit 9c3e816

Please sign in to comment.