diff --git a/graphql/index.d.ts b/graphql/index.d.ts index 0e93923c1d..b156afa6cf 100644 --- a/graphql/index.d.ts +++ b/graphql/index.d.ts @@ -1,11 +1,11 @@ -// Type definitions for graphql v0.7.0 +// Type definitions for graphql v0.8.0 // Project: https://www.npmjs.com/package/graphql -// Definitions by: TonyYang , Caleb Meredith +// Definitions by: TonyYang , Caleb Meredith , Dominic Watson // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /************************************* - * * - * MODULES * + * * + * MODULES * * * *************************************/ /////////////////////////// @@ -29,6 +29,9 @@ declare module "graphql" { // Execute GraphQL queries. export { execute, + defaultFieldResolver, + responsePathAsArray, + ExecutionResult, } from 'graphql/execution'; @@ -43,6 +46,8 @@ declare module "graphql" { export { GraphQLError, formatError, + GraphQLFormattedError, + GraphQLErrorLocation, } from 'graphql/error'; @@ -70,6 +75,9 @@ declare module "graphql" { // Print a GraphQLSchema to GraphQL Schema language. printSchema, + // Print a GraphQLType to GraphQL Schema language. + printType, + // Create a GraphQLType from a GraphQL language AST. typeFromAST, @@ -102,12 +110,32 @@ declare module "graphql" { // Asserts a string is a valid GraphQL name. assertValidName, + + BreakingChange, + + IntrospectionDirective, + IntrospectionEnumType, + IntrospectionEnumValue, + IntrospectionField, + IntrospectionInputObjectType, + IntrospectionInputValue, + IntrospectionInterfaceType, + IntrospectionListTypeRef, + IntrospectionNamedTypeRef, + IntrospectionNonNullTypeRef, + IntrospectionObjectType, + IntrospectionQuery, + IntrospectionScalarType, + IntrospectionSchema, + IntrospectionType, + IntrospectionTypeRef, + IntrospectionUnionType, } from 'graphql/utilities'; } declare module "graphql/graphql" { - import { GraphQLError } from 'graphql/error/GraphQLError'; import { GraphQLSchema } from 'graphql/type/schema'; + import { ExecutionResult } from 'graphql/execution/execute'; /** * This is the primary entry point function for fulfilling GraphQL operations @@ -142,18 +170,7 @@ declare module "graphql/graphql" { [key: string]: any }, operationName?: string - ): Promise; - - /** - * The result of a GraphQL parse, validation and execution. - * - * `data` is the result of a successful execution of the query. - * `errors` is included when any errors occurred as a non-empty array. - */ - type GraphQLResult = { - data?: Object; - errors?: Array; - } + ): Promise; } /////////////////////////// @@ -177,7 +194,7 @@ declare module "graphql/language/index" { export { getLocation } from 'graphql/language/location'; import * as Kind from 'graphql/language/kinds'; export { Kind }; - export { createLexer, TokenKind } from 'graphql/language/lexer'; + export { createLexer, TokenKind, Lexer } from 'graphql/language/lexer'; export { parse, parseValue, parseType } from 'graphql/language/parser'; export { print } from 'graphql/language/printer'; export { Source } from 'graphql/language/source'; @@ -286,46 +303,46 @@ declare module "graphql/language/ast" { /** * The list of all possible AST node types. */ - export type Node = Name - | Document - | OperationDefinition - | VariableDefinition - | Variable - | SelectionSet - | Field - | Argument - | FragmentSpread - | InlineFragment - | FragmentDefinition - | IntValue - | FloatValue - | StringValue - | BooleanValue - | EnumValue - | ListValue - | ObjectValue - | ObjectField - | Directive - | NamedType - | ListType - | NonNullType - | SchemaDefinition - | OperationTypeDefinition - | ScalarTypeDefinition - | ObjectTypeDefinition - | FieldDefinition - | InputValueDefinition - | InterfaceTypeDefinition - | UnionTypeDefinition - | EnumTypeDefinition - | EnumValueDefinition - | InputObjectTypeDefinition - | TypeExtensionDefinition - | DirectiveDefinition + export type ASTNode = NameNode + | DocumentNode + | OperationDefinitionNode + | VariableDefinitionNode + | VariableNode + | SelectionSetNode + | FieldNode + | ArgumentNode + | FragmentSpreadNode + | InlineFragmentNode + | FragmentDefinitionNode + | IntValueNode + | FloatValueNode + | StringValueNode + | BooleanValueNode + | EnumValueNode + | ListValueNode + | ObjectValueNode + | ObjectFieldNode + | DirectiveNode + | NamedTypeNode + | ListTypeNode + | NonNullTypeNode + | SchemaDefinitionNode + | OperationTypeDefinitionNode + | ScalarTypeDefinitionNode + | ObjectTypeDefinitionNode + | FieldDefinitionNode + | InputValueDefinitionNode + | InterfaceTypeDefinitionNode + | UnionTypeDefinitionNode + | EnumTypeDefinitionNode + | EnumValueDefinitionNode + | InputObjectTypeDefinitionNode + | TypeExtensionDefinitionNode + | DirectiveDefinitionNode; // Name - export type Name = { + export type NameNode = { kind: 'Name'; loc?: Location; value: string; @@ -333,306 +350,306 @@ declare module "graphql/language/ast" { // Document - export type Document = { + export type DocumentNode = { kind: 'Document'; loc?: Location; - definitions: Array; + definitions: Array; } - export type Definition = OperationDefinition - | FragmentDefinition - | TypeSystemDefinition // experimental non-spec addition. + export type DefinitionNode = OperationDefinitionNode + | FragmentDefinitionNode + | TypeSystemDefinitionNode // experimental non-spec addition. - export type OperationDefinition = { + export type OperationDefinitionNode = { kind: 'OperationDefinition'; loc?: Location; - operation: OperationType; - name?: Name; - variableDefinitions?: Array; - directives?: Array; - selectionSet: SelectionSet; + operation: OperationTypeNode; + name?: NameNode; + variableDefinitions?: Array; + directives?: Array; + selectionSet: SelectionSetNode; } // Note: subscription is an experimental non-spec addition. - export type OperationType = 'query' | 'mutation' | 'subscription'; + export type OperationTypeNode = 'query' | 'mutation' | 'subscription'; - export type VariableDefinition = { + export type VariableDefinitionNode = { kind: 'VariableDefinition'; loc?: Location; - variable: Variable; - type: Type; - defaultValue?: Value; + variable: VariableNode; + type: TypeNode; + defaultValue?: ValueNode; } - export type Variable = { + export type VariableNode = { kind: 'Variable'; loc?: Location; - name: Name; + name: NameNode; } - export type SelectionSet = { + export type SelectionSetNode = { kind: 'SelectionSet'; loc?: Location; - selections: Array; + selections: Array; } - export type Selection = Field - | FragmentSpread - | InlineFragment + export type SelectionNode = FieldNode + | FragmentSpreadNode + | InlineFragmentNode - export type Field = { + export type FieldNode = { kind: 'Field'; loc?: Location; - alias?: Name; - name: Name; - arguments?: Array; - directives?: Array; - selectionSet?: SelectionSet; + alias?: NameNode; + name: NameNode; + arguments?: Array; + directives?: Array; + selectionSet?: SelectionSetNode; } - export type Argument = { + export type ArgumentNode = { kind: 'Argument'; loc?: Location; - name: Name; - value: Value; + name: NameNode; + value: ValueNode; } // Fragments - export type FragmentSpread = { + export type FragmentSpreadNode = { kind: 'FragmentSpread'; loc?: Location; - name: Name; - directives?: Array; + name: NameNode; + directives?: Array; } - export type InlineFragment = { + export type InlineFragmentNode = { kind: 'InlineFragment'; loc?: Location; - typeCondition?: NamedType; - directives?: Array; - selectionSet: SelectionSet; + typeCondition?: NamedTypeNode; + directives?: Array; + selectionSet: SelectionSetNode; } - export type FragmentDefinition = { + export type FragmentDefinitionNode = { kind: 'FragmentDefinition'; loc?: Location; - name: Name; - typeCondition: NamedType; - directives?: Array; - selectionSet: SelectionSet; + name: NameNode; + typeCondition: NamedTypeNode; + directives?: Array; + selectionSet: SelectionSetNode; } // Values - export type Value = Variable - | IntValue - | FloatValue - | StringValue - | BooleanValue - | EnumValue - | ListValue - | ObjectValue + export type ValueNode = VariableNode + | IntValueNode + | FloatValueNode + | StringValueNode + | BooleanValueNode + | EnumValueNode + | ListValueNode + | ObjectValueNode - export type IntValue = { + export type IntValueNode = { kind: 'IntValue'; loc?: Location; value: string; } - export type FloatValue = { + export type FloatValueNode = { kind: 'FloatValue'; loc?: Location; value: string; } - export type StringValue = { + export type StringValueNode = { kind: 'StringValue'; loc?: Location; value: string; } - export type BooleanValue = { + export type BooleanValueNode = { kind: 'BooleanValue'; loc?: Location; value: boolean; } - export type EnumValue = { + export type EnumValueNode = { kind: 'EnumValue'; loc?: Location; value: string; } - export type ListValue = { + export type ListValueNode = { kind: 'ListValue'; loc?: Location; - values: Array; + values: Array; } - export type ObjectValue = { + export type ObjectValueNode = { kind: 'ObjectValue'; loc?: Location; - fields: Array; + fields: Array; } - export type ObjectField = { + export type ObjectFieldNode = { kind: 'ObjectField'; loc?: Location; - name: Name; - value: Value; + name: NameNode; + value: ValueNode; } // Directives - export type Directive = { + export type DirectiveNode = { kind: 'Directive'; loc?: Location; - name: Name; - arguments?: Array; + name: NameNode; + arguments?: Array; } // Type Reference - export type Type = NamedType - | ListType - | NonNullType + export type TypeNode = NamedTypeNode + | ListTypeNode + | NonNullTypeNode - export type NamedType = { + export type NamedTypeNode = { kind: 'NamedType'; loc?: Location; - name: Name; + name: NameNode; }; - export type ListType = { + export type ListTypeNode = { kind: 'ListType'; loc?: Location; - type: Type; + type: TypeNode; } - export type NonNullType = { + export type NonNullTypeNode = { kind: 'NonNullType'; loc?: Location; - type: NamedType | ListType; + type: NamedTypeNode | ListTypeNode; } // Type System Definition - export type TypeSystemDefinition = SchemaDefinition - | TypeDefinition - | TypeExtensionDefinition - | DirectiveDefinition + export type TypeSystemDefinitionNode = SchemaDefinitionNode + | TypeDefinitionNode + | TypeExtensionDefinitionNode + | DirectiveDefinitionNode - export type SchemaDefinition = { + export type SchemaDefinitionNode = { kind: 'SchemaDefinition'; loc?: Location; - directives: Array; - operationTypes: Array; + directives: Array; + operationTypes: Array; } - export type OperationTypeDefinition = { + export type OperationTypeDefinitionNode = { kind: 'OperationTypeDefinition'; loc?: Location; - operation: OperationType; - type: NamedType; + operation: OperationTypeNode; + type: NamedTypeNode; } - export type TypeDefinition = ScalarTypeDefinition - | ObjectTypeDefinition - | InterfaceTypeDefinition - | UnionTypeDefinition - | EnumTypeDefinition - | InputObjectTypeDefinition + export type TypeDefinitionNode = ScalarTypeDefinitionNode + | ObjectTypeDefinitionNode + | InterfaceTypeDefinitionNode + | UnionTypeDefinitionNode + | EnumTypeDefinitionNode + | InputObjectTypeDefinitionNode - export type ScalarTypeDefinition = { + export type ScalarTypeDefinitionNode = { kind: 'ScalarTypeDefinition'; loc?: Location; - name: Name; - directives?: Array; + name: NameNode; + directives?: Array; } - export type ObjectTypeDefinition = { + export type ObjectTypeDefinitionNode = { kind: 'ObjectTypeDefinition'; loc?: Location; - name: Name; - interfaces?: Array; - directives?: Array; - fields: Array; + name: NameNode; + interfaces?: Array; + directives?: Array; + fields: Array; } - export type FieldDefinition = { + export type FieldDefinitionNode = { kind: 'FieldDefinition'; loc?: Location; - name: Name; - arguments: Array; - type: Type; - directives?: Array; + name: NameNode; + arguments: Array; + type: TypeNode; + directives?: Array; } - export type InputValueDefinition = { + export type InputValueDefinitionNode = { kind: 'InputValueDefinition'; loc?: Location; - name: Name; - type: Type; - defaultValue?: Value; - directives?: Array; + name: NameNode; + type: TypeNode; + defaultValue?: ValueNode; + directives?: Array; } - export type InterfaceTypeDefinition = { + export type InterfaceTypeDefinitionNode = { kind: 'InterfaceTypeDefinition'; loc?: Location; - name: Name; - directives?: Array; - fields: Array; + name: NameNode; + directives?: Array; + fields: Array; } - export type UnionTypeDefinition = { + export type UnionTypeDefinitionNode = { kind: 'UnionTypeDefinition'; loc?: Location; - name: Name; - directives?: Array; - types: Array; + name: NameNode; + directives?: Array; + types: Array; } - export type EnumTypeDefinition = { + export type EnumTypeDefinitionNode = { kind: 'EnumTypeDefinition'; loc?: Location; - name: Name; - directives?: Array; - values: Array; + name: NameNode; + directives?: Array; + values: Array; } - export type EnumValueDefinition = { + export type EnumValueDefinitionNode = { kind: 'EnumValueDefinition'; loc?: Location; - name: Name; - directives?: Array; + name: NameNode; + directives?: Array; } - export type InputObjectTypeDefinition = { + export type InputObjectTypeDefinitionNode = { kind: 'InputObjectTypeDefinition'; loc?: Location; - name: Name; - directives?: Array; - fields: Array; + name: NameNode; + directives?: Array; + fields: Array; } - export type TypeExtensionDefinition = { + export type TypeExtensionDefinitionNode = { kind: 'TypeExtensionDefinition'; loc?: Location; - definition: ObjectTypeDefinition; + definition: ObjectTypeDefinitionNode; } - export type DirectiveDefinition = { + export type DirectiveDefinitionNode = { kind: 'DirectiveDefinition'; loc?: Location; - name: Name; - arguments?: Array; - locations: Array; + name: NameNode; + arguments?: Array; + locations: Array; } } @@ -664,6 +681,7 @@ declare module "graphql/language/kinds" { const FLOAT: 'FloatValue'; const STRING: 'StringValue'; const BOOLEAN: 'BooleanValue'; + const NULL: 'NullValue'; const ENUM: 'EnumValue'; const LIST: 'ListValue'; const OBJECT: 'ObjectValue'; @@ -801,7 +819,7 @@ declare module "graphql/language/location" { } declare module "graphql/language/parser" { - import { NamedType, Type, Value, Document } from "graphql/language/ast"; + import { NamedTypeNode, TypeNode, ValueNode, DocumentNode } from "graphql/language/ast"; import { Source } from "graphql/language/source"; import { Lexer } from "graphql/language/lexer"; @@ -824,7 +842,7 @@ declare module "graphql/language/parser" { function parse( source: string | Source, options?: ParseOptions - ): Document; + ): DocumentNode; /** * Given a string containing a GraphQL value, parse the AST for that value. @@ -836,9 +854,9 @@ declare module "graphql/language/parser" { function parseValue( source: Source | string, options?: ParseOptions - ): Value; + ): ValueNode; - function parseConstValue(lexer: Lexer): Value; + function parseConstValue(lexer: Lexer): ValueNode; /** * Type : @@ -846,12 +864,20 @@ declare module "graphql/language/parser" { * - ListType * - NonNullType */ - function parseType(lexer: Lexer): Type; + function parseType(lexer: Lexer): TypeNode; + + /** + * Type : + * - NamedType + * - ListType + * - NonNullType + */ + function parseTypeReference(lexer: Lexer): TypeNode; /** * NamedType : Name */ - function parseNamedType(lexer: Lexer): NamedType; + function parseNamedType(lexer: Lexer): NamedTypeNode; } declare module "graphql/language/printer" { @@ -889,6 +915,7 @@ declare module "graphql/language/visitor" { FloatValue: number[]; StringValue: string[]; BooleanValue: boolean[]; + NullValue: null[], EnumValue: any[]; ListValue: string[]; ObjectValue: string[]; @@ -980,14 +1007,15 @@ declare module "graphql/type/index" { TypeNameMetaFieldDef, } from 'graphql/type/introspection'; + export { DirectiveLocationEnum } from 'graphql/type/directives'; } declare module "graphql/type/definition" { import { - OperationDefinition, - Field, - FragmentDefinition, - Value, + OperationDefinitionNode, + FieldNode, + FragmentDefinitionNode, + ValueNode, } from 'graphql/language/ast'; import { GraphQLSchema } from 'graphql/type/schema'; @@ -1136,7 +1164,7 @@ declare module "graphql/type/definition" { parseValue(value: any): any; // Parses an externally provided literal value to use as an input. - parseLiteral(valueAST: Value): any; + parseLiteral(valueNode: ValueNode): any; toString(): string; } @@ -1146,7 +1174,7 @@ declare module "graphql/type/definition" { description?: string; serialize: (value: any) => TInternal; parseValue?: (value: any) => TExternal; - parseLiteral?: (valueAST: Value) => TInternal; + parseLiteral?: (valueNode: ValueNode) => TInternal; } /** @@ -1192,7 +1220,7 @@ declare module "graphql/type/definition" { isTypeOf: GraphQLIsTypeOfFn; constructor(config: GraphQLObjectTypeConfig); - getFields(): GraphQLFieldDefinitionMap; + getFields(): GraphQLFieldMap; getInterfaces(): Array; toString(): string; } @@ -1207,7 +1235,7 @@ declare module "graphql/type/definition" { description?: string } - export type GraphQLTypeResolveFn = ( + export type GraphQLTypeResolver = ( value: any, context: any, info: GraphQLResolveInfo @@ -1219,7 +1247,7 @@ declare module "graphql/type/definition" { info: GraphQLResolveInfo ) => boolean; - export type GraphQLFieldResolveFn = ( + export type GraphQLFieldResolver = ( source: TSource, args: { [argName: string]: any }, context: any, @@ -1228,21 +1256,23 @@ declare module "graphql/type/definition" { export interface GraphQLResolveInfo { fieldName: string; - fieldASTs: Array; + fieldNodes: Array; returnType: GraphQLOutputType; parentType: GraphQLCompositeType; - path: Array; + path: ResponsePath; schema: GraphQLSchema; - fragments: { [fragmentName: string]: FragmentDefinition }; + fragments: { [fragmentName: string]: FragmentDefinitionNode }; rootValue: any; - operation: OperationDefinition; + operation: OperationDefinitionNode; variableValues: { [variableName: string]: any }; } + export type ResponsePath = { prev: ResponsePath, key: string | number } | void; + export interface GraphQLFieldConfig { type: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; - resolve?: GraphQLFieldResolveFn; + resolve?: GraphQLFieldResolver; deprecationReason?: string; description?: string; } @@ -1261,12 +1291,12 @@ declare module "graphql/type/definition" { [fieldName: string]: GraphQLFieldConfig; } - export interface GraphQLFieldDefinition { + export interface GraphQLField { name: string; description: string; type: GraphQLOutputType; args: Array; - resolve: GraphQLFieldResolveFn; + resolve: GraphQLFieldResolver; isDeprecated: boolean; deprecationReason: string; } @@ -1278,8 +1308,8 @@ declare module "graphql/type/definition" { description?: string; } - export interface GraphQLFieldDefinitionMap { - [fieldName: string]: GraphQLFieldDefinition; + export interface GraphQLFieldMap { + [fieldName: string]: GraphQLField; } /** @@ -1303,11 +1333,11 @@ declare module "graphql/type/definition" { class GraphQLInterfaceType { name: string; description: string; - resolveType: GraphQLTypeResolveFn; + resolveType: GraphQLTypeResolver; constructor(config: GraphQLInterfaceTypeConfig); - getFields(): GraphQLFieldDefinitionMap; + getFields(): GraphQLFieldMap; toString(): string; } @@ -1320,7 +1350,7 @@ declare module "graphql/type/definition" { * the default implementation will call `isTypeOf` on each implementing * Object type. */ - resolveType?: GraphQLTypeResolveFn, + resolveType?: GraphQLTypeResolver, description?: string } @@ -1350,7 +1380,7 @@ declare module "graphql/type/definition" { class GraphQLUnionType { name: string; description: string; - resolveType: GraphQLTypeResolveFn; + resolveType: GraphQLTypeResolver; constructor(config: GraphQLUnionTypeConfig); @@ -1367,7 +1397,7 @@ declare module "graphql/type/definition" { * the default implementation will call `isTypeOf` on each implementing * Object type. */ - resolveType?: GraphQLTypeResolveFn; + resolveType?: GraphQLTypeResolver; description?: string; } @@ -1397,10 +1427,10 @@ declare module "graphql/type/definition" { description: string; constructor(config: GraphQLEnumTypeConfig); - getValues(): Array; + getValues(): Array; serialize(value: any): string; parseValue(value: any): any; - parseLiteral(valueAST: Value): any; + parseLiteral(valueNode: ValueNode): any; toString(): string; } @@ -1420,7 +1450,7 @@ declare module "graphql/type/definition" { description?: string; } - export interface GraphQLEnumValueDefinition { + export interface GraphQLEnumValue { name: string; description: string; deprecationReason: string; @@ -1451,7 +1481,7 @@ declare module "graphql/type/definition" { name: string; description: string; constructor(config: GraphQLInputObjectTypeConfig); - getFields(): GraphQLInputFieldDefinitionMap; + getFields(): GraphQLInputFieldMap; toString(): string; } @@ -1471,15 +1501,15 @@ declare module "graphql/type/definition" { [fieldName: string]: GraphQLInputFieldConfig; } - export interface GraphQLInputFieldDefinition { + export interface GraphQLInputField { name: string; type: GraphQLInputType; defaultValue?: any; description?: string; } - export interface GraphQLInputFieldDefinitionMap { - [fieldName: string]: GraphQLInputFieldDefinition; + export interface GraphQLInputFieldMap { + [fieldName: string]: GraphQLInputField; } /** @@ -1623,7 +1653,7 @@ declare module "graphql/type/introspection" { GraphQLList, GraphQLNonNull, } from 'graphql/type/definition'; - import { GraphQLFieldDefinition } from 'graphql/type/definition'; + import { GraphQLField } from 'graphql/type/definition'; const __Schema: GraphQLObjectType; const __Directive: GraphQLObjectType; @@ -1647,12 +1677,12 @@ declare module "graphql/type/introspection" { const __TypeKind: GraphQLEnumType; /** - * Note that these are GraphQLFieldDefinition and not GraphQLFieldConfig, + * Note that these are GraphQLField and not GraphQLFieldConfig, * so the format for args is different. */ - const SchemaMetaFieldDef: GraphQLFieldDefinition; - const TypeMetaFieldDef: GraphQLFieldDefinition; - const TypeNameMetaFieldDef: GraphQLFieldDefinition; + const SchemaMetaFieldDef: GraphQLField; + const TypeMetaFieldDef: GraphQLField; + const TypeNameMetaFieldDef: GraphQLField; } declare module "graphql/type/scalars" { @@ -1765,19 +1795,19 @@ declare module "graphql/validation/specifiedRules" { declare module "graphql/validation/validate" { import { GraphQLError } from 'graphql/error'; import { - Document, - OperationDefinition, - Variable, - SelectionSet, - FragmentSpread, - FragmentDefinition, + DocumentNode, + OperationDefinitionNode, + VariableNode, + SelectionSetNode, + FragmentSpreadNode, + FragmentDefinitionNode, } from 'graphql/language/ast'; import { GraphQLSchema } from 'graphql/type/schema'; import { GraphQLInputType, GraphQLOutputType, GraphQLCompositeType, - GraphQLFieldDefinition, + GraphQLField, GraphQLArgument } from 'graphql/type/definition'; import { GraphQLDirective } from 'graphql/type/directives'; @@ -1801,7 +1831,7 @@ declare module "graphql/validation/validate" { */ function validate( schema: GraphQLSchema, - ast: Document, + ast: DocumentNode, rules?: Array ): Array; @@ -1814,13 +1844,13 @@ declare module "graphql/validation/validate" { function visitUsingRules( schema: GraphQLSchema, typeInfo: TypeInfo, - documentAST: Document, + documentAST: DocumentNode, rules: Array ): Array; - type HasSelectionSet = OperationDefinition | FragmentDefinition; + type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode; interface VariableUsage { - node: Variable, + node: VariableNode, type: GraphQLInputType } @@ -1830,27 +1860,27 @@ declare module "graphql/validation/validate" { * validation rule. */ export class ValidationContext { - constructor(schema: GraphQLSchema, ast: Document, typeInfo: TypeInfo); + constructor(schema: GraphQLSchema, ast: DocumentNode, typeInfo: TypeInfo); reportError(error: GraphQLError): void; getErrors(): Array; getSchema(): GraphQLSchema; - getDocument(): Document; + getDocument(): DocumentNode; - getFragment(name: string): FragmentDefinition; + getFragment(name: string): FragmentDefinitionNode; - getFragmentSpreads(node: SelectionSet): Array; + getFragmentSpreads(node: SelectionSetNode): Array; getRecursivelyReferencedFragments( - operation: OperationDefinition - ): Array; + operation: OperationDefinitionNode + ): Array; - getVariableUsages(node: HasSelectionSet): Array; + getVariableUsages(node: NodeWithSelectionSet): Array; getRecursiveVariableUsages( - operation: OperationDefinition + operation: OperationDefinitionNode ): Array; getType(): GraphQLOutputType; @@ -1859,7 +1889,7 @@ declare module "graphql/validation/validate" { getInputType(): GraphQLInputType; - getFieldDef(): GraphQLFieldDefinition; + getFieldDef(): GraphQLField; getDirective(): GraphQLDirective; @@ -1877,20 +1907,21 @@ declare module "graphql/execution" { } declare module "graphql/execution/index" { - export { execute } from 'graphql/execution/execute'; + export { execute, defaultFieldResolver, responsePathAsArray, ExecutionResult } from 'graphql/execution/execute'; } declare module "graphql/execution/execute" { import { GraphQLError, locatedError } from 'graphql/error'; import { GraphQLSchema } from 'graphql/type/schema'; + import { GraphQLField, GraphQLFieldResolver, ResponsePath } from 'graphql/type/definition'; import { - Directive, - Document, - OperationDefinition, - SelectionSet, - Field, - InlineFragment, - FragmentDefinition + DirectiveNode, + DocumentNode, + OperationDefinitionNode, + SelectionSetNode, + FieldNode, + InlineFragmentNode, + FragmentDefinitionNode, } from 'graphql/language/ast'; /** * Data that must be available at all points during query execution. @@ -1900,9 +1931,9 @@ declare module "graphql/execution/execute" { */ interface ExecutionContext { schema: GraphQLSchema; - fragments: { [key: string]: FragmentDefinition }; + fragments: { [key: string]: FragmentDefinitionNode }; rootValue: any; - operation: OperationDefinition; + operation: OperationDefinitionNode; variableValues: { [key: string]: any }; errors: Array; } @@ -1912,8 +1943,8 @@ declare module "graphql/execution/execute" { * query, `errors` is null if no errors occurred, and is a * non-empty array if an error occurred. */ - interface ExecutionResult { - data: Object; + export interface ExecutionResult { + data: {[key: string]: any}; errors?: Array; } @@ -1927,20 +1958,39 @@ declare module "graphql/execution/execute" { */ function execute( schema: GraphQLSchema, - documentAST: Document, + document: DocumentNode, rootValue?: any, contextValue?: any, variableValues?: { [key: string]: any }, operationName?: string - ): Promise + ): Promise; + + /** + * Given a ResponsePath (found in the `path` entry in the information provided + * as the last argument to a field resolver), return an Array of the path keys. + */ + export function responsePathAsArray( + path: ResponsePath + ): Array; + + function addPath(prev: ResponsePath, key: string | number): any; + + /** + * If a resolve function is not given, then a default resolve behavior is used + * which takes the property of the source object of the same name as the field + * and returns it as the result, or if it's a function, returns the result + * of calling that function while passing along args and context. + */ + export const defaultFieldResolver: GraphQLFieldResolver; } declare module "graphql/execution/values" { - import { GraphQLInputType, GraphQLArgument } from 'graphql/type/definition'; + import { GraphQLInputType, GraphQLField, GraphQLArgument } from 'graphql/type/definition'; + import { GraphQLDirective } from 'graphql/type/directives'; import { GraphQLSchema } from 'graphql/type/schema'; - import { Argument, VariableDefinition } from 'graphql/language/ast'; + import { FieldNode, DirectiveNode, VariableDefinitionNode } from 'graphql/language/ast'; /** * Prepares an object map of variableValues of the correct type based on the * provided variable definitions and arbitrary input. If the input cannot be @@ -1948,7 +1998,7 @@ declare module "graphql/execution/values" { */ function getVariableValues( schema: GraphQLSchema, - definitionASTs: Array, + varDefNodes: Array, inputs: { [key: string]: any } ): { [key: string]: any } @@ -1957,8 +2007,8 @@ declare module "graphql/execution/values" { * definitions and list of argument AST nodes. */ function getArgumentValues( - argDefs: Array, - argASTs: Array, + def: GraphQLField | GraphQLDirective, + node: FieldNode | DirectiveNode, variableValues?: { [key: string]: any } ): { [key: string]: any }; } @@ -1974,7 +2024,7 @@ declare module "graphql/error/index" { export { GraphQLError } from 'graphql/error/GraphQLError'; export { syntaxError } from 'graphql/error/syntaxError'; export { locatedError } from 'graphql/error/locatedError'; - export { formatError } from 'graphql/error/formatError'; + export { formatError, GraphQLFormattedError, GraphQLErrorLocation } from 'graphql/error/formatError'; } declare module "graphql/error/formatError" { @@ -1988,7 +2038,8 @@ declare module "graphql/error/formatError" { type GraphQLFormattedError = { message: string, - locations: Array + locations: Array, + path: Array }; type GraphQLErrorLocation = { @@ -1999,7 +2050,7 @@ declare module "graphql/error/formatError" { declare module "graphql/error/GraphQLError" { import { getLocation } from 'graphql/language'; - import { Node } from 'graphql/language/ast'; + import { ASTNode } from 'graphql/language/ast'; import { Source } from 'graphql/language/source'; /** @@ -2040,7 +2091,7 @@ declare module "graphql/error/GraphQLError" { /** * An array of GraphQL AST Nodes corresponding to this error. */ - nodes: Array | void; + nodes: Array | void; /** * The source GraphQL document corresponding to this error. @@ -2100,6 +2151,25 @@ declare module "graphql/utilities" { declare module "graphql/utilities/index" { // The GraphQL query recommended for a full schema introspection. export { introspectionQuery } from 'graphql/utilities/introspectionQuery'; + export { + IntrospectionQuery, + IntrospectionSchema, + IntrospectionType, + IntrospectionScalarType, + IntrospectionObjectType, + IntrospectionInterfaceType, + IntrospectionUnionType, + IntrospectionEnumType, + IntrospectionInputObjectType, + IntrospectionTypeRef, + IntrospectionNamedTypeRef, + IntrospectionListTypeRef, + IntrospectionNonNullTypeRef, + IntrospectionField, + IntrospectionInputValue, + IntrospectionEnumValue, + IntrospectionDirective, + } from 'graphql/utilities/introspectionQuery'; // Gets the target Operation from a Document export { getOperationAST } from 'graphql/utilities/getOperationAST'; @@ -2114,7 +2184,7 @@ declare module "graphql/utilities/index" { export { extendSchema } from 'graphql/utilities/extendSchema'; // Print a GraphQLSchema to GraphQL Schema language. - export { printSchema, printIntrospectionSchema } from 'graphql/utilities/schemaPrinter'; + export { printSchema, printType, printIntrospectionSchema } from 'graphql/utilities/schemaPrinter'; // Create a GraphQLType from a GraphQL language AST. export { typeFromAST } from 'graphql/utilities/typeFromAST'; @@ -2150,6 +2220,10 @@ declare module "graphql/utilities/index" { // Asserts that a string is a valid GraphQL name export { assertValidName } from 'graphql/utilities/assertValidName'; + + // Compares two GraphQLSchemas and detects breaking changes. + export { findBreakingChanges } from 'graphql/utilities/findBreakingChanges'; + export { BreakingChange } from 'graphql/utilities/findBreakingChanges'; } declare module "graphql/utilities/assertValidName" { @@ -2159,14 +2233,14 @@ declare module "graphql/utilities/assertValidName" { declare module "graphql/utilities/astFromValue" { import { - Value, - //IntValue, - //FloatValue, - //StringValue, - //BooleanValue, - //EnumValue, - //ListValue, - //ObjectValue, + ValueNode, + //IntValueNode, + //FloatValueNode, + //StringValueNode, + //BooleanValueNode, + //EnumValueNode, + //ListValueNode, + //ObjectValueNode, } from 'graphql/language/ast'; import { GraphQLInputType } from 'graphql/type/definition'; @@ -2190,11 +2264,11 @@ declare module "graphql/utilities/astFromValue" { export function astFromValue( value: any, type: GraphQLInputType - ): Value // Warning: there is a code in bottom: throw new TypeError + ): ValueNode // Warning: there is a code in bottom: throw new TypeError } declare module "graphql/utilities/buildASTSchema" { - import { Document, Location } from 'graphql/language/ast'; + import { DocumentNode, Location } from 'graphql/language/ast'; import { Source } from 'graphql/language/source'; import { GraphQLSchema } from 'graphql/type/schema'; @@ -2208,7 +2282,7 @@ declare module "graphql/utilities/buildASTSchema" { * Given that AST it constructs a GraphQLSchema. The resulting schema * has no resolve methods, so execution will use default resolvers. */ - function buildASTSchema(ast: Document): GraphQLSchema; + function buildASTSchema(ast: DocumentNode): GraphQLSchema; /** * Given an ast node, returns its string description based on a contiguous @@ -2253,17 +2327,17 @@ declare module "graphql/utilities/buildClientSchema" { } declare module "graphql/utilities/concatAST" { - import { Document } from 'graphql/language/ast'; + import { DocumentNode } from 'graphql/language/ast'; /** * Provided a collection of ASTs, presumably each from different files, * concatenate the ASTs together into batched AST, useful for validating many * GraphQL source files which together represent one conceptual application. */ - function concatAST(asts: Array): Document; + function concatAST(asts: Array): DocumentNode; } declare module "graphql/utilities/extendSchema" { - import { Document } from 'graphql/language/ast'; + import { DocumentNode } from 'graphql/language/ast'; import { GraphQLSchema } from 'graphql/type/schema'; /** @@ -2280,12 +2354,102 @@ declare module "graphql/utilities/extendSchema" { */ function extendSchema( schema: GraphQLSchema, - documentAST: Document + documentAST: DocumentNode ): GraphQLSchema; } +declare module "graphql/utilities/findBreakingChanges" { + import { + getNamedType, + GraphQLScalarType, + GraphQLEnumType, + GraphQLInputObjectType, + GraphQLInterfaceType, + GraphQLObjectType, + GraphQLUnionType, + GraphQLNamedType, + } from 'graphql/type/definition'; + import { GraphQLSchema } from 'graphql/type/schema'; + + export const BreakingChangeType: { + FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND', + FIELD_REMOVED: 'FIELD_REMOVED', + TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND', + TYPE_REMOVED: 'TYPE_REMOVED', + TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION', + VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM', + }; + + type BreakingChangeKey = 'FIELD_CHANGED_KIND' + | 'FIELD_REMOVED' + | 'TYPE_CHANGED_KIND' + | 'TYPE_REMOVED' + | 'TYPE_REMOVED_FROM_UNION' + | 'VALUE_REMOVED_FROM_ENUM'; + + export type BreakingChange = { + type: BreakingChangeKey; + description: string; + }; + + /** + * Given two schemas, returns an Array containing descriptions of all the types + * of breaking changes covered by the other functions down below. + */ + export function findBreakingChanges( + oldSchema: GraphQLSchema, + newSchema: GraphQLSchema + ): Array + + /** + * 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 + + /** + * 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 + + /** + * Given two schemas, returns an Array containing descriptions of any breaking + * changes in the newSchema related to the fields on a type. This includes if + * a field has been removed from a type or if a field has changed type. + */ + export function findFieldsThatChangedType( + oldSchema: GraphQLSchema, + newSchema: GraphQLSchema + ): Array; + + /** + * 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; + + /** + * 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; +} + declare module "graphql/utilities/getOperationAST" { - import { Document, OperationDefinition } from 'graphql/language/ast'; + import { DocumentNode, OperationDefinitionNode } from 'graphql/language/ast'; /** * Returns an operation AST given a document AST and optionally an operation @@ -2293,9 +2457,9 @@ declare module "graphql/utilities/getOperationAST" { * provided in the document. */ export function getOperationAST( - documentAST: Document, + documentAST: DocumentNode, operationName: string - ): OperationDefinition; + ): OperationDefinitionNode; } declare module "graphql/utilities/introspectionQuery" { @@ -2526,7 +2690,7 @@ declare module "graphql/utilities/isValidJSValue" { } declare module "graphql/utilities/isValidLiteralValue" { - import { Value } from 'graphql/language/ast'; + import { ValueNode } from 'graphql/language/ast'; import { GraphQLInputType } from 'graphql/type/definition'; /** @@ -2538,27 +2702,30 @@ declare module "graphql/utilities/isValidLiteralValue" { */ function isValidLiteralValue( type: GraphQLInputType, - valueAST: Value + valueNode: ValueNode ): Array } declare module "graphql/utilities/schemaPrinter" { import { GraphQLSchema } from 'graphql/type/schema'; + import { GraphQLType } from 'graphql/type/definition'; function printSchema(schema: GraphQLSchema): string; function printIntrospectionSchema(schema: GraphQLSchema): string; + + function printType(type: GraphQLType): string } declare module "graphql/utilities/separateOperations" { import { - Document, - OperationDefinition, + DocumentNode, + OperationDefinitionNode, } from 'graphql/language/ast'; function separateOperations( - documentAST: Document - ): { [operationName: string]: Document } + documentAST: DocumentNode + ): { [operationName: string]: DocumentNode } } declare module "graphql/utilities/typeComparators" { @@ -2603,13 +2770,13 @@ declare module "graphql/utilities/typeComparators" { } declare module "graphql/utilities/typeFromAST" { - import { Type } from 'graphql/language/ast'; + import { TypeNode } from 'graphql/language/ast'; import { GraphQLType, GraphQLNullableType } from 'graphql/type/definition'; import { GraphQLSchema } from 'graphql/type/schema'; function typeFromAST( schema: GraphQLSchema, - inputTypeAST: Type + typeNode: TypeNode ): GraphQLType } @@ -2620,14 +2787,14 @@ declare module "graphql/utilities/TypeInfo" { declare module "graphql/utilities/valueFromAST" { import { GraphQLInputType } from 'graphql/type/definition'; import { - Value, - Variable, - ListValue, - ObjectValue + ValueNode, + VariableNode, + ListValueNode, + ObjectValueNode } from 'graphql/language/ast'; function valueFromAST( - valueAST: Value, + valueNode: ValueNode, type: GraphQLInputType, variables?: { [key: string]: any