Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Synchronise *.d.ts with sources converted to TS #3132

Merged
merged 1 commit into from May 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/error/GraphQLError.d.ts
Expand Up @@ -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<ReadonlyArray<ASTNode> | ASTNode>,
source?: Maybe<Source>,
positions?: Maybe<ReadonlyArray<number>>,
path?: Maybe<ReadonlyArray<string | number>>,
originalError?: Maybe<Error>,
extensions?: Maybe<{ [key: string]: unknown }>,
);
/**
* A message describing the Error for debugging purposes.
*
Expand All @@ -36,38 +27,57 @@ export class GraphQLError extends Error {
*
* Enumerable, and appears in the result of JSON.stringify().
*/
readonly locations: ReadonlyArray<SourceLocation> | undefined;
readonly locations?: ReadonlyArray<SourceLocation>;
/**
* 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<string | number> | undefined;
readonly path?: ReadonlyArray<string | number>;
/**
* An array of GraphQL AST Nodes corresponding to this error.
*/
readonly nodes: ReadonlyArray<ASTNode> | undefined;
readonly nodes?: ReadonlyArray<ASTNode>;
/**
* 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<number> | undefined;
readonly positions?: ReadonlyArray<number>;
/**
* The original error thrown from a field resolver during execution.
*/
readonly originalError: Maybe<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> | ASTNode | null,
source?: Maybe<Source>,
positions?: Maybe<ReadonlyArray<number>>,
path?: Maybe<ReadonlyArray<string | number>>,
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
Expand Down
4 changes: 3 additions & 1 deletion src/error/formatError.d.ts
Expand Up @@ -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;
};
}
3 changes: 2 additions & 1 deletion 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';
4 changes: 2 additions & 2 deletions src/error/locatedError.d.ts
@@ -1,13 +1,13 @@
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
* document responsible for the original Error.
*/
export function locatedError(
rawOriginalError: unknown,
nodes: ASTNode | ReadonlyArray<ASTNode> | undefined,
nodes: ASTNode | ReadonlyArray<ASTNode> | undefined | null,
path?: Maybe<ReadonlyArray<string | number>>,
): GraphQLError;
2 changes: 1 addition & 1 deletion 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.
Expand Down
44 changes: 25 additions & 19 deletions 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,
Expand All @@ -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
Expand Down Expand Up @@ -46,11 +46,13 @@ import type {
*/
export interface ExecutionContext {
schema: GraphQLSchema;
fragments: ObjMap<FragmentDefinitionNode>;
rootValue: unknown;
contextValue: unknown;
fragments: ObjMap<FragmentDefinitionNode>;
operation: OperationDefinitionNode;
variableValues: { [key: string]: unknown };
variableValues: {
[variable: string]: unknown;
};
fieldResolver: GraphQLFieldResolver<any, any>;
typeResolver: GraphQLTypeResolver<any, any>;
errors: Array<GraphQLError>;
Expand All @@ -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<unknown>,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLError>;
// 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<unknown>,
TExtensions = ObjMap<unknown>,
> {
errors?: ReadonlyArray<GraphQLFormattedError>;
// TS_SPECIFIC: TData. Motivation: https://github.com/graphql/graphql-js/pull/2490#issuecomment-639154229
data?: TData | null;
extensions?: TExtensions;
}
Expand All @@ -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<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
Expand Down Expand Up @@ -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
Expand All @@ -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<string>,
fieldResolver: Maybe<GraphQLFieldResolver<unknown, unknown>>,
typeResolver?: Maybe<GraphQLTypeResolver<unknown, unknown>>,
Expand All @@ -150,9 +156,9 @@ export function collectFields(
exeContext: ExecutionContext,
runtimeType: GraphQLObjectType,
selectionSet: SelectionSetNode,
fields: ObjMap<Array<FieldNode>>,
visitedFragmentNames: ObjMap<boolean>,
): ObjMap<Array<FieldNode>>;
fields: Map<string, Array<FieldNode>>,
visitedFragmentNames: Set<string>,
): Map<string, Array<FieldNode>>;
/**
* @internal
*/
Expand Down Expand Up @@ -195,5 +201,5 @@ export const defaultFieldResolver: GraphQLFieldResolver<unknown, unknown>;
export function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLObjectType,
fieldName: string,
fieldNode: FieldNode,
): Maybe<GraphQLField<unknown, unknown>>;
2 changes: 2 additions & 0 deletions src/execution/index.d.ts
Expand Up @@ -4,6 +4,8 @@ export {
executeSync,
defaultFieldResolver,
defaultTypeResolver,
} from './execute';
export type {
ExecutionArgs,
ExecutionResult,
FormattedExecutionResult,
Expand Down
40 changes: 31 additions & 9 deletions 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<GraphQLError>; coerced?: never }
| { errors?: never; coerced: { [key: string]: unknown } };
| {
errors: ReadonlyArray<GraphQLError>;
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
Expand All @@ -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<VariableDefinitionNode>,
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
Expand All @@ -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<unknown, unknown> | GraphQLDirective,
node: FieldNode | DirectiveNode,
variableValues?: Maybe<ObjMap<unknown>>,
): { [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
Expand All @@ -57,4 +75,8 @@ export function getDirectiveValues(
readonly directives?: ReadonlyArray<DirectiveNode>;
},
variableValues?: Maybe<ObjMap<unknown>>,
): undefined | { [key: string]: unknown };
):
| undefined
| {
[argument: string]: unknown;
};
6 changes: 4 additions & 2 deletions 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
Expand Down Expand Up @@ -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<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
typeResolver?: Maybe<GraphQLTypeResolver<any, any>>;
Expand Down