Skip to content

Commit 43c6657

Browse files
Jackson KearlIvanGoncharov
Jackson Kearl
authored andcommitted
Sync utilities TS definitions with flow (#2115)
1 parent 0d8d239 commit 43c6657

14 files changed

+116
-182
lines changed

tstypes/utilities/TypeInfo.d.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import Maybe from '../tsutils/Maybe';
2+
import { ASTNode, FieldNode } from '../language/ast';
23
import { GraphQLSchema } from '../type/schema';
4+
import { GraphQLDirective } from '../type/directives';
35
import {
6+
GraphQLType,
7+
GraphQLInputType,
48
GraphQLOutputType,
59
GraphQLCompositeType,
6-
GraphQLInputType,
710
GraphQLField,
811
GraphQLArgument,
912
GraphQLEnumValue,
10-
GraphQLType,
1113
} from '../type/definition';
12-
import { GraphQLDirective } from '../type/directives';
13-
import { ASTNode, FieldNode } from '../language/ast';
1414

1515
/**
1616
* TypeInfo is a utility class which, given a GraphQL schema, can keep track

tstypes/utilities/buildASTSchema.d.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,16 @@ import {
99
FieldDefinitionNode,
1010
InputValueDefinitionNode,
1111
EnumValueDefinitionNode,
12+
TypeNode,
1213
} from '../language/ast';
1314
import {
1415
GraphQLNamedType,
1516
GraphQLFieldConfig,
1617
GraphQLInputField,
1718
GraphQLEnumValueConfig,
19+
GraphQLType,
20+
GraphQLArgumentConfig,
21+
GraphQLInputFieldConfig,
1822
} from '../type/definition';
1923
import { GraphQLDirective } from '../type/directives';
2024
import { Source } from '../language/source';
@@ -66,25 +70,23 @@ type TypeDefinitionsMap = { [key: string]: TypeDefinitionNode };
6670
type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;
6771

6872
export class ASTDefinitionBuilder {
69-
constructor(
70-
typeDefinitionsMap: TypeDefinitionsMap,
71-
options: Maybe<BuildSchemaOptions>,
72-
resolveType: TypeResolver,
73-
);
73+
constructor(options: Maybe<BuildSchemaOptions>, resolveType: TypeResolver);
7474

75-
buildTypes(
76-
nodes: ReadonlyArray<NamedTypeNode | TypeDefinitionNode>,
77-
): Array<GraphQLNamedType>;
75+
getNamedType(node: NamedTypeNode): GraphQLNamedType;
7876

79-
buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
77+
getWrappedType(node: TypeNode): GraphQLType;
8078

81-
buildDirective(directiveNode: DirectiveDefinitionNode): GraphQLDirective;
79+
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective;
8280

8381
buildField(field: FieldDefinitionNode): GraphQLFieldConfig<any, any>;
8482

85-
buildInputField(value: InputValueDefinitionNode): GraphQLInputField;
83+
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig;
84+
85+
buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig;
8686

8787
buildEnumValue(value: EnumValueDefinitionNode): GraphQLEnumValueConfig;
88+
89+
buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
8890
}
8991

9092
/**
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { GraphQLInputType } from '../type/definition';
2+
import { GraphQLError } from 'tstypes/error';
3+
4+
type OnErrorCB = (
5+
path: ReadonlyArray<string | number>,
6+
invalidValue: any,
7+
error: GraphQLError,
8+
) => void;
9+
10+
/**
11+
* Coerces a JavaScript value given a GraphQL Input Type.
12+
*/
13+
export function coerceInputValue(
14+
inputValue: any,
15+
type: GraphQLInputType,
16+
onError?: OnErrorCB,
17+
): any;

tstypes/utilities/coerceValue.d.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { Path } from '../jsutils/Path';
12
import { GraphQLError } from '../error/GraphQLError';
23
import { ASTNode } from '../language/ast';
34
import { GraphQLInputType } from '../type/definition';
@@ -7,11 +8,6 @@ interface CoercedValue {
78
readonly value: any;
89
}
910

10-
interface Path {
11-
readonly prev: Path | undefined;
12-
readonly key: string | number;
13-
}
14-
1511
/**
1612
* Coerces a JavaScript value given a GraphQL Type.
1713
*
@@ -20,7 +16,7 @@ interface Path {
2016
*
2117
*/
2218
export function coerceValue(
23-
value: any,
19+
inputValue: any,
2420
type: GraphQLInputType,
2521
blameNode?: ASTNode,
2622
path?: Path,

tstypes/utilities/extendSchema.d.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { DocumentNode } from '../language/ast';
2-
import { GraphQLSchema } from '../type/schema';
3-
import { GraphQLSchemaValidationOptions } from '../type/schema';
2+
import { GraphQLSchemaValidationOptions, GraphQLSchema } from '../type/schema';
43

54
interface Options extends GraphQLSchemaValidationOptions {
65
/**
Lines changed: 9 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
import {
2-
getNamedType,
3-
GraphQLScalarType,
4-
GraphQLEnumType,
5-
GraphQLInputObjectType,
6-
GraphQLInterfaceType,
7-
GraphQLObjectType,
8-
GraphQLUnionType,
9-
GraphQLNamedType,
10-
} from '../type/definition';
111
import { GraphQLDirective } from '../type/directives';
122
import { GraphQLSchema } from '../type/schema';
133
import { DirectiveLocationEnum } from '../language/directiveLocation';
@@ -16,33 +6,33 @@ export const BreakingChangeType: _BreakingChangeType;
166

177
// @internal
188
type _BreakingChangeType = {
19-
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND';
20-
FIELD_REMOVED: 'FIELD_REMOVED';
21-
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND';
229
TYPE_REMOVED: 'TYPE_REMOVED';
10+
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND';
2311
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION';
2412
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM';
25-
ARG_REMOVED: 'ARG_REMOVED';
26-
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND';
27-
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED';
2813
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED';
2914
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT';
15+
FIELD_REMOVED: 'FIELD_REMOVED';
16+
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND';
17+
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED';
18+
ARG_REMOVED: 'ARG_REMOVED';
19+
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND';
3020
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED';
3121
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED';
32-
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
3322
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED';
23+
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
3424
};
3525

3626
export const DangerousChangeType: _DangerousChangeType;
3727

3828
// @internal
3929
type _DangerousChangeType = {
40-
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE';
4130
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM';
42-
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT';
4331
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION';
4432
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED';
4533
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED';
34+
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT';
35+
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE';
4636
};
4737

4838
export interface BreakingChange {
@@ -72,119 +62,3 @@ export function findDangerousChanges(
7262
oldSchema: GraphQLSchema,
7363
newSchema: GraphQLSchema,
7464
): Array<DangerousChange>;
75-
76-
/**
77-
* Given two schemas, returns an Array containing descriptions of any breaking
78-
* changes in the newSchema related to removing an entire type.
79-
*/
80-
export function findRemovedTypes(
81-
oldSchema: GraphQLSchema,
82-
newSchema: GraphQLSchema,
83-
): Array<BreakingChange>;
84-
85-
/**
86-
* Given two schemas, returns an Array containing descriptions of any breaking
87-
* changes in the newSchema related to changing the type of a type.
88-
*/
89-
export function findTypesThatChangedKind(
90-
oldSchema: GraphQLSchema,
91-
newSchema: GraphQLSchema,
92-
): Array<BreakingChange>;
93-
94-
/**
95-
* Given two schemas, returns an Array containing descriptions of any
96-
* breaking or dangerous changes in the newSchema related to arguments
97-
* (such as removal or change of type of an argument, or a change in an
98-
* argument's default value).
99-
*/
100-
export function findArgChanges(
101-
oldSchema: GraphQLSchema,
102-
newSchema: GraphQLSchema,
103-
): {
104-
breakingChanges: Array<BreakingChange>;
105-
dangerousChanges: Array<DangerousChange>;
106-
};
107-
108-
export function findFieldsThatChangedTypeOnObjectOrInterfaceTypes(
109-
oldSchema: GraphQLSchema,
110-
newSchema: GraphQLSchema,
111-
): Array<BreakingChange>;
112-
113-
export function findFieldsThatChangedTypeOnInputObjectTypes(
114-
oldSchema: GraphQLSchema,
115-
newSchema: GraphQLSchema,
116-
): {
117-
breakingChanges: Array<BreakingChange>;
118-
dangerousChanges: Array<DangerousChange>;
119-
};
120-
121-
/**
122-
* Given two schemas, returns an Array containing descriptions of any breaking
123-
* changes in the newSchema related to removing types from a union type.
124-
*/
125-
export function findTypesRemovedFromUnions(
126-
oldSchema: GraphQLSchema,
127-
newSchema: GraphQLSchema,
128-
): Array<BreakingChange>;
129-
130-
/**
131-
* Given two schemas, returns an Array containing descriptions of any dangerous
132-
* changes in the newSchema related to adding types to a union type.
133-
*/
134-
export function findTypesAddedToUnions(
135-
oldSchema: GraphQLSchema,
136-
newSchema: GraphQLSchema,
137-
): Array<DangerousChange>;
138-
139-
/**
140-
* Given two schemas, returns an Array containing descriptions of any breaking
141-
* changes in the newSchema related to removing values from an enum type.
142-
*/
143-
export function findValuesRemovedFromEnums(
144-
oldSchema: GraphQLSchema,
145-
newSchema: GraphQLSchema,
146-
): Array<BreakingChange>;
147-
148-
/**
149-
* Given two schemas, returns an Array containing descriptions of any dangerous
150-
* changes in the newSchema related to adding values to an enum type.
151-
*/
152-
export function findValuesAddedToEnums(
153-
oldSchema: GraphQLSchema,
154-
newSchema: GraphQLSchema,
155-
): Array<DangerousChange>;
156-
157-
export function findInterfacesRemovedFromObjectTypes(
158-
oldSchema: GraphQLSchema,
159-
newSchema: GraphQLSchema,
160-
): Array<BreakingChange>;
161-
162-
export function findInterfacesAddedToObjectTypes(
163-
oldSchema: GraphQLSchema,
164-
newSchema: GraphQLSchema,
165-
): Array<DangerousChange>;
166-
167-
export function findRemovedDirectives(
168-
oldSchema: GraphQLSchema,
169-
newSchema: GraphQLSchema,
170-
): Array<BreakingChange>;
171-
172-
export function findRemovedDirectiveArgs(
173-
oldSchema: GraphQLSchema,
174-
newSchema: GraphQLSchema,
175-
): Array<BreakingChange>;
176-
177-
export function findAddedNonNullDirectiveArgs(
178-
oldSchema: GraphQLSchema,
179-
newSchema: GraphQLSchema,
180-
): Array<BreakingChange>;
181-
182-
export function findRemovedLocationsForDirective(
183-
oldDirective: GraphQLDirective,
184-
newDirective: GraphQLDirective,
185-
): Array<DirectiveLocationEnum>;
186-
187-
export function findRemovedDirectiveLocations(
188-
oldSchema: GraphQLSchema,
189-
newSchema: GraphQLSchema,
190-
): Array<BreakingChange>;

tstypes/utilities/findDeprecatedUsages.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { GraphQLSchema } from '../type/schema';
2-
import { DocumentNode } from '../language/ast';
31
import { GraphQLError } from '../error/GraphQLError';
2+
import { DocumentNode } from '../language/ast';
3+
import { GraphQLSchema } from '../type/schema';
44

55
/**
66
* A validation rule which reports deprecated usages.

tstypes/utilities/getOperationRootType.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { GraphQLSchema } from '../type/schema';
21
import {
32
OperationDefinitionNode,
43
OperationTypeDefinitionNode,
54
} from '../language/ast';
5+
import { GraphQLSchema } from '../type/schema';
66
import { GraphQLObjectType } from '../type/definition';
77

88
/**

tstypes/utilities/index.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export { astFromValue } from './astFromValue';
8181
// the GraphQL type system.
8282
export { TypeInfo } from './TypeInfo';
8383

84+
// Coerces a JavaScript value to a GraphQL type, or produces errors.
85+
export { coerceInputValue } from './coerceInputValue';
86+
8487
// Coerces a JavaScript value to a GraphQL type, or produces errors.
8588
export { coerceValue } from './coerceValue';
8689

@@ -96,6 +99,10 @@ export { concatAST } from './concatAST';
9699
// Separates an AST into an AST per Operation.
97100
export { separateOperations } from './separateOperations';
98101

102+
// Strips characters that are not significant to the validity or execution
103+
// of a GraphQL document.
104+
export { stripIgnoredCharacters } from './stripIgnoredCharacters';
105+
99106
// Comparators for types
100107
export {
101108
isEqualType,

tstypes/utilities/separateOperations.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DocumentNode, OperationDefinitionNode } from '../language/ast';
1+
import { DocumentNode } from '../language/ast';
22

33
/**
44
* separateOperations accepts a single AST document which may contain many

0 commit comments

Comments
 (0)