diff --git a/src/error/GraphQLError.d.ts b/src/error/GraphQLError.d.ts index 5634a6b0ef..4bdcfd27c7 100644 --- a/src/error/GraphQLError.d.ts +++ b/src/error/GraphQLError.d.ts @@ -9,15 +9,6 @@ import type { SourceLocation } from '../language/location'; * GraphQL document and/or execution result that correspond to the Error. */ export class GraphQLError extends Error { - constructor( - message: string, - nodes?: Maybe | ASTNode>, - source?: Maybe, - positions?: Maybe>, - path?: Maybe>, - originalError?: Maybe, - extensions?: Maybe<{ [key: string]: unknown }>, - ); /** * A message describing the Error for debugging purposes. * @@ -36,30 +27,30 @@ export class GraphQLError extends Error { * * Enumerable, and appears in the result of JSON.stringify(). */ - readonly locations: ReadonlyArray | undefined; + readonly locations?: ReadonlyArray; /** * An array describing the JSON-path into the execution response which * corresponds to this error. Only included for errors during execution. * * Enumerable, and appears in the result of JSON.stringify(). */ - readonly path: ReadonlyArray | undefined; + readonly path?: ReadonlyArray; /** * An array of GraphQL AST Nodes corresponding to this error. */ - readonly nodes: ReadonlyArray | undefined; + readonly nodes?: ReadonlyArray; /** - * The source GraphQL document corresponding to this error. + * The source GraphQL document for the first location of this error. * * Note that if this Error represents more than one node, the source may not * represent nodes after the first node. */ - readonly source: Source | undefined; + readonly source?: Source; /** * An array of character offsets within the source GraphQL document * which correspond to this error. */ - readonly positions: ReadonlyArray | undefined; + readonly positions?: ReadonlyArray; /** * The original error thrown from a field resolver during execution. */ @@ -67,7 +58,26 @@ export class GraphQLError extends Error { /** * Extension fields to add to the formatted error. */ - readonly extensions: { [key: string]: unknown } | undefined; + readonly extensions?: { + [key: string]: unknown; + }; + constructor( + message: string, + nodes?: ReadonlyArray | ASTNode | null, + source?: Maybe, + positions?: Maybe>, + path?: Maybe>, + originalError?: Maybe< + Error & { + readonly extensions?: unknown; + } + >, + extensions?: Maybe<{ + [key: string]: unknown; + }>, + ); + toString(): string; + get [Symbol.toStringTag](): string; } /** * Prints a GraphQLError to a string, representing useful location information diff --git a/src/error/formatError.d.ts b/src/error/formatError.d.ts index e473694d3b..db7acf73a0 100644 --- a/src/error/formatError.d.ts +++ b/src/error/formatError.d.ts @@ -31,5 +31,7 @@ export interface GraphQLFormattedError { * Reserved for implementors to extend the protocol however they see fit, * and hence there are no additional restrictions on its contents. */ - readonly extensions?: { [key: string]: unknown }; + readonly extensions?: { + [key: string]: unknown; + }; } diff --git a/src/error/index.d.ts b/src/error/index.d.ts index 9373b7167d..e69dacf43a 100644 --- a/src/error/index.d.ts +++ b/src/error/index.d.ts @@ -1,4 +1,5 @@ export { GraphQLError, printError } from './GraphQLError'; export { syntaxError } from './syntaxError'; export { locatedError } from './locatedError'; -export { formatError, GraphQLFormattedError } from './formatError'; +export { formatError } from './formatError'; +export type { GraphQLFormattedError } from './formatError'; diff --git a/src/error/locatedError.d.ts b/src/error/locatedError.d.ts index 1b69ac0e77..ef1460d66a 100644 --- a/src/error/locatedError.d.ts +++ b/src/error/locatedError.d.ts @@ -1,6 +1,6 @@ import type { Maybe } from '../jsutils/Maybe'; import type { ASTNode } from '../language/ast'; -import type { GraphQLError } from './GraphQLError'; +import { GraphQLError } from './GraphQLError'; /** * Given an arbitrary value, presumably thrown while attempting to execute a * GraphQL operation, produce a new GraphQLError aware of the location in the @@ -8,6 +8,6 @@ import type { GraphQLError } from './GraphQLError'; */ export function locatedError( rawOriginalError: unknown, - nodes: ASTNode | ReadonlyArray | undefined, + nodes: ASTNode | ReadonlyArray | undefined | null, path?: Maybe>, ): GraphQLError; diff --git a/src/error/syntaxError.d.ts b/src/error/syntaxError.d.ts index 842b6d416f..6df94d4cd7 100644 --- a/src/error/syntaxError.d.ts +++ b/src/error/syntaxError.d.ts @@ -1,5 +1,5 @@ import type { Source } from '../language/source'; -import type { GraphQLError } from './GraphQLError'; +import { GraphQLError } from './GraphQLError'; /** * Produces a GraphQLError representing a syntax error, containing useful * descriptive information about the syntax error's position in the source. diff --git a/src/execution/execute.d.ts b/src/execution/execute.d.ts index 3f2af256db..d2f87bb32d 100644 --- a/src/execution/execute.d.ts +++ b/src/execution/execute.d.ts @@ -1,9 +1,9 @@ -import type { Maybe } from '../jsutils/Maybe'; +import type { Path } from '../jsutils/Path'; import type { ObjMap } from '../jsutils/ObjMap'; import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; -import type { Path } from '../jsutils/Path'; -import type { GraphQLError } from '../error/GraphQLError'; +import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLFormattedError } from '../error/formatError'; +import { GraphQLError } from '../error/GraphQLError'; import type { DocumentNode, OperationDefinitionNode, @@ -13,11 +13,11 @@ import type { } from '../language/ast'; import type { GraphQLSchema } from '../type/schema'; import type { + GraphQLObjectType, GraphQLField, GraphQLFieldResolver, GraphQLResolveInfo, GraphQLTypeResolver, - GraphQLObjectType, } from '../type/definition'; /** * Terminology @@ -46,11 +46,13 @@ import type { */ export interface ExecutionContext { schema: GraphQLSchema; + fragments: ObjMap; rootValue: unknown; contextValue: unknown; - fragments: ObjMap; operation: OperationDefinitionNode; - variableValues: { [key: string]: unknown }; + variableValues: { + [variable: string]: unknown; + }; fieldResolver: GraphQLFieldResolver; typeResolver: GraphQLTypeResolver; errors: Array; @@ -63,20 +65,18 @@ export interface ExecutionContext { * - `extensions` is reserved for adding non-standard properties. */ export interface ExecutionResult< - TData = { [key: string]: any }, - TExtensions = { [key: string]: any }, + TData = ObjMap, + TExtensions = ObjMap, > { errors?: ReadonlyArray; - // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 data?: TData | null; extensions?: TExtensions; } export interface FormattedExecutionResult< - TData = { [key: string]: any }, - TExtensions = { [key: string]: any }, + TData = ObjMap, + TExtensions = ObjMap, > { errors?: ReadonlyArray; - // TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229 data?: TData | null; extensions?: TExtensions; } @@ -85,7 +85,9 @@ export interface ExecutionArgs { document: DocumentNode; rootValue?: unknown; contextValue?: unknown; - variableValues?: Maybe<{ [key: string]: unknown }>; + variableValues?: Maybe<{ + readonly [variable: string]: unknown; + }>; operationName?: Maybe; fieldResolver?: Maybe>; typeResolver?: Maybe>; @@ -116,7 +118,9 @@ export function executeSync(args: ExecutionArgs): ExecutionResult; export function assertValidExecutionArguments( schema: GraphQLSchema, document: DocumentNode, - rawVariableValues: Maybe<{ [key: string]: unknown }>, + rawVariableValues: Maybe<{ + readonly [variable: string]: unknown; + }>, ): void; /** * Constructs a ExecutionContext object from the arguments passed to @@ -131,7 +135,9 @@ export function buildExecutionContext( document: DocumentNode, rootValue: unknown, contextValue: unknown, - rawVariableValues: Maybe<{ [key: string]: unknown }>, + rawVariableValues: Maybe<{ + readonly [variable: string]: unknown; + }>, operationName: Maybe, fieldResolver: Maybe>, typeResolver?: Maybe>, @@ -150,9 +156,9 @@ export function collectFields( exeContext: ExecutionContext, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, - fields: ObjMap>, - visitedFragmentNames: ObjMap, -): ObjMap>; + fields: Map>, + visitedFragmentNames: Set, +): Map>; /** * @internal */ @@ -195,5 +201,5 @@ export const defaultFieldResolver: GraphQLFieldResolver; export function getFieldDef( schema: GraphQLSchema, parentType: GraphQLObjectType, - fieldName: string, + fieldNode: FieldNode, ): Maybe>; diff --git a/src/execution/index.d.ts b/src/execution/index.d.ts index d7a618c81b..674aeb30cf 100644 --- a/src/execution/index.d.ts +++ b/src/execution/index.d.ts @@ -4,6 +4,8 @@ export { executeSync, defaultFieldResolver, defaultTypeResolver, +} from './execute'; +export type { ExecutionArgs, ExecutionResult, FormattedExecutionResult, diff --git a/src/execution/values.d.ts b/src/execution/values.d.ts index b0829ed83a..6150727e0e 100644 --- a/src/execution/values.d.ts +++ b/src/execution/values.d.ts @@ -1,17 +1,25 @@ -import type { Maybe } from '../jsutils/Maybe'; import type { ObjMap } from '../jsutils/ObjMap'; -import type { GraphQLError } from '../error/GraphQLError'; +import type { Maybe } from '../jsutils/Maybe'; +import { GraphQLError } from '../error/GraphQLError'; import type { FieldNode, DirectiveNode, VariableDefinitionNode, } from '../language/ast'; -import type { GraphQLDirective } from '../type/directives'; import type { GraphQLSchema } from '../type/schema'; import type { GraphQLField } from '../type/definition'; +import type { GraphQLDirective } from '../type/directives'; type CoercedVariableValues = - | { errors: ReadonlyArray; coerced?: never } - | { errors?: never; coerced: { [key: string]: unknown } }; + | { + errors: ReadonlyArray; + coerced?: never; + } + | { + coerced: { + [variable: string]: unknown; + }; + errors?: never; + }; /** * Prepares an object map of variableValues of the correct type based on the * provided variable definitions and arbitrary input. If the input cannot be @@ -20,12 +28,18 @@ type CoercedVariableValues = * Note: The returned value is a plain Object with a prototype, since it is * exposed to user code. Care should be taken to not pull values from the * Object prototype. + * + * @internal */ export function getVariableValues( schema: GraphQLSchema, varDefNodes: ReadonlyArray, - inputs: { [key: string]: unknown }, - options?: { maxErrors?: number }, + inputs: { + readonly [variable: string]: unknown; + }, + options?: { + maxErrors?: number; + }, ): CoercedVariableValues; /** * Prepares an object map of argument values given a list of argument @@ -34,12 +48,16 @@ export function getVariableValues( * Note: The returned value is a plain Object with a prototype, since it is * exposed to user code. Care should be taken to not pull values from the * Object prototype. + * + * @internal */ export function getArgumentValues( def: GraphQLField | GraphQLDirective, node: FieldNode | DirectiveNode, variableValues?: Maybe>, -): { [key: string]: unknown }; +): { + [argument: string]: unknown; +}; /** * Prepares an object map of argument values given a directive definition * and a AST node which may contain directives. Optionally also accepts a map @@ -57,4 +75,8 @@ export function getDirectiveValues( readonly directives?: ReadonlyArray; }, variableValues?: Maybe>, -): undefined | { [key: string]: unknown }; +): + | undefined + | { + [argument: string]: unknown; + }; diff --git a/src/graphql.d.ts b/src/graphql.d.ts index 13fe084937..92dd8b2b68 100644 --- a/src/graphql.d.ts +++ b/src/graphql.d.ts @@ -1,10 +1,10 @@ import type { Maybe } from './jsutils/Maybe'; import type { Source } from './language/source'; -import type { GraphQLSchema } from './type/schema'; import type { GraphQLFieldResolver, GraphQLTypeResolver, } from './type/definition'; +import type { GraphQLSchema } from './type/schema'; import type { ExecutionResult } from './execution/execute'; /** * This is the primary entry point function for fulfilling GraphQL operations @@ -50,7 +50,9 @@ export interface GraphQLArgs { source: string | Source; rootValue?: unknown; contextValue?: unknown; - variableValues?: Maybe<{ [key: string]: unknown }>; + variableValues?: Maybe<{ + readonly [variable: string]: unknown; + }>; operationName?: Maybe; fieldResolver?: Maybe>; typeResolver?: Maybe>; diff --git a/src/index.d.ts b/src/index.d.ts index d90543c3bf..6a1733c97c 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -1,4 +1,3 @@ -// Minimum TypeScript Version: 3.7 /** * GraphQL.js provides a reference implementation for the GraphQL specification * but is also a useful utility for operating on GraphQL files and building @@ -25,7 +24,8 @@ /** The GraphQL.js version info. */ export { version, versionInfo } from './version'; /** The primary entry point into fulfilling a GraphQL request. */ -export { GraphQLArgs, graphql, graphqlSync } from './graphql'; +export type { GraphQLArgs } from './graphql'; +export { graphql, graphqlSync } from './graphql'; /** Create and operate on GraphQL type definitions and schema. */ export { /** Definitions */ @@ -122,7 +122,7 @@ export { validateSchema, assertValidSchema, } from './type/index'; -export { +export type { GraphQLType, GraphQLInputType, GraphQLOutputType, @@ -147,19 +147,19 @@ export { GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, - GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, + GraphQLEnumValueExtensions, GraphQLField, GraphQLFieldConfig, - GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, + GraphQLFieldExtensions, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, - GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, + GraphQLInputFieldExtensions, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, GraphQLInputObjectTypeExtensions, @@ -217,7 +217,7 @@ export { isTypeSystemExtensionNode, isTypeExtensionNode, } from './language/index'; -export { +export type { ParseOptions, SourceLocation, TokenKindEnum, @@ -298,15 +298,14 @@ export { defaultTypeResolver, responsePathAsArray, getDirectiveValues, +} from './execution/index'; +export type { ExecutionArgs, ExecutionResult, FormattedExecutionResult, } from './execution/index'; -export { - subscribe, - createSourceEventStream, - SubscriptionArgs, -} from './subscription/index'; +export { subscribe, createSourceEventStream } from './subscription/index'; +export type { SubscriptionArgs } from './subscription/index'; /** Validate GraphQL documents. */ export { validate, @@ -351,8 +350,8 @@ export { /** Custom validation rules */ NoDeprecatedCustomRule, NoSchemaIntrospectionCustomRule, - ValidationRule, } from './validation/index'; +export type { ValidationRule } from './validation/index'; /** Create, format, and print GraphQL errors. */ export { GraphQLError, @@ -360,8 +359,8 @@ export { locatedError, printError, formatError, - GraphQLFormattedError, } from './error/index'; +export type { GraphQLFormattedError } from './error/index'; /** Utilities for operating on GraphQL type schema and parsed sources. */ export { /** @@ -424,7 +423,7 @@ export { findBreakingChanges, findDangerousChanges, } from './utilities/index'; -export { +export type { IntrospectionOptions, IntrospectionQuery, IntrospectionSchema, diff --git a/src/jsutils/ObjMap.d.ts b/src/jsutils/ObjMap.d.ts index 9387488d89..fa87afb12d 100644 --- a/src/jsutils/ObjMap.d.ts +++ b/src/jsutils/ObjMap.d.ts @@ -1,6 +1,16 @@ -export type ObjMap = Record; -export type ObjMapLike = ObjMap | Record; -export type ReadOnlyObjMap = Readonly>; +export interface ObjMap { + [key: string]: T; +} +export type ObjMapLike = + | ObjMap + | { + [key: string]: T; + }; +export interface ReadOnlyObjMap { + readonly [key: string]: T; +} export type ReadOnlyObjMapLike = - | Readonly> - | ReadOnlyObjMap; + | ReadOnlyObjMap + | { + readonly [key: string]: T; + }; diff --git a/src/jsutils/Path.d.ts b/src/jsutils/Path.d.ts index b14d49c7e9..943c3a5dc7 100644 --- a/src/jsutils/Path.d.ts +++ b/src/jsutils/Path.d.ts @@ -1,17 +1,20 @@ +import type { Maybe } from './Maybe'; export interface Path { - prev: Path | undefined; - key: string | number; - typename: string | undefined; + readonly prev: Path | undefined; + readonly key: string | number; + readonly typename: string | undefined; } /** * Given a Path and a key, return a new Path containing the new key. */ export function addPath( - prev: Path | undefined, + prev: Readonly | undefined, key: string | number, typename: string | undefined, ): Path; /** * Given a Path, return an Array of the path keys. */ -export function pathToArray(path: Path): Array; +export function pathToArray( + path: Maybe>, +): Array; diff --git a/src/jsutils/instanceOf.d.ts b/src/jsutils/instanceOf.d.ts index f95e88ff59..03221d907b 100644 --- a/src/jsutils/instanceOf.d.ts +++ b/src/jsutils/instanceOf.d.ts @@ -1 +1,10 @@ -export const instanceOf: (value: unknown, constructor: unknown) => boolean; +/** + * A replacement for instanceof which includes an error warning when multi-realm + * constructors are detected. + * See: https://expressjs.com/en/advanced/best-practice-performance.html#set-node_env-to-production + * See: https://webpack.js.org/guides/production/ + */ +export const instanceOf: (value: unknown, constructor: Constructor) => boolean; +interface Constructor extends Function { + name: string; +} diff --git a/src/jsutils/isObjectLike.d.ts b/src/jsutils/isObjectLike.d.ts index 54c36fe228..6e58c1145f 100644 --- a/src/jsutils/isObjectLike.d.ts +++ b/src/jsutils/isObjectLike.d.ts @@ -2,4 +2,6 @@ * Return true if `value` is object-like. A value is object-like if it's not * `null` and has a `typeof` result of "object". */ -export function isObjectLike(value: unknown): value is Record; +export function isObjectLike(value: unknown): value is { + [key: string]: unknown; +}; diff --git a/src/jsutils/promiseReduce.d.ts b/src/jsutils/promiseReduce.d.ts index 6f4865f4d0..85ad5f2ff5 100644 --- a/src/jsutils/promiseReduce.d.ts +++ b/src/jsutils/promiseReduce.d.ts @@ -7,7 +7,7 @@ import type { PromiseOrValue } from './PromiseOrValue'; * return a Promise. */ export function promiseReduce( - values: ReadonlyArray, - callback: (U: any, T: any) => PromiseOrValue, + values: Iterable, + callbackFn: (accumulator: U, currentValue: T) => PromiseOrValue, initialValue: PromiseOrValue, ): PromiseOrValue; diff --git a/src/language/ast.d.ts b/src/language/ast.d.ts index c6e8d799fd..eb1941c726 100644 --- a/src/language/ast.d.ts +++ b/src/language/ast.d.ts @@ -26,7 +26,10 @@ export class Location { */ readonly source: Source; constructor(startToken: Token, endToken: Token, source: Source); - toJSON(): { start: number; end: number }; + toJSON(): { + start: number; + end: number; + }; } /** * Represents a range of characters represented by a lexical token @@ -56,7 +59,7 @@ export class Token { /** * For non-punctuation tokens, represents the interpreted value of the token. */ - readonly value: string | undefined; + readonly value?: string; /** * Tokens exist as nodes in a double-linked-list amongst all tokens * including ignored tokens. is always the first node and @@ -75,7 +78,7 @@ export class Token { ); toJSON(): { kind: TokenKindEnum; - value: string | undefined; + value?: string; line: number; column: number; }; diff --git a/src/language/blockString.d.ts b/src/language/blockString.d.ts index b56ce27d7c..1ef70f9074 100644 --- a/src/language/blockString.d.ts +++ b/src/language/blockString.d.ts @@ -10,7 +10,7 @@ export function dedentBlockStringValue(rawString: string): string; /** * @internal */ -export function getBlockStringIndentation(body: string): number; +export function getBlockStringIndentation(value: string): number; /** * Print a block string in the indented block form by adding a leading and * trailing blank line. However, if a block string starts with whitespace and is @@ -20,6 +20,5 @@ export function getBlockStringIndentation(body: string): number; */ export function printBlockString( value: string, - indentation?: string, preferMultipleLines?: boolean, ): string; diff --git a/src/language/directiveLocation.d.ts b/src/language/directiveLocation.d.ts index 1e8a7153c5..a6ae437f08 100644 --- a/src/language/directiveLocation.d.ts +++ b/src/language/directiveLocation.d.ts @@ -3,26 +3,26 @@ */ export const DirectiveLocation: Readonly<{ /** Request Definitions */ - QUERY: 'QUERY'; - MUTATION: 'MUTATION'; - SUBSCRIPTION: 'SUBSCRIPTION'; - FIELD: 'FIELD'; - FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION'; - FRAGMENT_SPREAD: 'FRAGMENT_SPREAD'; - INLINE_FRAGMENT: 'INLINE_FRAGMENT'; - VARIABLE_DEFINITION: 'VARIABLE_DEFINITION'; + readonly QUERY: 'QUERY'; + readonly MUTATION: 'MUTATION'; + readonly SUBSCRIPTION: 'SUBSCRIPTION'; + readonly FIELD: 'FIELD'; + readonly FRAGMENT_DEFINITION: 'FRAGMENT_DEFINITION'; + readonly FRAGMENT_SPREAD: 'FRAGMENT_SPREAD'; + readonly INLINE_FRAGMENT: 'INLINE_FRAGMENT'; + readonly VARIABLE_DEFINITION: 'VARIABLE_DEFINITION'; /** Type System Definitions */ - SCHEMA: 'SCHEMA'; - SCALAR: 'SCALAR'; - OBJECT: 'OBJECT'; - FIELD_DEFINITION: 'FIELD_DEFINITION'; - ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION'; - INTERFACE: 'INTERFACE'; - UNION: 'UNION'; - ENUM: 'ENUM'; - ENUM_VALUE: 'ENUM_VALUE'; - INPUT_OBJECT: 'INPUT_OBJECT'; - INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'; + readonly SCHEMA: 'SCHEMA'; + readonly SCALAR: 'SCALAR'; + readonly OBJECT: 'OBJECT'; + readonly FIELD_DEFINITION: 'FIELD_DEFINITION'; + readonly ARGUMENT_DEFINITION: 'ARGUMENT_DEFINITION'; + readonly INTERFACE: 'INTERFACE'; + readonly UNION: 'UNION'; + readonly ENUM: 'ENUM'; + readonly ENUM_VALUE: 'ENUM_VALUE'; + readonly INPUT_OBJECT: 'INPUT_OBJECT'; + readonly INPUT_FIELD_DEFINITION: 'INPUT_FIELD_DEFINITION'; }>; /** * The enum type representing the directive location values. diff --git a/src/language/index.d.ts b/src/language/index.d.ts index 752d098892..db2ffaff33 100644 --- a/src/language/index.d.ts +++ b/src/language/index.d.ts @@ -1,28 +1,19 @@ export { Source } from './source'; -export { getLocation, SourceLocation } from './location'; +export { getLocation } from './location'; +export type { SourceLocation } from './location'; export { printLocation, printSourceLocation } from './printLocation'; -export { Kind, KindEnum } from './kinds'; -export { TokenKind, TokenKindEnum } from './tokenKind'; +export { Kind } from './kinds'; +export type { KindEnum } from './kinds'; +export { TokenKind } from './tokenKind'; +export type { TokenKindEnum } from './tokenKind'; export { Lexer } from './lexer'; -export { - parse, - parseValue, - parseConstValue, - parseType, - ParseOptions, -} from './parser'; +export { parse, parseValue, parseConstValue, parseType } from './parser'; +export type { ParseOptions } from './parser'; export { print } from './printer'; -export { - visit, - visitInParallel, - getVisitFn, - BREAK, - ASTVisitor, - ASTVisitFn, -} from './visitor'; -export { - Location, - Token, +export { visit, visitInParallel, getVisitFn, BREAK } from './visitor'; +export type { ASTVisitor, ASTVisitFn } from './visitor'; +export { Location, Token } from './ast'; +export type { ASTNode, ASTKindToNode, /** Each kind of AST node */ @@ -98,4 +89,5 @@ export { isTypeSystemExtensionNode, isTypeExtensionNode, } from './predicates'; -export { DirectiveLocation, DirectiveLocationEnum } from './directiveLocation'; +export { DirectiveLocation } from './directiveLocation'; +export type { DirectiveLocationEnum } from './directiveLocation'; diff --git a/src/language/kinds.d.ts b/src/language/kinds.d.ts index 8253fd0eda..17570caa24 100644 --- a/src/language/kinds.d.ts +++ b/src/language/kinds.d.ts @@ -3,59 +3,59 @@ */ export const Kind: Readonly<{ /** Name */ - NAME: 'Name'; + readonly NAME: 'Name'; /** Document */ - DOCUMENT: 'Document'; - OPERATION_DEFINITION: 'OperationDefinition'; - VARIABLE_DEFINITION: 'VariableDefinition'; - SELECTION_SET: 'SelectionSet'; - FIELD: 'Field'; - ARGUMENT: 'Argument'; + readonly DOCUMENT: 'Document'; + readonly OPERATION_DEFINITION: 'OperationDefinition'; + readonly VARIABLE_DEFINITION: 'VariableDefinition'; + readonly SELECTION_SET: 'SelectionSet'; + readonly FIELD: 'Field'; + readonly ARGUMENT: 'Argument'; /** Fragments */ - FRAGMENT_SPREAD: 'FragmentSpread'; - INLINE_FRAGMENT: 'InlineFragment'; - FRAGMENT_DEFINITION: 'FragmentDefinition'; + readonly FRAGMENT_SPREAD: 'FragmentSpread'; + readonly INLINE_FRAGMENT: 'InlineFragment'; + readonly FRAGMENT_DEFINITION: 'FragmentDefinition'; /** Values */ - VARIABLE: 'Variable'; - INT: 'IntValue'; - FLOAT: 'FloatValue'; - STRING: 'StringValue'; - BOOLEAN: 'BooleanValue'; - NULL: 'NullValue'; - ENUM: 'EnumValue'; - LIST: 'ListValue'; - OBJECT: 'ObjectValue'; - OBJECT_FIELD: 'ObjectField'; + readonly VARIABLE: 'Variable'; + readonly INT: 'IntValue'; + readonly FLOAT: 'FloatValue'; + readonly STRING: 'StringValue'; + readonly BOOLEAN: 'BooleanValue'; + readonly NULL: 'NullValue'; + readonly ENUM: 'EnumValue'; + readonly LIST: 'ListValue'; + readonly OBJECT: 'ObjectValue'; + readonly OBJECT_FIELD: 'ObjectField'; /** Directives */ - DIRECTIVE: 'Directive'; + readonly DIRECTIVE: 'Directive'; /** Types */ - NAMED_TYPE: 'NamedType'; - LIST_TYPE: 'ListType'; - NON_NULL_TYPE: 'NonNullType'; + readonly NAMED_TYPE: 'NamedType'; + readonly LIST_TYPE: 'ListType'; + readonly NON_NULL_TYPE: 'NonNullType'; /** Type System Definitions */ - SCHEMA_DEFINITION: 'SchemaDefinition'; - OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition'; + readonly SCHEMA_DEFINITION: 'SchemaDefinition'; + readonly OPERATION_TYPE_DEFINITION: 'OperationTypeDefinition'; /** Type Definitions */ - SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition'; - OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition'; - FIELD_DEFINITION: 'FieldDefinition'; - INPUT_VALUE_DEFINITION: 'InputValueDefinition'; - INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition'; - UNION_TYPE_DEFINITION: 'UnionTypeDefinition'; - ENUM_TYPE_DEFINITION: 'EnumTypeDefinition'; - ENUM_VALUE_DEFINITION: 'EnumValueDefinition'; - INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition'; + readonly SCALAR_TYPE_DEFINITION: 'ScalarTypeDefinition'; + readonly OBJECT_TYPE_DEFINITION: 'ObjectTypeDefinition'; + readonly FIELD_DEFINITION: 'FieldDefinition'; + readonly INPUT_VALUE_DEFINITION: 'InputValueDefinition'; + readonly INTERFACE_TYPE_DEFINITION: 'InterfaceTypeDefinition'; + readonly UNION_TYPE_DEFINITION: 'UnionTypeDefinition'; + readonly ENUM_TYPE_DEFINITION: 'EnumTypeDefinition'; + readonly ENUM_VALUE_DEFINITION: 'EnumValueDefinition'; + readonly INPUT_OBJECT_TYPE_DEFINITION: 'InputObjectTypeDefinition'; /** Directive Definitions */ - DIRECTIVE_DEFINITION: 'DirectiveDefinition'; + readonly DIRECTIVE_DEFINITION: 'DirectiveDefinition'; /** Type System Extensions */ - SCHEMA_EXTENSION: 'SchemaExtension'; + readonly SCHEMA_EXTENSION: 'SchemaExtension'; /** Type Extensions */ - SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension'; - OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension'; - INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension'; - UNION_TYPE_EXTENSION: 'UnionTypeExtension'; - ENUM_TYPE_EXTENSION: 'EnumTypeExtension'; - INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'; + readonly SCALAR_TYPE_EXTENSION: 'ScalarTypeExtension'; + readonly OBJECT_TYPE_EXTENSION: 'ObjectTypeExtension'; + readonly INTERFACE_TYPE_EXTENSION: 'InterfaceTypeExtension'; + readonly UNION_TYPE_EXTENSION: 'UnionTypeExtension'; + readonly ENUM_TYPE_EXTENSION: 'EnumTypeExtension'; + readonly INPUT_OBJECT_TYPE_EXTENSION: 'InputObjectTypeExtension'; }>; /** * The enum type representing the possible kind values of AST nodes. diff --git a/src/language/lexer.d.ts b/src/language/lexer.d.ts index ed7e0137ec..ad08397cc8 100644 --- a/src/language/lexer.d.ts +++ b/src/language/lexer.d.ts @@ -1,8 +1,8 @@ -import type { Token } from './ast'; import type { Source } from './source'; import type { TokenKindEnum } from './tokenKind'; +import { Token } from './ast'; /** - * Given a Source object, this returns a Lexer for that source. + * Given a Source object, creates a Lexer for that source. * A Lexer is a stateful stream generator in that every time * it is advanced, it returns the next token in the Source. Assuming the * source lexes, the final Token emitted by the lexer will be of kind diff --git a/src/language/parser.d.ts b/src/language/parser.d.ts index 8a9239df5d..9d4ef028be 100644 --- a/src/language/parser.d.ts +++ b/src/language/parser.d.ts @@ -1,5 +1,6 @@ import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLError } from '../error/GraphQLError'; +import type { TokenKindEnum } from './tokenKind'; import type { Token, NameNode, @@ -52,9 +53,8 @@ import type { EnumTypeExtensionNode, InputObjectTypeExtensionNode, } from './ast'; -import type { TokenKindEnum } from './tokenKind'; -import type { Source } from './source'; -import type { Lexer } from './lexer'; +import { Location } from './ast'; +import { Source } from './source'; /** * Configuration options to control parser behavior */ @@ -90,11 +90,14 @@ export function parse( options?: ParseOptions, ): DocumentNode; /** - * Given a string containing a GraphQL value, parse the AST for that value. + * Given a string containing a GraphQL value (ex. `[42]`), parse the AST for + * that value. * Throws GraphQLError if a syntax error is encountered. * * This is useful within tools that operate upon GraphQL Values directly and * in isolation of complete GraphQL documents. + * + * Consider providing the results to the utility function: valueFromAST(). */ export function parseValue( source: string | Source, @@ -133,9 +136,9 @@ export function parseType( * * @internal */ -export declare class Parser { - _options: Maybe; - _lexer: Lexer; +export class Parser { + private _options; + private _lexer; constructor(source: string | Source, options?: ParseOptions); /** * Converts a name lex token into a name parse node. @@ -204,7 +207,7 @@ export declare class Parser { * Argument[Const] : Name : Value[?Const] */ parseArgument(isConst: true): ConstArgumentNode; - parseArgument(isConst: boolean): ArgumentNode; + parseArgument(isConst?: boolean): ArgumentNode; parseConstArgument(): ConstArgumentNode; /** * Corresponds to both FragmentSpread and InlineFragment in the spec. @@ -245,6 +248,7 @@ export declare class Parser { */ parseValueLiteral(isConst: true): ConstValueNode; parseValueLiteral(isConst: boolean): ValueNode; + parseConstValueLiteral(): ConstValueNode; parseStringLiteral(): StringValueNode; /** * ListValue[Const] : @@ -270,6 +274,7 @@ export declare class Parser { */ parseDirectives(isConst: true): Array; parseDirectives(isConst: boolean): Array; + parseConstDirectives(): Array; /** * Directive[Const] : @ Name Arguments[?Const]? */ @@ -462,7 +467,11 @@ export declare class Parser { * location object, used to identify the place in the source that created a * given parsed object. */ - node(startToken: Token, node: T): T; + node< + T extends { + loc?: Location; + }, + >(startToken: Token, node: T): T; /** * Determines if the next token is of a given kind */ diff --git a/src/language/printLocation.d.ts b/src/language/printLocation.d.ts index 01154cc477..57aaf1ae9f 100644 --- a/src/language/printLocation.d.ts +++ b/src/language/printLocation.d.ts @@ -1,5 +1,5 @@ -import type { Location } from './ast'; import type { Source } from './source'; +import type { Location } from './ast'; import type { SourceLocation } from './location'; /** * Render a helpful description of the location in the GraphQL Source document. diff --git a/src/language/tokenKind.d.ts b/src/language/tokenKind.d.ts index 85cd86ae0e..b96022906d 100644 --- a/src/language/tokenKind.d.ts +++ b/src/language/tokenKind.d.ts @@ -3,28 +3,28 @@ * lexer emits. */ export const TokenKind: Readonly<{ - SOF: ''; - EOF: ''; - BANG: '!'; - DOLLAR: '$'; - AMP: '&'; - PAREN_L: '('; - PAREN_R: ')'; - SPREAD: '...'; - COLON: ':'; - EQUALS: '='; - AT: '@'; - BRACKET_L: '['; - BRACKET_R: ']'; - BRACE_L: '{'; - PIPE: '|'; - BRACE_R: '}'; - NAME: 'Name'; - INT: 'Int'; - FLOAT: 'Float'; - STRING: 'String'; - BLOCK_STRING: 'BlockString'; - COMMENT: 'Comment'; + readonly SOF: ''; + readonly EOF: ''; + readonly BANG: '!'; + readonly DOLLAR: '$'; + readonly AMP: '&'; + readonly PAREN_L: '('; + readonly PAREN_R: ')'; + readonly SPREAD: '...'; + readonly COLON: ':'; + readonly EQUALS: '='; + readonly AT: '@'; + readonly BRACKET_L: '['; + readonly BRACKET_R: ']'; + readonly BRACE_L: '{'; + readonly PIPE: '|'; + readonly BRACE_R: '}'; + readonly NAME: 'Name'; + readonly INT: 'Int'; + readonly FLOAT: 'Float'; + readonly STRING: 'String'; + readonly BLOCK_STRING: 'BlockString'; + readonly COMMENT: 'Comment'; }>; /** * The enum type representing the token kinds values. diff --git a/src/language/visitor.d.ts b/src/language/visitor.d.ts index 47188d20c5..c19126b1d8 100644 --- a/src/language/visitor.d.ts +++ b/src/language/visitor.d.ts @@ -10,10 +10,10 @@ type KindVisitor = { | ASTVisitFn | EnterLeaveVisitor; }; -type EnterLeaveVisitor = { +interface EnterLeaveVisitor { readonly enter?: ASTVisitFn; readonly leave?: ASTVisitFn; -}; +} /** * A visitor is comprised of visit functions, which are called on each node * during the visitor's traversal. @@ -34,7 +34,7 @@ export type ASTVisitFn = ( */ ancestors: ReadonlyArray>, ) => any; -export const BREAK: any; +export const BREAK: unknown; /** * visit() will walk through an AST using a depth-first traversal, calling * the visitor's enter function at each node in the traversal, and calling the diff --git a/src/subscription/index.d.ts b/src/subscription/index.d.ts index ba8835f196..899e443b6b 100644 --- a/src/subscription/index.d.ts +++ b/src/subscription/index.d.ts @@ -1,5 +1,2 @@ -export { - subscribe, - createSourceEventStream, - SubscriptionArgs, -} from './subscribe'; +export { subscribe, createSourceEventStream } from './subscribe'; +export type { SubscriptionArgs } from './subscribe'; diff --git a/src/subscription/mapAsyncIterator.d.ts b/src/subscription/mapAsyncIterator.d.ts index 15f3d7f58c..a625837eb1 100644 --- a/src/subscription/mapAsyncIterator.d.ts +++ b/src/subscription/mapAsyncIterator.d.ts @@ -3,8 +3,7 @@ import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; * Given an AsyncIterable and a callback function, return an AsyncIterator * which produces values mapped via calling the callback function. */ -export function mapAsyncIterator( - iterable: AsyncIterable | AsyncGenerator, - callback: (arg: T) => PromiseOrValue, - rejectCallback?: (arg: any) => PromiseOrValue, -): AsyncGenerator; +export function mapAsyncIterator( + iterable: AsyncGenerator | AsyncIterable, + callback: (value: T) => PromiseOrValue, +): AsyncGenerator; diff --git a/src/subscription/subscribe.d.ts b/src/subscription/subscribe.d.ts index 67670d9042..29349b19d3 100644 --- a/src/subscription/subscribe.d.ts +++ b/src/subscription/subscribe.d.ts @@ -8,7 +8,9 @@ export interface SubscriptionArgs { document: DocumentNode; rootValue?: unknown; contextValue?: unknown; - variableValues?: Maybe>; + variableValues?: Maybe<{ + readonly [variable: string]: unknown; + }>; operationName?: Maybe; fieldResolver?: Maybe>; subscribeFieldResolver?: Maybe>; @@ -70,7 +72,9 @@ export function createSourceEventStream( document: DocumentNode, rootValue?: unknown, contextValue?: unknown, - variableValues?: { [key: string]: unknown }, + variableValues?: Maybe<{ + readonly [variable: string]: unknown; + }>, operationName?: Maybe, fieldResolver?: Maybe>, ): Promise | ExecutionResult>; diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index 8d275b3521..3f5be271e4 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -1,26 +1,26 @@ -import type { Maybe } from '../jsutils/Maybe'; -import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; import type { Path } from '../jsutils/Path'; +import type { PromiseOrValue } from '../jsutils/PromiseOrValue'; import type { ObjMap } from '../jsutils/ObjMap'; +import type { Maybe } from '../jsutils/Maybe'; import type { + FieldNode, + ValueNode, + OperationDefinitionNode, + FragmentDefinitionNode, ScalarTypeDefinitionNode, + ScalarTypeExtensionNode, ObjectTypeDefinitionNode, + ObjectTypeExtensionNode, FieldDefinitionNode, InputValueDefinitionNode, InterfaceTypeDefinitionNode, + InterfaceTypeExtensionNode, UnionTypeDefinitionNode, + UnionTypeExtensionNode, EnumTypeDefinitionNode, EnumValueDefinitionNode, - InputObjectTypeDefinitionNode, - ObjectTypeExtensionNode, - InterfaceTypeExtensionNode, - OperationDefinitionNode, - FieldNode, - FragmentDefinitionNode, - ValueNode, - ScalarTypeExtensionNode, - UnionTypeExtensionNode, EnumTypeExtensionNode, + InputObjectTypeDefinitionNode, InputObjectTypeExtensionNode, } from '../language/ast'; import type { GraphQLSchema } from './schema'; @@ -34,10 +34,21 @@ export type GraphQLType = | GraphQLUnionType | GraphQLEnumType | GraphQLInputObjectType - | GraphQLList - | GraphQLNonNull; + | GraphQLList + | GraphQLNonNull< + | GraphQLScalarType + | GraphQLObjectType + | GraphQLInterfaceType + | GraphQLUnionType + | GraphQLEnumType + | GraphQLInputObjectType + | GraphQLList + >; export function isType(type: unknown): type is GraphQLType; export function assertType(type: unknown): GraphQLType; +/** + * There are predicates for each kind of GraphQL type. + */ export function isScalarType(type: unknown): type is GraphQLScalarType; export function assertScalarType(type: unknown): GraphQLScalarType; export function isObjectType(type: unknown): type is GraphQLObjectType; @@ -52,48 +63,60 @@ export function isInputObjectType( type: unknown, ): type is GraphQLInputObjectType; export function assertInputObjectType(type: unknown): GraphQLInputObjectType; -export function isListType(type: unknown): type is GraphQLList; -export function assertListType(type: unknown): GraphQLList; -export function isNonNullType(type: unknown): type is GraphQLNonNull; -export function assertNonNullType(type: unknown): GraphQLNonNull; +export function isListType( + type: GraphQLInputType, +): type is GraphQLList; +export function isListType( + type: GraphQLOutputType, +): type is GraphQLList; +export function isListType(type: unknown): type is GraphQLList; +export function assertListType(type: unknown): GraphQLList; +export function isNonNullType( + type: GraphQLInputType, +): type is GraphQLNonNull; +export function isNonNullType( + type: GraphQLOutputType, +): type is GraphQLNonNull; +export function isNonNullType( + type: unknown, +): type is GraphQLNonNull; +export function assertNonNullType(type: unknown): GraphQLNonNull; /** * These types may be used as input types for arguments and directives. */ -// TS_SPECIFIC: TS does not allow recursive type definitions, hence the `any`s export type GraphQLInputType = | GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType - | GraphQLList + | GraphQLList | GraphQLNonNull< | GraphQLScalarType | GraphQLEnumType | GraphQLInputObjectType - | GraphQLList + | GraphQLList >; export function isInputType(type: unknown): type is GraphQLInputType; export function assertInputType(type: unknown): GraphQLInputType; /** * These types may be used as output types as the result of fields. */ -// TS_SPECIFIC: TS does not allow recursive type definitions, hence the `any`s export type GraphQLOutputType = | GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType - | GraphQLList + | GraphQLList | GraphQLNonNull< | GraphQLScalarType | GraphQLObjectType | GraphQLInterfaceType | GraphQLUnionType | GraphQLEnumType - | GraphQLList + | GraphQLList >; -export function isOutputType(type: any): type is GraphQLOutputType; -export function assertOutputType(type: any): GraphQLOutputType; +export function isOutputType(type: unknown): type is GraphQLOutputType; +export function assertOutputType(type: unknown): GraphQLOutputType; /** * These types may describe types which may be leaf values. */ @@ -116,36 +139,35 @@ export type GraphQLAbstractType = GraphQLInterfaceType | GraphQLUnionType; export function isAbstractType(type: unknown): type is GraphQLAbstractType; export function assertAbstractType(type: unknown): GraphQLAbstractType; /** - * List Modifier + * List Type Wrapper * - * A list is a kind of type marker, a wrapping type which points to another - * type. Lists are often created within the context of defining the fields - * of an object type. + * A list is a wrapping type which points to another type. + * Lists are often created within the context of defining the fields of + * an object type. * * Example: * * const PersonType = new GraphQLObjectType({ * name: 'Person', * fields: () => ({ - * parents: { type: new GraphQLList(Person) }, - * children: { type: new GraphQLList(Person) }, + * parents: { type: new GraphQLList(PersonType) }, + * children: { type: new GraphQLList(PersonType) }, * }) * }) * */ export class GraphQLList { readonly ofType: T; - constructor(type: T); - toString: () => string; - toJSON: () => string; - inspect: () => string; + constructor(ofType: T); + toString(): string; + toJSON(): string; get [Symbol.toStringTag](): string; } /** - * Non-Null Modifier + * Non-Null Type Wrapper * - * A non-null is a kind of type marker, a wrapping type which points to another - * type. Non-null types enforce that their values are never null and can ensure + * A non-null is a wrapping type which points to another type. + * Non-null types enforce that their values are never null and can ensure * an error is raised if this ever occurs during a request. It is useful for * fields which you can make a strong guarantee on non-nullability, for example * usually the id field of a database row will never be null. @@ -163,13 +185,17 @@ export class GraphQLList { */ export class GraphQLNonNull { readonly ofType: T; - constructor(type: T); - toString: () => string; - toJSON: () => string; - inspect: () => string; + constructor(ofType: T); + toString(): string; + toJSON(): string; get [Symbol.toStringTag](): string; } -export type GraphQLWrappingType = GraphQLList | GraphQLNonNull; +/** + * These types wrap and modify other types + */ +export type GraphQLWrappingType = + | GraphQLList + | GraphQLNonNull; export function isWrappingType(type: unknown): type is GraphQLWrappingType; export function assertWrappingType(type: unknown): GraphQLWrappingType; /** @@ -182,15 +208,12 @@ export type GraphQLNullableType = | GraphQLUnionType | GraphQLEnumType | GraphQLInputObjectType - | GraphQLList; + | GraphQLList; export function isNullableType(type: unknown): type is GraphQLNullableType; export function assertNullableType(type: unknown): GraphQLNullableType; -export function getNullableType(type: undefined): undefined; -export function getNullableType(type: T): T; +export function getNullableType(type: undefined | null): void; export function getNullableType( - // FIXME Disabled because of https://github.com/yaacovCR/graphql-tools-fork/issues/40#issuecomment-586671219 - // eslint-disable-next-line @typescript-eslint/unified-signatures - type: GraphQLNonNull, + type: T | GraphQLNonNull, ): T; /** * These named types do not include modifiers like List or NonNull. @@ -208,7 +231,7 @@ export type GraphQLNamedOutputType = | GraphQLEnumType; export function isNamedType(type: unknown): type is GraphQLNamedType; export function assertNamedType(type: unknown): GraphQLNamedType; -export function getNamedType(type: undefined): undefined; +export function getNamedType(type: undefined | null): void; export function getNamedType(type: GraphQLInputType): GraphQLNamedInputType; export function getNamedType(type: GraphQLOutputType): GraphQLNamedOutputType; export function getNamedType(type: GraphQLType): GraphQLNamedType; @@ -216,8 +239,8 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; * Used while defining GraphQL types to allow for circular references in * otherwise immutable type definitions. */ -export type ThunkArray = Array | (() => Array); -export type ThunkObjMap = ObjMap | (() => ObjMap); +export type ThunkArray = (() => Array) | Array; +export type ThunkObjMap = (() => ObjMap) | ObjMap; /** * Custom extensions * @@ -237,12 +260,19 @@ export interface GraphQLScalarTypeExtensions { * Scalars (or Enums) and are defined with a name and a series of functions * used to parse input from ast or variables and to ensure validity. * + * If a type's serialize function does not return a value (i.e. it returns + * `undefined`) then an error will be raised and a `null` value will be returned + * in the response. If the serialize function returns `null`, then no error will + * be included in the response. + * * Example: * * const OddType = new GraphQLScalarType({ * name: 'Odd', * serialize(value) { - * return value % 2 === 1 ? value : null; + * if (value % 2 === 1) { + * return value; + * } * } * }); * @@ -258,23 +288,16 @@ export class GraphQLScalarType { astNode: Maybe; extensionASTNodes: ReadonlyArray; constructor(config: Readonly>); - toConfig(): GraphQLScalarTypeConfig & { - specifiedByURL: Maybe; - serialize: GraphQLScalarSerializer; - parseValue: GraphQLScalarValueParser; - parseLiteral: GraphQLScalarLiteralParser; - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLScalarTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; + get [Symbol.toStringTag](): string; } export type GraphQLScalarSerializer = ( - value: unknown, + outputValue: unknown, ) => Maybe; export type GraphQLScalarValueParser = ( - value: unknown, + inputValue: unknown, ) => Maybe; export type GraphQLScalarLiteralParser = ( valueNode: ValueNode, @@ -283,7 +306,7 @@ export type GraphQLScalarLiteralParser = ( export interface GraphQLScalarTypeConfig { name: string; description?: Maybe; - specifiedBy?: Maybe; + specifiedByURL?: Maybe; /** Serializes an internal value to include in a response. */ serialize?: GraphQLScalarSerializer; /** Parses an externally provided value to use as an input. */ @@ -294,6 +317,14 @@ export interface GraphQLScalarTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +interface GraphQLScalarTypeNormalizedConfig + extends GraphQLScalarTypeConfig { + serialize: GraphQLScalarSerializer; + parseValue: GraphQLScalarValueParser; + parseLiteral: GraphQLScalarLiteralParser; + extensions: Maybe>; + extensionASTNodes: ReadonlyArray; +} /** * Custom extensions * @@ -353,20 +384,22 @@ export class GraphQLObjectType { extensions: Maybe>>; astNode: Maybe; extensionASTNodes: ReadonlyArray; + private _fields; + private _interfaces; constructor(config: Readonly>); getFields(): GraphQLFieldMap; getInterfaces(): Array; - toConfig(): GraphQLObjectTypeConfig & { - interfaces: Array; - fields: GraphQLFieldConfigMap; - extensions: Maybe>>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLObjectTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } +export function defineArguments( + config: GraphQLFieldConfigArgumentMap, +): ReadonlyArray; +/** + * @internal + */ export function argsToArgsConfig( args: ReadonlyArray, ): GraphQLFieldConfigArgumentMap; @@ -380,6 +413,13 @@ export interface GraphQLObjectTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +interface GraphQLObjectTypeNormalizedConfig + extends GraphQLObjectTypeConfig { + interfaces: Array; + fields: GraphQLFieldConfigMap; + extensions: Maybe>>; + extensionASTNodes: ReadonlyArray; +} export type GraphQLTypeResolver = ( value: TSource, context: TContext, @@ -394,7 +434,9 @@ export type GraphQLIsTypeOfFn = ( export type GraphQLFieldResolver< TSource, TContext, - TArgs = { [argName: string]: any }, + TArgs = { + [argument: string]: any; + }, > = ( source: TSource, args: TArgs, @@ -411,7 +453,9 @@ export interface GraphQLResolveInfo { readonly fragments: ObjMap; readonly rootValue: unknown; readonly operation: OperationDefinitionNode; - readonly variableValues: { [variableName: string]: unknown }; + readonly variableValues: { + [variable: string]: unknown; + }; } /** * Custom extensions @@ -428,14 +472,18 @@ export interface GraphQLResolveInfo { export interface GraphQLFieldExtensions< _TSource, _TContext, - _TArgs = { [argName: string]: any }, + _TArgs = { + [argName: string]: any; + }, > { [attributeName: string]: unknown; } export interface GraphQLFieldConfig< TSource, TContext, - TArgs = { [argName: string]: any }, + TArgs = { + [argument: string]: any; + }, > { description?: Maybe; type: GraphQLOutputType; @@ -475,7 +523,9 @@ export type GraphQLFieldConfigMap = ObjMap< export interface GraphQLField< TSource, TContext, - TArgs = { [key: string]: any }, + TArgs = { + [argument: string]: any; + }, > { name: string; description: Maybe; @@ -485,7 +535,7 @@ export interface GraphQLField< subscribe?: GraphQLFieldResolver; deprecationReason: Maybe; extensions: Maybe>>; - astNode?: Maybe; + astNode: Maybe; } export interface GraphQLArgument { name: string; @@ -535,20 +585,16 @@ export class GraphQLInterfaceType { description: Maybe; resolveType: Maybe>; extensions: Maybe>; - astNode?: Maybe; + astNode: Maybe; extensionASTNodes: ReadonlyArray; + private _fields; + private _interfaces; constructor(config: Readonly>); getFields(): GraphQLFieldMap; getInterfaces(): Array; - toConfig(): GraphQLInterfaceTypeConfig & { - interfaces: Array; - fields: GraphQLFieldConfigMap; - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLInterfaceTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } export interface GraphQLInterfaceTypeConfig { @@ -566,6 +612,13 @@ export interface GraphQLInterfaceTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +export interface GraphQLInterfaceTypeNormalizedConfig + extends GraphQLInterfaceTypeConfig { + interfaces: Array; + fields: GraphQLFieldConfigMap; + extensions: Maybe>; + extensionASTNodes: ReadonlyArray; +} /** * Custom extensions * @@ -608,16 +661,12 @@ export class GraphQLUnionType { extensions: Maybe>; astNode: Maybe; extensionASTNodes: ReadonlyArray; + private _types; constructor(config: Readonly>); getTypes(): Array; - toConfig(): GraphQLUnionTypeConfig & { - types: Array; - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLUnionTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } export interface GraphQLUnionTypeConfig { @@ -634,6 +683,12 @@ export interface GraphQLUnionTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +interface GraphQLUnionTypeNormalizedConfig + extends GraphQLUnionTypeConfig { + types: Array; + extensions: Maybe>; + extensionASTNodes: ReadonlyArray; +} /** * Custom extensions * @@ -673,22 +728,21 @@ export class GraphQLEnumType { extensions: Maybe>; astNode: Maybe; extensionASTNodes: ReadonlyArray; + private _values; + private _valueLookup; + private _nameLookup; constructor(config: Readonly); getValues(): Array; getValue(name: string): Maybe; - serialize(value: unknown): Maybe; - parseValue(value: unknown): Maybe; + serialize(outputValue: unknown): Maybe; + parseValue(inputValue: unknown): Maybe; parseLiteral( valueNode: ValueNode, _variables: Maybe>, ): Maybe; - toConfig(): GraphQLEnumTypeConfig & { - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLEnumTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } export interface GraphQLEnumTypeConfig { @@ -699,6 +753,10 @@ export interface GraphQLEnumTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig { + extensions: Maybe>; + extensionASTNodes: ReadonlyArray; +} export type GraphQLEnumValueConfigMap = ObjMap; /** * Custom extensions @@ -725,7 +783,7 @@ export interface GraphQLEnumValue { value: any; deprecationReason: Maybe; extensions: Maybe>; - astNode?: Maybe; + astNode: Maybe; } /** * Custom extensions @@ -765,16 +823,12 @@ export class GraphQLInputObjectType { extensions: Maybe>; astNode: Maybe; extensionASTNodes: ReadonlyArray; + private _fields; constructor(config: Readonly); getFields(): GraphQLInputFieldMap; - toConfig(): GraphQLInputObjectTypeConfig & { - fields: GraphQLInputFieldConfigMap; - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - }; + toConfig(): GraphQLInputObjectTypeNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } export interface GraphQLInputObjectTypeConfig { @@ -785,6 +839,12 @@ export interface GraphQLInputObjectTypeConfig { astNode?: Maybe; extensionASTNodes?: Maybe>; } +interface GraphQLInputObjectTypeNormalizedConfig + extends GraphQLInputObjectTypeConfig { + fields: GraphQLInputFieldConfigMap; + extensions: Maybe>; + extensionASTNodes: ReadonlyArray; +} /** * Custom extensions * @@ -808,12 +868,12 @@ export interface GraphQLInputFieldConfig { export type GraphQLInputFieldConfigMap = ObjMap; export interface GraphQLInputField { name: string; - description?: Maybe; + description: Maybe; type: GraphQLInputType; - defaultValue?: unknown; + defaultValue: unknown; deprecationReason: Maybe; extensions: Maybe>; - astNode?: Maybe; + astNode: Maybe; } export function isRequiredInputField(field: GraphQLInputField): boolean; export type GraphQLInputFieldMap = ObjMap; diff --git a/src/type/directives.d.ts b/src/type/directives.d.ts index 301d39815c..576da63fbc 100644 --- a/src/type/directives.d.ts +++ b/src/type/directives.d.ts @@ -2,8 +2,8 @@ import type { Maybe } from '../jsutils/Maybe'; import type { DirectiveDefinitionNode } from '../language/ast'; import type { DirectiveLocationEnum } from '../language/directiveLocation'; import type { - GraphQLFieldConfigArgumentMap, GraphQLArgument, + GraphQLFieldConfigArgumentMap, } from './definition'; /** * Test if the given value is a GraphQL directive. @@ -30,19 +30,14 @@ export class GraphQLDirective { name: string; description: Maybe; locations: Array; + args: ReadonlyArray; isRepeatable: boolean; - args: Array; extensions: Maybe>; astNode: Maybe; constructor(config: Readonly); - toConfig(): GraphQLDirectiveConfig & { - args: GraphQLFieldConfigArgumentMap; - isRepeatable: boolean; - extensions: Maybe>; - }; + toConfig(): GraphQLDirectiveNormalizedConfig; toString(): string; toJSON(): string; - inspect(): string; get [Symbol.toStringTag](): string; } export interface GraphQLDirectiveConfig { @@ -54,6 +49,11 @@ export interface GraphQLDirectiveConfig { extensions?: Maybe>; astNode?: Maybe; } +interface GraphQLDirectiveNormalizedConfig extends GraphQLDirectiveConfig { + args: GraphQLFieldConfigArgumentMap; + isRepeatable: boolean; + extensions: Maybe>; +} /** * Used to conditionally include fields or fragments. */ @@ -62,18 +62,18 @@ export const GraphQLIncludeDirective: GraphQLDirective; * Used to conditionally skip (exclude) fields or fragments. */ export const GraphQLSkipDirective: GraphQLDirective; -/** - * Used to provide a URL for specifying the behavior of custom scalar definitions. - */ -export const GraphQLSpecifiedByDirective: GraphQLDirective; /** * Constant string used for default reason for a deprecation. */ -export const DEFAULT_DEPRECATION_REASON: 'No longer supported'; +export const DEFAULT_DEPRECATION_REASON = 'No longer supported'; /** * Used to declare element of a GraphQL schema as deprecated. */ export const GraphQLDeprecatedDirective: GraphQLDirective; +/** + * Used to provide a URL for specifying the behaviour of custom scalar definitions. + */ +export const GraphQLSpecifiedByDirective: GraphQLDirective; /** * The full list of specified directives. */ diff --git a/src/type/index.d.ts b/src/type/index.d.ts index 65f7b7ef33..bc104e6872 100644 --- a/src/type/index.d.ts +++ b/src/type/index.d.ts @@ -1,4 +1,4 @@ -export { Path as ResponsePath } from '../jsutils/Path'; +export type { Path as ResponsePath } from '../jsutils/Path'; export { /** Predicate */ isSchema, @@ -6,9 +6,8 @@ export { assertSchema, /** GraphQL Schema definition */ GraphQLSchema, - GraphQLSchemaConfig, - GraphQLSchemaExtensions, } from './schema'; +export type { GraphQLSchemaConfig, GraphQLSchemaExtensions } from './schema'; export { /** Predicates */ isType, @@ -61,7 +60,8 @@ export { /** Type Wrappers */ GraphQLList, GraphQLNonNull, - /** type */ +} from './definition'; +export type { GraphQLType, GraphQLInputType, GraphQLOutputType, @@ -129,13 +129,16 @@ export { GraphQLSpecifiedByDirective, /** Constant Deprecation Reason */ DEFAULT_DEPRECATION_REASON, - /** type */ +} from './directives'; +export type { GraphQLDirectiveConfig, GraphQLDirectiveExtensions, } from './directives'; /** Common built-in scalar instances. */ export { + /** Predicate */ isSpecifiedScalarType, + /** Standard GraphQL Scalars */ specifiedScalarTypes, GraphQLInt, GraphQLFloat, @@ -144,10 +147,9 @@ export { GraphQLID, } from './scalars'; export { - /** "Enum" of Type Kinds */ - TypeKind, - /** GraphQL Types for introspection. */ + /** Predicate */ isIntrospectionType, + /** GraphQL Types for introspection. */ introspectionTypes, __Schema, __Directive, @@ -162,4 +164,9 @@ export { TypeMetaFieldDef, TypeNameMetaFieldDef, } from './introspection'; +export type { + /** "Enum" of Type Kinds */ + TypeKind, +} from './introspection'; +/** Validate GraphQL schema. */ export { validateSchema, assertValidSchema } from './validate'; diff --git a/src/type/introspection.d.ts b/src/type/introspection.d.ts index bbc4945074..eb4a6a05e3 100644 --- a/src/type/introspection.d.ts +++ b/src/type/introspection.d.ts @@ -1,9 +1,5 @@ -import type { - GraphQLObjectType, - GraphQLField, - GraphQLEnumType, - GraphQLNamedType, -} from './definition'; +import type { GraphQLNamedType, GraphQLField } from './definition'; +import { GraphQLObjectType, GraphQLEnumType } from './definition'; export const __Schema: GraphQLObjectType; export const __Directive: GraphQLObjectType; export const __DirectiveLocation: GraphQLEnumType; @@ -12,14 +8,14 @@ export const __Field: GraphQLObjectType; export const __InputValue: GraphQLObjectType; export const __EnumValue: GraphQLObjectType; export const TypeKind: Readonly<{ - SCALAR: 'SCALAR'; - OBJECT: 'OBJECT'; - INTERFACE: 'INTERFACE'; - UNION: 'UNION'; - ENUM: 'ENUM'; - INPUT_OBJECT: 'INPUT_OBJECT'; - LIST: 'LIST'; - NON_NULL: 'NON_NULL'; + readonly SCALAR: 'SCALAR'; + readonly OBJECT: 'OBJECT'; + readonly INTERFACE: 'INTERFACE'; + readonly UNION: 'UNION'; + readonly ENUM: 'ENUM'; + readonly INPUT_OBJECT: 'INPUT_OBJECT'; + readonly LIST: 'LIST'; + readonly NON_NULL: 'NON_NULL'; }>; export const __TypeKind: GraphQLEnumType; /** diff --git a/src/type/scalars.d.ts b/src/type/scalars.d.ts index 18407370ae..6a33adb8b9 100644 --- a/src/type/scalars.d.ts +++ b/src/type/scalars.d.ts @@ -1,4 +1,5 @@ -import type { GraphQLScalarType, GraphQLNamedType } from './definition'; +import type { GraphQLNamedType } from './definition'; +import { GraphQLScalarType } from './definition'; export const GraphQLInt: GraphQLScalarType; export const GraphQLFloat: GraphQLScalarType; export const GraphQLString: GraphQLScalarType; diff --git a/src/type/schema.d.ts b/src/type/schema.d.ts index e3b2cc309f..b6b99d9e25 100644 --- a/src/type/schema.d.ts +++ b/src/type/schema.d.ts @@ -1,16 +1,17 @@ -import type { Maybe } from '../jsutils/Maybe'; import type { ObjMap } from '../jsutils/ObjMap'; +import type { Maybe } from '../jsutils/Maybe'; +import type { GraphQLError } from '../error/GraphQLError'; import type { SchemaDefinitionNode, SchemaExtensionNode, } from '../language/ast'; -import type { GraphQLDirective } from './directives'; import type { GraphQLNamedType, GraphQLAbstractType, GraphQLObjectType, GraphQLInterfaceType, } from './definition'; +import type { GraphQLDirective } from './directives'; /** * Test if the given value is a GraphQL schema. */ @@ -42,6 +43,43 @@ export interface GraphQLSchemaExtensions { * mutation: MyAppMutationRootType, * }) * + * Note: When the schema is constructed, by default only the types that are + * reachable by traversing the root types are included, other types must be + * explicitly referenced. + * + * Example: + * + * const characterInterface = new GraphQLInterfaceType({ + * name: 'Character', + * ... + * }); + * + * const humanType = new GraphQLObjectType({ + * name: 'Human', + * interfaces: [characterInterface], + * ... + * }); + * + * const droidType = new GraphQLObjectType({ + * name: 'Droid', + * interfaces: [characterInterface], + * ... + * }); + * + * const schema = new GraphQLSchema({ + * query: new GraphQLObjectType({ + * name: 'Query', + * fields: { + * hero: { type: characterInterface, ... }, + * } + * }), + * ... + * // Since this schema references only the `Character` interface it's + * // necessary to explicitly list the types that implement it if + * // you want them to be included in the final schema. + * types: [humanType, droidType], + * }) + * * Note: If an array of `directives` are provided to GraphQLSchema, that will be * the exact list of directives represented and allowed. If `directives` is not * provided then a default set of the specified directives (e.g. @include and @@ -59,6 +97,14 @@ export class GraphQLSchema { extensions: Maybe>; astNode: Maybe; extensionASTNodes: ReadonlyArray; + __validationErrors: Maybe>; + private _queryType; + private _mutationType; + private _subscriptionType; + private _directives; + private _typeMap; + private _subTypeMap; + private _implementationsMap; constructor(config: Readonly); getQueryType(): Maybe; getMutationType(): Maybe; @@ -68,29 +114,20 @@ export class GraphQLSchema { getPossibleTypes( abstractType: GraphQLAbstractType, ): ReadonlyArray; - getImplementations( - interfaceType: GraphQLInterfaceType, - ): InterfaceImplementations; + getImplementations(interfaceType: GraphQLInterfaceType): { + objects: Array; + interfaces: Array; + }; isSubType( abstractType: GraphQLAbstractType, maybeSubType: GraphQLObjectType | GraphQLInterfaceType, ): boolean; getDirectives(): ReadonlyArray; getDirective(name: string): Maybe; - toConfig(): GraphQLSchemaConfig & { - types: Array; - directives: Array; - extensions: Maybe>; - extensionASTNodes: ReadonlyArray; - assumeValid: boolean; - }; + toConfig(): GraphQLSchemaNormalizedConfig; get [Symbol.toStringTag](): string; } type TypeMap = ObjMap; -interface InterfaceImplementations { - objects: ReadonlyArray; - interfaces: ReadonlyArray; -} export interface GraphQLSchemaValidationOptions { /** * When building a schema from a GraphQL service's introspection result, it diff --git a/src/type/validate.d.ts b/src/type/validate.d.ts index 7ba58f90bb..b07bc0c11a 100644 --- a/src/type/validate.d.ts +++ b/src/type/validate.d.ts @@ -1,4 +1,4 @@ -import type { GraphQLError } from '../error/GraphQLError'; +import { GraphQLError } from '../error/GraphQLError'; import type { GraphQLSchema } from './schema'; /** * Implements the "Type Validation" sub-sections of the specification's diff --git a/src/utilities/TypeInfo.d.ts b/src/utilities/TypeInfo.d.ts index 3f6fda00fa..fa1d01944a 100644 --- a/src/utilities/TypeInfo.d.ts +++ b/src/utilities/TypeInfo.d.ts @@ -1,6 +1,6 @@ -import type { Maybe } from '../jsutils/Maybe'; import type { ASTVisitor } from '../language/visitor'; import type { ASTNode, FieldNode } from '../language/ast'; +import type { Maybe } from '../jsutils/Maybe'; import type { GraphQLSchema } from '../type/schema'; import type { GraphQLDirective } from '../type/directives'; import type { @@ -18,13 +18,23 @@ import type { * AST during a recursive descent by calling `enter(node)` and `leave(node)`. */ export class TypeInfo { + private _schema; + private _typeStack; + private _parentTypeStack; + private _inputTypeStack; + private _fieldDefStack; + private _defaultValueStack; + private _directive; + private _argument; + private _enumValue; + private _getFieldDef; constructor( schema: GraphQLSchema, /** * Initial type may be provided in rare cases to facilitate traversals * beginning somewhere other than documents. */ - initialType?: GraphQLType, + initialType?: Maybe, /** @deprecated will be removed in 17.0.0 */ getFieldDefFn?: GetFieldDefFn, ); @@ -37,8 +47,8 @@ export class TypeInfo { getDirective(): Maybe; getArgument(): Maybe; getEnumValue(): Maybe; - enter(node: ASTNode): any; - leave(node: ASTNode): any; + enter(node: ASTNode): void; + leave(node: ASTNode): void; } type GetFieldDefFn = ( schema: GraphQLSchema, diff --git a/src/utilities/assertValidName.d.ts b/src/utilities/assertValidName.d.ts index 9824149561..9abf64cadd 100644 --- a/src/utilities/assertValidName.d.ts +++ b/src/utilities/assertValidName.d.ts @@ -1,4 +1,4 @@ -import type { GraphQLError } from '../error/GraphQLError'; +import { GraphQLError } from '../error/GraphQLError'; /** * Upholds the spec rules about naming. */ diff --git a/src/utilities/astFromValue.d.ts b/src/utilities/astFromValue.d.ts index ad79ac697f..390ecdf571 100644 --- a/src/utilities/astFromValue.d.ts +++ b/src/utilities/astFromValue.d.ts @@ -2,7 +2,11 @@ import type { Maybe } from '../jsutils/Maybe'; import type { ValueNode } from '../language/ast'; import type { GraphQLInputType } from '../type/definition'; /** - * Produces a GraphQL Value AST given a JavaScript value. + * Produces a GraphQL Value AST given a JavaScript object. + * Function will match JavaScript/JSON values to GraphQL AST schema format + * by using suggested GraphQLInputType. For example: + * + * astFromValue("value", GraphQLString) * * A GraphQL type must be provided, which will be used to interpret different * JavaScript values. diff --git a/src/utilities/buildASTSchema.d.ts b/src/utilities/buildASTSchema.d.ts index ea70b785d1..fe36c9dc94 100644 --- a/src/utilities/buildASTSchema.d.ts +++ b/src/utilities/buildASTSchema.d.ts @@ -1,10 +1,8 @@ -import type { DocumentNode } from '../language/ast'; import type { Source } from '../language/source'; -import type { - GraphQLSchema, - GraphQLSchemaValidationOptions, -} from '../type/schema'; +import type { DocumentNode } from '../language/ast'; import type { ParseOptions } from '../language/parser'; +import type { GraphQLSchemaValidationOptions } from '../type/schema'; +import { GraphQLSchema } from '../type/schema'; export interface BuildSchemaOptions extends GraphQLSchemaValidationOptions { /** * Set to true to assume the SDL is valid. diff --git a/src/utilities/buildClientSchema.d.ts b/src/utilities/buildClientSchema.d.ts index d2e30cd9f7..2cb46834b4 100644 --- a/src/utilities/buildClientSchema.d.ts +++ b/src/utilities/buildClientSchema.d.ts @@ -1,7 +1,5 @@ -import type { - GraphQLSchema, - GraphQLSchemaValidationOptions, -} from '../type/schema'; +import type { GraphQLSchemaValidationOptions } from '../type/schema'; +import { GraphQLSchema } from '../type/schema'; import type { IntrospectionQuery } from './getIntrospectionQuery'; /** * Build a GraphQLSchema for use by client tools. diff --git a/src/utilities/coerceInputValue.d.ts b/src/utilities/coerceInputValue.d.ts index 3307a9be92..54ed99bc97 100644 --- a/src/utilities/coerceInputValue.d.ts +++ b/src/utilities/coerceInputValue.d.ts @@ -1,5 +1,5 @@ +import { GraphQLError } from '../error/GraphQLError'; import type { GraphQLInputType } from '../type/definition'; -import type { GraphQLError } from '../error/GraphQLError'; type OnErrorCB = ( path: ReadonlyArray, invalidValue: unknown, diff --git a/src/utilities/concatAST.d.ts b/src/utilities/concatAST.d.ts index 2a6a853d7b..d289766f1d 100644 --- a/src/utilities/concatAST.d.ts +++ b/src/utilities/concatAST.d.ts @@ -4,4 +4,4 @@ import type { DocumentNode } from '../language/ast'; * concatenate the ASTs together into batched AST, useful for validating many * GraphQL source files which together represent one conceptual application. */ -export function concatAST(asts: ReadonlyArray): DocumentNode; +export function concatAST(documents: ReadonlyArray): DocumentNode; diff --git a/src/utilities/extendSchema.d.ts b/src/utilities/extendSchema.d.ts index 102dcef496..2a6cec7f49 100644 --- a/src/utilities/extendSchema.d.ts +++ b/src/utilities/extendSchema.d.ts @@ -1,9 +1,9 @@ import type { DocumentNode } from '../language/ast'; import type { GraphQLSchemaValidationOptions, - GraphQLSchema, GraphQLSchemaNormalizedConfig, } from '../type/schema'; +import { GraphQLSchema } from '../type/schema'; interface Options extends GraphQLSchemaValidationOptions { /** * Set to true to assume the SDL is valid. diff --git a/src/utilities/findBreakingChanges.d.ts b/src/utilities/findBreakingChanges.d.ts index aac9ecea04..8149251bb9 100644 --- a/src/utilities/findBreakingChanges.d.ts +++ b/src/utilities/findBreakingChanges.d.ts @@ -1,30 +1,30 @@ import type { GraphQLSchema } from '../type/schema'; -export const BreakingChangeType: { - 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'; - REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED'; - IMPLEMENTED_INTERFACE_REMOVED: 'IMPLEMENTED_INTERFACE_REMOVED'; - 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'; - REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED'; - DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED'; - DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'; -}; -export const DangerousChangeType: { - VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM'; - TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION'; - OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED'; - OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED'; - IMPLEMENTED_INTERFACE_ADDED: 'IMPLEMENTED_INTERFACE_ADDED'; - ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'; -}; +export const BreakingChangeType: Readonly<{ + readonly TYPE_REMOVED: 'TYPE_REMOVED'; + readonly TYPE_CHANGED_KIND: 'TYPE_CHANGED_KIND'; + readonly TYPE_REMOVED_FROM_UNION: 'TYPE_REMOVED_FROM_UNION'; + readonly VALUE_REMOVED_FROM_ENUM: 'VALUE_REMOVED_FROM_ENUM'; + readonly REQUIRED_INPUT_FIELD_ADDED: 'REQUIRED_INPUT_FIELD_ADDED'; + readonly IMPLEMENTED_INTERFACE_REMOVED: 'IMPLEMENTED_INTERFACE_REMOVED'; + readonly FIELD_REMOVED: 'FIELD_REMOVED'; + readonly FIELD_CHANGED_KIND: 'FIELD_CHANGED_KIND'; + readonly REQUIRED_ARG_ADDED: 'REQUIRED_ARG_ADDED'; + readonly ARG_REMOVED: 'ARG_REMOVED'; + readonly ARG_CHANGED_KIND: 'ARG_CHANGED_KIND'; + readonly DIRECTIVE_REMOVED: 'DIRECTIVE_REMOVED'; + readonly DIRECTIVE_ARG_REMOVED: 'DIRECTIVE_ARG_REMOVED'; + readonly REQUIRED_DIRECTIVE_ARG_ADDED: 'REQUIRED_DIRECTIVE_ARG_ADDED'; + readonly DIRECTIVE_REPEATABLE_REMOVED: 'DIRECTIVE_REPEATABLE_REMOVED'; + readonly DIRECTIVE_LOCATION_REMOVED: 'DIRECTIVE_LOCATION_REMOVED'; +}>; +export const DangerousChangeType: Readonly<{ + readonly VALUE_ADDED_TO_ENUM: 'VALUE_ADDED_TO_ENUM'; + readonly TYPE_ADDED_TO_UNION: 'TYPE_ADDED_TO_UNION'; + readonly OPTIONAL_INPUT_FIELD_ADDED: 'OPTIONAL_INPUT_FIELD_ADDED'; + readonly OPTIONAL_ARG_ADDED: 'OPTIONAL_ARG_ADDED'; + readonly IMPLEMENTED_INTERFACE_ADDED: 'IMPLEMENTED_INTERFACE_ADDED'; + readonly ARG_DEFAULT_VALUE_CHANGE: 'ARG_DEFAULT_VALUE_CHANGE'; +}>; export interface BreakingChange { type: keyof typeof BreakingChangeType; description: string; diff --git a/src/utilities/index.d.ts b/src/utilities/index.d.ts index 44b34b25b1..f2d9ebe28b 100644 --- a/src/utilities/index.d.ts +++ b/src/utilities/index.d.ts @@ -1,9 +1,9 @@ -export { - /** - * Produce the GraphQL query recommended for a full schema introspection. - * Accepts optional IntrospectionOptions. - */ - getIntrospectionQuery, +/** + * Produce the GraphQL query recommended for a full schema introspection. + * Accepts optional IntrospectionOptions. + */ +export { getIntrospectionQuery } from './getIntrospectionQuery'; +export type { IntrospectionOptions, IntrospectionQuery, IntrospectionSchema, @@ -27,20 +27,17 @@ export { IntrospectionEnumValue, IntrospectionDirective, } from './getIntrospectionQuery'; -/** Gets the target Operation from a Document */ +/** Gets the target Operation from a Document. */ export { getOperationAST } from './getOperationAST'; /** Gets the Type for the target Operation AST. */ export { getOperationRootType } from './getOperationRootType'; -/** Convert a GraphQLSchema to an IntrospectionQuery */ +/** Convert a GraphQLSchema to an IntrospectionQuery. */ export { introspectionFromSchema } from './introspectionFromSchema'; /** Build a GraphQLSchema from an introspection result. */ export { buildClientSchema } from './buildClientSchema'; /** Build a GraphQLSchema from GraphQL Schema language. */ -export { - buildASTSchema, - buildSchema, - BuildSchemaOptions, -} from './buildASTSchema'; +export { buildASTSchema, buildSchema } from './buildASTSchema'; +export type { BuildSchemaOptions } from './buildASTSchema'; /** Extends an existing GraphQLSchema from a parsed GraphQL Schema language AST. */ export { extendSchema } from './extendSchema'; /** Sort a GraphQLSchema. */ @@ -59,8 +56,7 @@ export { valueFromAST } from './valueFromAST'; export { valueFromASTUntyped } from './valueFromASTUntyped'; /** Create a GraphQL language AST from a JavaScript value. */ export { astFromValue } from './astFromValue'; -/** A helper to use within recursive-descent visitors which need to be aware of */ -/** the GraphQL type system. */ +/** A helper to use within recursive-descent visitors which need to be aware of the GraphQL type system. */ export { TypeInfo, visitWithTypeInfo } from './TypeInfo'; /** Coerces a JavaScript value to a GraphQL type, or produces errors. */ export { coerceInputValue } from './coerceInputValue'; @@ -84,8 +80,7 @@ export { DangerousChangeType, findBreakingChanges, findDangerousChanges, - BreakingChange, - DangerousChange, } from './findBreakingChanges'; +export type { BreakingChange, DangerousChange } from './findBreakingChanges'; /** Wrapper type that contains DocumentNode and types that can be deduced from it. */ export { TypedQueryDocumentNode } from './typedQueryDocumentNode'; diff --git a/src/utilities/lexicographicSortSchema.d.ts b/src/utilities/lexicographicSortSchema.d.ts index d72d3945e2..45d749d5d2 100644 --- a/src/utilities/lexicographicSortSchema.d.ts +++ b/src/utilities/lexicographicSortSchema.d.ts @@ -1,4 +1,4 @@ -import type { GraphQLSchema } from '../type/schema'; +import { GraphQLSchema } from '../type/schema'; /** * Sort GraphQLSchema. * diff --git a/src/utilities/stripIgnoredCharacters.d.ts b/src/utilities/stripIgnoredCharacters.d.ts index 11375e01c9..3ea3397f8f 100644 --- a/src/utilities/stripIgnoredCharacters.d.ts +++ b/src/utilities/stripIgnoredCharacters.d.ts @@ -1,4 +1,4 @@ -import type { Source } from '../language/source'; +import { Source } from '../language/source'; /** * Strips characters that are not significant to the validity or execution * of a GraphQL document: diff --git a/src/utilities/typeFromAST.d.ts b/src/utilities/typeFromAST.d.ts index ec9d8296bf..cbd45d429c 100644 --- a/src/utilities/typeFromAST.d.ts +++ b/src/utilities/typeFromAST.d.ts @@ -1,14 +1,12 @@ import type { + TypeNode, NamedTypeNode, ListTypeNode, NonNullTypeNode, } from '../language/ast'; import type { GraphQLSchema } from '../type/schema'; -import type { - GraphQLNamedType, - GraphQLList, - GraphQLNonNull, -} from '../type/definition'; +import type { GraphQLType, GraphQLNamedType } from '../type/definition'; +import { GraphQLList, GraphQLNonNull } from '../type/definition'; /** * Given a Schema and an AST node describing a type, return a GraphQLType * definition which applies to that type. For example, if provided the parsed @@ -28,3 +26,7 @@ export function typeFromAST( schema: GraphQLSchema, typeNode: NonNullTypeNode, ): GraphQLNonNull | undefined; +export function typeFromAST( + schema: GraphQLSchema, + typeNode: TypeNode, +): GraphQLType | undefined; diff --git a/src/utilities/valueFromAST.d.ts b/src/utilities/valueFromAST.d.ts index 6910d48bd8..084f98c1ac 100644 --- a/src/utilities/valueFromAST.d.ts +++ b/src/utilities/valueFromAST.d.ts @@ -1,7 +1,7 @@ -import type { Maybe } from '../jsutils/Maybe'; import type { ObjMap } from '../jsutils/ObjMap'; import type { ValueNode } from '../language/ast'; import type { GraphQLInputType } from '../type/definition'; +import type { Maybe } from '../jsutils/Maybe'; /** * Produces a JavaScript value given a GraphQL Value AST. * diff --git a/src/utilities/valueFromASTUntyped.d.ts b/src/utilities/valueFromASTUntyped.d.ts index 6e2d52e519..e21fe785cb 100644 --- a/src/utilities/valueFromASTUntyped.d.ts +++ b/src/utilities/valueFromASTUntyped.d.ts @@ -1,5 +1,5 @@ -import type { Maybe } from '../jsutils/Maybe'; import type { ObjMap } from '../jsutils/ObjMap'; +import type { Maybe } from '../jsutils/Maybe'; import type { ValueNode } from '../language/ast'; /** * Produces a JavaScript value given a GraphQL Value AST. diff --git a/src/validation/ValidationContext.d.ts b/src/validation/ValidationContext.d.ts index 9e13981360..ce14c494e9 100644 --- a/src/validation/ValidationContext.d.ts +++ b/src/validation/ValidationContext.d.ts @@ -19,7 +19,7 @@ import type { GraphQLArgument, GraphQLEnumValue, } from '../type/definition'; -import type { TypeInfo } from '../utilities/TypeInfo'; +import { TypeInfo } from '../utilities/TypeInfo'; type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode; interface VariableUsage { readonly node: VariableNode; @@ -32,8 +32,13 @@ interface VariableUsage { * validation rule. */ export class ASTValidationContext { + private _ast; + private _onError; + private _fragments; + private _fragmentSpreads; + private _recursivelyReferencedFragments; constructor(ast: DocumentNode, onError: (error: GraphQLError) => void); - reportError(error: GraphQLError): undefined; + reportError(error: GraphQLError): void; getDocument(): DocumentNode; getFragment(name: string): Maybe; getFragmentSpreads(node: SelectionSetNode): ReadonlyArray; @@ -41,7 +46,9 @@ export class ASTValidationContext { operation: OperationDefinitionNode, ): ReadonlyArray; } +export type ASTValidationRule = (context: ASTValidationContext) => ASTVisitor; export class SDLValidationContext extends ASTValidationContext { + private _schema; constructor( ast: DocumentNode, schema: Maybe, @@ -51,6 +58,10 @@ export class SDLValidationContext extends ASTValidationContext { } export type SDLValidationRule = (context: SDLValidationContext) => ASTVisitor; export class ValidationContext extends ASTValidationContext { + private _schema; + private _typeInfo; + private _variableUsages; + private _recursiveVariableUsages; constructor( schema: GraphQLSchema, ast: DocumentNode, @@ -59,9 +70,9 @@ export class ValidationContext extends ASTValidationContext { ); getSchema(): GraphQLSchema; getVariableUsages(node: NodeWithSelectionSet): ReadonlyArray; - getRecursivelyReferencedFragments( + getRecursiveVariableUsages( operation: OperationDefinitionNode, - ): ReadonlyArray; + ): ReadonlyArray; getType(): Maybe; getParentType(): Maybe; getInputType(): Maybe; diff --git a/src/validation/index.d.ts b/src/validation/index.d.ts index 9eb70091a3..f06ebaeadf 100644 --- a/src/validation/index.d.ts +++ b/src/validation/index.d.ts @@ -1,5 +1,7 @@ export { validate } from './validate'; -export { ValidationContext, ValidationRule } from './ValidationContext'; +export { ValidationContext } from './ValidationContext'; +export type { ValidationRule } from './ValidationContext'; +/** All validation rules in the GraphQL Specification. */ export { specifiedRules } from './specifiedRules'; /** Spec Section: "Executable Definitions" */ export { ExecutableDefinitionsRule } from './rules/ExecutableDefinitionsRule'; diff --git a/src/validation/rules/KnownArgumentNamesRule.d.ts b/src/validation/rules/KnownArgumentNamesRule.d.ts index 0f1c442252..97e98376a8 100644 --- a/src/validation/rules/KnownArgumentNamesRule.d.ts +++ b/src/validation/rules/KnownArgumentNamesRule.d.ts @@ -1,8 +1,8 @@ +import type { ASTVisitor } from '../../language/visitor'; import type { ValidationContext, SDLValidationContext, } from '../ValidationContext'; -import type { ASTVisitor } from '../../language/visitor'; /** * Known argument names * diff --git a/src/validation/rules/NoFragmentCyclesRule.d.ts b/src/validation/rules/NoFragmentCyclesRule.d.ts index bb1b78d0da..de3c3bedb1 100644 --- a/src/validation/rules/NoFragmentCyclesRule.d.ts +++ b/src/validation/rules/NoFragmentCyclesRule.d.ts @@ -1,3 +1,3 @@ import type { ASTVisitor } from '../../language/visitor'; -import type { ValidationContext } from '../ValidationContext'; -export function NoFragmentCyclesRule(context: ValidationContext): ASTVisitor; +import type { ASTValidationContext } from '../ValidationContext'; +export function NoFragmentCyclesRule(context: ASTValidationContext): ASTVisitor; diff --git a/src/validation/rules/NoUnusedFragmentsRule.d.ts b/src/validation/rules/NoUnusedFragmentsRule.d.ts index 25daa273bc..dc24956092 100644 --- a/src/validation/rules/NoUnusedFragmentsRule.d.ts +++ b/src/validation/rules/NoUnusedFragmentsRule.d.ts @@ -1,9 +1,11 @@ import type { ASTVisitor } from '../../language/visitor'; -import type { ValidationContext } from '../ValidationContext'; +import type { ASTValidationContext } from '../ValidationContext'; /** * No unused fragments * * A GraphQL document is only valid if all fragment definitions are spread * within operations, or spread within other fragments spread within operations. */ -export function NoUnusedFragmentsRule(context: ValidationContext): ASTVisitor; +export function NoUnusedFragmentsRule( + context: ASTValidationContext, +): ASTVisitor; diff --git a/src/validation/rules/UniqueDirectivesPerLocationRule.d.ts b/src/validation/rules/UniqueDirectivesPerLocationRule.d.ts index 777262d322..fd3f0787d7 100644 --- a/src/validation/rules/UniqueDirectivesPerLocationRule.d.ts +++ b/src/validation/rules/UniqueDirectivesPerLocationRule.d.ts @@ -1,11 +1,14 @@ import type { ASTVisitor } from '../../language/visitor'; -import type { ASTValidationContext } from '../ValidationContext'; +import type { + SDLValidationContext, + ValidationContext, +} from '../ValidationContext'; /** * Unique directive names per location * - * A GraphQL document is only valid if all directives at a given location - * are uniquely named. + * A GraphQL document is only valid if all non-repeatable directives at + * a given location are uniquely named. */ export function UniqueDirectivesPerLocationRule( - context: ASTValidationContext, + context: ValidationContext | SDLValidationContext, ): ASTVisitor; diff --git a/src/validation/validate.d.ts b/src/validation/validate.d.ts index 427d4ea7b5..732f40750f 100644 --- a/src/validation/validate.d.ts +++ b/src/validation/validate.d.ts @@ -1,9 +1,9 @@ import type { Maybe } from '../jsutils/Maybe'; -import type { GraphQLError } from '../error/GraphQLError'; +import { GraphQLError } from '../error/GraphQLError'; import type { DocumentNode } from '../language/ast'; import type { GraphQLSchema } from '../type/schema'; -import type { TypeInfo } from '../utilities/TypeInfo'; -import type { ValidationRule, SDLValidationRule } from './ValidationContext'; +import { TypeInfo } from '../utilities/TypeInfo'; +import type { SDLValidationRule, ValidationRule } from './ValidationContext'; /** * Implements the "Validation" section of the spec. * @@ -24,7 +24,9 @@ export function validate( schema: GraphQLSchema, documentAST: DocumentNode, rules?: ReadonlyArray, - options?: { maxErrors?: number }, + options?: { + maxErrors?: number; + }, /** @deprecate will be removed in 17.0.0 */ typeInfo?: TypeInfo, ): ReadonlyArray; @@ -35,7 +37,7 @@ export function validateSDL( documentAST: DocumentNode, schemaToExtend?: Maybe, rules?: ReadonlyArray, -): Readonly; +): ReadonlyArray; /** * Utility function which asserts a SDL document is valid by throwing an error * if it is invalid. diff --git a/src/version.d.ts b/src/version.d.ts index 3a87a02393..675618f252 100644 --- a/src/version.d.ts +++ b/src/version.d.ts @@ -5,9 +5,9 @@ export const version: string; /** * An object containing the components of the GraphQL.js version string */ -export const versionInfo: { +export const versionInfo: Readonly<{ major: number; minor: number; patch: number; - preReleaseTag: number | null; -}; + preReleaseTag: string | null; +}>;