Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync utilities TS definitions with flow #2115

Merged
merged 1 commit into from Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 4 additions & 4 deletions tstypes/utilities/TypeInfo.d.ts
@@ -1,16 +1,16 @@
import Maybe from '../tsutils/Maybe';
import { ASTNode, FieldNode } from '../language/ast';
import { GraphQLSchema } from '../type/schema';
import { GraphQLDirective } from '../type/directives';
import {
GraphQLType,
GraphQLInputType,
GraphQLOutputType,
GraphQLCompositeType,
GraphQLInputType,
GraphQLField,
GraphQLArgument,
GraphQLEnumValue,
GraphQLType,
} from '../type/definition';
import { GraphQLDirective } from '../type/directives';
import { ASTNode, FieldNode } from '../language/ast';

/**
* TypeInfo is a utility class which, given a GraphQL schema, can keep track
Expand Down
24 changes: 13 additions & 11 deletions tstypes/utilities/buildASTSchema.d.ts
Expand Up @@ -9,12 +9,16 @@ import {
FieldDefinitionNode,
InputValueDefinitionNode,
EnumValueDefinitionNode,
TypeNode,
} from '../language/ast';
import {
GraphQLNamedType,
GraphQLFieldConfig,
GraphQLInputField,
GraphQLEnumValueConfig,
GraphQLType,
GraphQLArgumentConfig,
GraphQLInputFieldConfig,
} from '../type/definition';
import { GraphQLDirective } from '../type/directives';
import { Source } from '../language/source';
Expand Down Expand Up @@ -66,25 +70,23 @@ type TypeDefinitionsMap = { [key: string]: TypeDefinitionNode };
type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;

export class ASTDefinitionBuilder {
constructor(
typeDefinitionsMap: TypeDefinitionsMap,
options: Maybe<BuildSchemaOptions>,
resolveType: TypeResolver,
);
constructor(options: Maybe<BuildSchemaOptions>, resolveType: TypeResolver);

buildTypes(
nodes: ReadonlyArray<NamedTypeNode | TypeDefinitionNode>,
): Array<GraphQLNamedType>;
getNamedType(node: NamedTypeNode): GraphQLNamedType;

buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
getWrappedType(node: TypeNode): GraphQLType;

buildDirective(directiveNode: DirectiveDefinitionNode): GraphQLDirective;
buildDirective(directive: DirectiveDefinitionNode): GraphQLDirective;

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

buildInputField(value: InputValueDefinitionNode): GraphQLInputField;
buildArg(value: InputValueDefinitionNode): GraphQLArgumentConfig;

buildInputField(value: InputValueDefinitionNode): GraphQLInputFieldConfig;

buildEnumValue(value: EnumValueDefinitionNode): GraphQLEnumValueConfig;

buildType(node: NamedTypeNode | TypeDefinitionNode): GraphQLNamedType;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions tstypes/utilities/coerceInputValue.d.ts
@@ -0,0 +1,17 @@
import { GraphQLInputType } from '../type/definition';
import { GraphQLError } from 'tstypes/error';

type OnErrorCB = (
path: ReadonlyArray<string | number>,
invalidValue: any,
error: GraphQLError,
) => void;

/**
* Coerces a JavaScript value given a GraphQL Input Type.
*/
export function coerceInputValue(
inputValue: any,
type: GraphQLInputType,
onError?: OnErrorCB,
): any;
8 changes: 2 additions & 6 deletions tstypes/utilities/coerceValue.d.ts
@@ -1,3 +1,4 @@
import { Path } from '../jsutils/Path';
import { GraphQLError } from '../error/GraphQLError';
import { ASTNode } from '../language/ast';
import { GraphQLInputType } from '../type/definition';
Expand All @@ -7,11 +8,6 @@ interface CoercedValue {
readonly value: any;
}

interface Path {
readonly prev: Path | undefined;
readonly key: string | number;
}

/**
* Coerces a JavaScript value given a GraphQL Type.
*
Expand All @@ -20,7 +16,7 @@ interface Path {
*
*/
export function coerceValue(
value: any,
inputValue: any,
type: GraphQLInputType,
blameNode?: ASTNode,
path?: Path,
Expand Down
3 changes: 1 addition & 2 deletions tstypes/utilities/extendSchema.d.ts
@@ -1,6 +1,5 @@
import { DocumentNode } from '../language/ast';
import { GraphQLSchema } from '../type/schema';
import { GraphQLSchemaValidationOptions } from '../type/schema';
import { GraphQLSchemaValidationOptions, GraphQLSchema } from '../type/schema';

interface Options extends GraphQLSchemaValidationOptions {
/**
Expand Down
144 changes: 9 additions & 135 deletions tstypes/utilities/findBreakingChanges.d.ts
@@ -1,13 +1,3 @@
import {
getNamedType,
GraphQLScalarType,
GraphQLEnumType,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLUnionType,
GraphQLNamedType,
} from '../type/definition';
import { GraphQLDirective } from '../type/directives';
import { GraphQLSchema } from '../type/schema';
import { DirectiveLocationEnum } from '../language/directiveLocation';
Expand All @@ -16,33 +6,33 @@ export const BreakingChangeType: _BreakingChangeType;

// @internal
type _BreakingChangeType = {
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND';
FIELD_REMOVED: 'FIELD_REMOVED';
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND';
TYPE_REMOVED: 'TYPE_REMOVED';
TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND';
TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION';
VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM';
ARG_REMOVED: 'ARG_REMOVED';
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND';
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED';
REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED';
INTERFACE_REMOVED_FROM_OBJECT: 'INTERFACE_REMOVED_FROM_OBJECT';
FIELD_REMOVED: 'FIELD_REMOVED';
FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND';
REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED';
ARG_REMOVED: 'ARG_REMOVED';
ARG_CHANGED_KIND: 'ARG_CHANGED_KIND';
DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED';
DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED';
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED';
DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED';
};

export const DangerousChangeType: _DangerousChangeType;

// @internal
type _DangerousChangeType = {
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE';
VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM';
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT';
TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION';
OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED';
OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED';
INTERFACE_ADDED_TO_OBJECT: 'INTERFACE_ADDED_TO_OBJECT';
ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE';
};

export interface BreakingChange {
Expand Down Expand Up @@ -72,119 +62,3 @@ export function findDangerousChanges(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<DangerousChange>;

/**
* Given two schemas, returns an Array containing descriptions of any breaking
* changes in the newSchema related to removing an entire type.
*/
export function findRemovedTypes(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

/**
* Given two schemas, returns an Array containing descriptions of any breaking
* changes in the newSchema related to changing the type of a type.
*/
export function findTypesThatChangedKind(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

/**
* Given two schemas, returns an Array containing descriptions of any
* breaking or dangerous changes in the newSchema related to arguments
* (such as removal or change of type of an argument, or a change in an
* argument's default value).
*/
export function findArgChanges(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): {
breakingChanges: Array<BreakingChange>;
dangerousChanges: Array<DangerousChange>;
};

export function findFieldsThatChangedTypeOnObjectOrInterfaceTypes(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

export function findFieldsThatChangedTypeOnInputObjectTypes(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): {
breakingChanges: Array<BreakingChange>;
dangerousChanges: Array<DangerousChange>;
};

/**
* Given two schemas, returns an Array containing descriptions of any breaking
* changes in the newSchema related to removing types from a union type.
*/
export function findTypesRemovedFromUnions(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

/**
* Given two schemas, returns an Array containing descriptions of any dangerous
* changes in the newSchema related to adding types to a union type.
*/
export function findTypesAddedToUnions(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<DangerousChange>;

/**
* Given two schemas, returns an Array containing descriptions of any breaking
* changes in the newSchema related to removing values from an enum type.
*/
export function findValuesRemovedFromEnums(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

/**
* Given two schemas, returns an Array containing descriptions of any dangerous
* changes in the newSchema related to adding values to an enum type.
*/
export function findValuesAddedToEnums(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<DangerousChange>;

export function findInterfacesRemovedFromObjectTypes(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

export function findInterfacesAddedToObjectTypes(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<DangerousChange>;

export function findRemovedDirectives(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

export function findRemovedDirectiveArgs(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

export function findAddedNonNullDirectiveArgs(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;

export function findRemovedLocationsForDirective(
oldDirective: GraphQLDirective,
newDirective: GraphQLDirective,
): Array<DirectiveLocationEnum>;

export function findRemovedDirectiveLocations(
oldSchema: GraphQLSchema,
newSchema: GraphQLSchema,
): Array<BreakingChange>;
4 changes: 2 additions & 2 deletions tstypes/utilities/findDeprecatedUsages.d.ts
@@ -1,6 +1,6 @@
import { GraphQLSchema } from '../type/schema';
import { DocumentNode } from '../language/ast';
import { GraphQLError } from '../error/GraphQLError';
import { DocumentNode } from '../language/ast';
import { GraphQLSchema } from '../type/schema';

/**
* A validation rule which reports deprecated usages.
Expand Down
2 changes: 1 addition & 1 deletion tstypes/utilities/getOperationRootType.d.ts
@@ -1,8 +1,8 @@
import { GraphQLSchema } from '../type/schema';
import {
OperationDefinitionNode,
OperationTypeDefinitionNode,
} from '../language/ast';
import { GraphQLSchema } from '../type/schema';
import { GraphQLObjectType } from '../type/definition';

/**
Expand Down
7 changes: 7 additions & 0 deletions tstypes/utilities/index.d.ts
Expand Up @@ -81,6 +81,9 @@ export { astFromValue } from './astFromValue';
// the GraphQL type system.
export { TypeInfo } from './TypeInfo';

// Coerces a JavaScript value to a GraphQL type, or produces errors.
export { coerceInputValue } from './coerceInputValue';

// Coerces a JavaScript value to a GraphQL type, or produces errors.
export { coerceValue } from './coerceValue';

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

// Strips characters that are not significant to the validity or execution
// of a GraphQL document.
export { stripIgnoredCharacters } from './stripIgnoredCharacters';

// Comparators for types
export {
isEqualType,
Expand Down
2 changes: 1 addition & 1 deletion tstypes/utilities/separateOperations.d.ts
@@ -1,4 +1,4 @@
import { DocumentNode, OperationDefinitionNode } from '../language/ast';
import { DocumentNode } from '../language/ast';

/**
* separateOperations accepts a single AST document which may contain many
Expand Down