diff --git a/types/graphql/error/GraphQLError.d.ts b/types/graphql/error/GraphQLError.d.ts index 12f65a506c..857f25b593 100644 --- a/types/graphql/error/GraphQLError.d.ts +++ b/types/graphql/error/GraphQLError.d.ts @@ -27,7 +27,7 @@ export class GraphQLError extends Error { * * Enumerable, and appears in the result of JSON.stringify(). */ - locations?: Array<{ line: number, column: number }> | void; + locations?: Array<{ line: number, column: number }> | undefined; /** * An array describing the JSON-path into the execution response which @@ -35,23 +35,23 @@ export class GraphQLError extends Error { * * Enumerable, and appears in the result of JSON.stringify(). */ - path?: Array | void; + path?: Array | undefined; /** * An array of GraphQL AST Nodes corresponding to this error. */ - nodes?: Array | void; + nodes?: Array | undefined; /** * The source GraphQL document corresponding to this error. */ - source?: Source | void; + source?: Source | undefined; /** * An array of character offsets within the source GraphQL document * which correspond to this error. */ - positions?: Array | void; + positions?: Array | undefined; /** * The original error thrown from a field resolver during execution. diff --git a/types/graphql/index.d.ts b/types/graphql/index.d.ts index 43d810de02..de2a1405e6 100644 --- a/types/graphql/index.d.ts +++ b/types/graphql/index.d.ts @@ -1,6 +1,6 @@ -// Type definitions for graphql v0.8.2 +// Type definitions for graphql 0.9 // Project: https://www.npmjs.com/package/graphql -// Definitions by: TonyYang , Caleb Meredith , Dominic Watson +// Definitions by: TonyYang , Caleb Meredith , Dominic Watson , Firede // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -105,6 +105,12 @@ export { // Asserts a string is a valid GraphQL name. assertValidName, + // Compares two GraphQLSchemas and detects breaking changes. + findBreakingChanges, + + // Report all deprecated usage within a GraphQL document. + findDeprecatedUsages, + BreakingChange, IntrospectionDirective, diff --git a/types/graphql/language/ast.d.ts b/types/graphql/language/ast.d.ts index 238cbe7210..d0f25b65d0 100644 --- a/types/graphql/language/ast.d.ts +++ b/types/graphql/language/ast.d.ts @@ -85,7 +85,7 @@ export type Token = { /** * For non-punctuation tokens, represents the interpreted value of the token. */ - value: string | void; + value: string | undefined; /** * Tokens exist as nodes in a double-linked-list amongst all tokens diff --git a/types/graphql/language/visitor.d.ts b/types/graphql/language/visitor.d.ts index 1d0f399d6e..d4c528501e 100644 --- a/types/graphql/language/visitor.d.ts +++ b/types/graphql/language/visitor.d.ts @@ -42,7 +42,7 @@ export const QueryDocumentKeys: { export const BREAK: any; -export function visit(root: any, visitor: any, keyMap: any): any; +export function visit(root: any, visitor: any, keyMap?: any): any; export function visitInParallel(visitors: any): any; diff --git a/types/graphql/type/definition.d.ts b/types/graphql/type/definition.d.ts index 6fef914d8e..cf077ad5ba 100644 --- a/types/graphql/type/definition.d.ts +++ b/types/graphql/type/definition.d.ts @@ -126,6 +126,10 @@ export type GraphQLNamedType = GraphQLEnumType | GraphQLInputObjectType; +export function isNamedType(type: GraphQLType): boolean; + +export function assertNamedType(type: GraphQLType): GraphQLNamedType; + export function getNamedType(type: GraphQLType): GraphQLNamedType; /** @@ -237,13 +241,13 @@ export type GraphQLTypeResolver = ( value: TSource, context: TContext, info: GraphQLResolveInfo -) => GraphQLObjectType; +) => GraphQLObjectType | string | Promise; export type GraphQLIsTypeOfFn = ( source: TSource, context: TContext, info: GraphQLResolveInfo -) => boolean; +) => boolean | Promise; export type GraphQLFieldResolver = ( source: TSource, @@ -265,7 +269,7 @@ export interface GraphQLResolveInfo { variableValues: { [variableName: string]: any }; } -export type ResponsePath = { prev: ResponsePath, key: string | number } | void; +export type ResponsePath = { prev: ResponsePath, key: string | number } | undefined; export interface GraphQLFieldConfig { type: GraphQLOutputType; @@ -426,6 +430,7 @@ export class GraphQLEnumType { constructor(config: GraphQLEnumTypeConfig); getValues(): Array; + getValue(name: string): GraphQLEnumValue; serialize(value: any): string; parseValue(value: any): any; parseLiteral(valueNode: ValueNode): any; diff --git a/types/graphql/utilities/TypeInfo.d.ts b/types/graphql/utilities/TypeInfo.d.ts index 2957114ae5..b4fa855569 100644 --- a/types/graphql/utilities/TypeInfo.d.ts +++ b/types/graphql/utilities/TypeInfo.d.ts @@ -5,6 +5,7 @@ import { GraphQLInputType, GraphQLField, GraphQLArgument, + GraphQLEnumValue, GraphQLType, } from '../type/definition'; import { GraphQLDirective } from '../type/directives'; @@ -30,6 +31,7 @@ export class TypeInfo { getFieldDef(): GraphQLField; getDirective(): GraphQLDirective; getArgument(): GraphQLArgument; + getEnumValue(): GraphQLEnumValue; enter(node: ASTNode): any; leave(node: ASTNode): any; } @@ -40,4 +42,4 @@ export interface getFieldDef { parentType: GraphQLType, fieldNode: FieldNode ): GraphQLField -} \ No newline at end of file +} diff --git a/types/graphql/utilities/buildASTSchema.d.ts b/types/graphql/utilities/buildASTSchema.d.ts index cf782a30ec..94f4e2a47a 100644 --- a/types/graphql/utilities/buildASTSchema.d.ts +++ b/types/graphql/utilities/buildASTSchema.d.ts @@ -26,15 +26,3 @@ export function getDescription(node: { loc?: Location }): string; * document. */ export function buildSchema(source: string | Source): GraphQLSchema; - -/** - * Given an ast node, returns its string description based on a contiguous - * block full-line of comments preceding it. - */ -export function getDescription(node: { loc?: Location }): string; - -/** - * A helper function to build a GraphQLSchema directly from a source - * document. - */ -export function buildSchema(source: string | Source): GraphQLSchema; diff --git a/types/graphql/utilities/findDeprecatedUsages.d.ts b/types/graphql/utilities/findDeprecatedUsages.d.ts new file mode 100644 index 0000000000..58e9ae1685 --- /dev/null +++ b/types/graphql/utilities/findDeprecatedUsages.d.ts @@ -0,0 +1,13 @@ +import { GraphQLSchema } from '../type/schema'; +import { DocumentNode } from '../language/ast'; +import { GraphQLError } from '../error/GraphQLError'; + +/** + * A validation rule which reports deprecated usages. + * + * Returns a list of GraphQLError instances describing each deprecated use. + */ +export function findDeprecatedUsages( + schema: GraphQLSchema, + ast: DocumentNode +): Array diff --git a/types/graphql/utilities/getOperationAST.d.ts b/types/graphql/utilities/getOperationAST.d.ts index 65c7735a5d..ce99d39b2b 100644 --- a/types/graphql/utilities/getOperationAST.d.ts +++ b/types/graphql/utilities/getOperationAST.d.ts @@ -7,5 +7,5 @@ import { DocumentNode, OperationDefinitionNode } from '../language/ast'; */ export function getOperationAST( documentAST: DocumentNode, - operationName: string + operationName?: string ): OperationDefinitionNode; diff --git a/types/graphql/utilities/index.d.ts b/types/graphql/utilities/index.d.ts index 47cfd70ff9..8815046735 100644 --- a/types/graphql/utilities/index.d.ts +++ b/types/graphql/utilities/index.d.ts @@ -73,3 +73,6 @@ export { assertValidName } from './assertValidName'; // Compares two GraphQLSchemas and detects breaking changes. export { findBreakingChanges } from './findBreakingChanges'; export { BreakingChange } from './findBreakingChanges'; + +// Report all deprecated usage within a GraphQL document. +export { findDeprecatedUsages } from './findDeprecatedUsages';