[@types/graphql] Switch void for more correct undefined | null typing (#25639)

* [@types/graphql] Switch void for more correct `undefined | null` typing

* Moved Maybe.d.ts to a better place

* Moved and fixed up Maybe imports
This commit is contained in:
Brad Zacher
2018-05-11 05:58:19 +10:00
committed by Sheetal Nandi
parent f8cac97960
commit 7aa84a6417
23 changed files with 197 additions and 167 deletions

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { getLocation } from "../language";
import { ASTNode } from "../language/ast";
import { Source } from "../language/source";
@@ -58,7 +59,7 @@ export class GraphQLError extends Error {
/**
* The original error thrown from a field resolver during execution.
*/
readonly originalError: Error | void;
readonly originalError: Maybe<Error>;
/**
* Extension fields to add to the formatted error.
@@ -68,10 +69,10 @@ export class GraphQLError extends Error {
constructor(
message: string,
nodes?: ReadonlyArray<ASTNode> | ASTNode | undefined,
source?: Source | void,
positions?: ReadonlyArray<number> | void,
path?: ReadonlyArray<string | number> | void,
originalError?: Error | void,
extensions?: { [key: string]: any } | void
source?: Maybe<Source>,
positions?: Maybe<ReadonlyArray<number>>,
path?: Maybe<ReadonlyArray<string | number>>,
originalError?: Maybe<Error>,
extensions?: Maybe<{ [key: string]: any }>
);
}

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLError, locatedError } from "../error";
import { GraphQLSchema } from "../type/schema";
import {
@@ -51,9 +52,9 @@ export type ExecutionArgs = {
document: DocumentNode;
rootValue?: any;
contextValue?: any;
variableValues?: { [key: string]: any } | void;
operationName?: string | void;
fieldResolver?: GraphQLFieldResolver<any, any> | void;
variableValues?: Maybe<{ [key: string]: any }>;
operationName?: Maybe<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
};
/**
@@ -74,9 +75,9 @@ export function execute(
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any } | void,
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void
variableValues?: Maybe<{ [key: string]: any }>,
operationName?: Maybe<string>,
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
): MaybePromise<ExecutionResult>;
/**
@@ -101,7 +102,7 @@ export function addPath(
export function assertValidExecutionArguments(
schema: GraphQLSchema,
document: DocumentNode,
rawVariableValues: { [key: string]: any } | void
rawVariableValues: Maybe<{ [key: string]: any }>
): void;
/**
@@ -115,9 +116,9 @@ export function buildExecutionContext(
document: DocumentNode,
rootValue: any,
contextValue: any,
rawVariableValues: { [key: string]: any } | void,
operationName: string | void,
fieldResolver: GraphQLFieldResolver<any, any> | void
rawVariableValues: Maybe<{ [key: string]: any }>,
operationName: Maybe<string>,
fieldResolver: Maybe<GraphQLFieldResolver<any, any>>
): ReadonlyArray<GraphQLError> | ExecutionContext;
/**
@@ -181,4 +182,4 @@ export function getFieldDef(
schema: GraphQLSchema,
parentType: GraphQLObjectType,
fieldName: string
): GraphQLField<any, any> | void;
): Maybe<GraphQLField<any, any>>;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLError } from "../error";
import { GraphQLInputType, GraphQLField, GraphQLArgument } from "../type/definition";
import { GraphQLDirective } from "../type/directives";
@@ -35,7 +36,7 @@ export function getVariableValues(
export function getArgumentValues(
def: GraphQLField<any, any> | GraphQLDirective,
node: FieldNode | DirectiveNode,
variableValues?: { [key: string]: any } | void
variableValues?: Maybe<{ [key: string]: any }>
): { [key: string]: any };
/**
@@ -54,5 +55,5 @@ export function getDirectiveValues(
node: {
readonly directives?: ReadonlyArray<DirectiveNode>;
},
variableValues?: { [key: string]: any } | void
variableValues?: Maybe<{ [key: string]: any }>
): undefined | { [key: string]: any };

View File

@@ -1,3 +1,4 @@
import Maybe from "./tsutils/Maybe";
import { Source } from "./language/source";
import { GraphQLFieldResolver } from "./type/definition";
import { GraphQLSchema } from "./type/schema";
@@ -38,9 +39,9 @@ export interface GraphQLArgs {
source: Source | string;
rootValue?: any;
contextValue?: any;
variableValues?: { [key: string]: any } | void;
operationName?: string | void;
fieldResolver?: GraphQLFieldResolver<any, any> | void;
variableValues?: Maybe<{ [key: string]: any }>;
operationName?: Maybe<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
}
export function graphql(args: GraphQLArgs): Promise<ExecutionResult>;
@@ -49,9 +50,9 @@ export function graphql(
source: Source | string,
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any } | void,
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void
variableValues?: Maybe<{ [key: string]: any }>,
operationName?: Maybe<string>,
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
): Promise<ExecutionResult>;
/**
@@ -66,7 +67,7 @@ export function graphqlSync(
source: Source | string,
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any } | void,
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void
variableValues?: Maybe<{ [key: string]: any }>,
operationName?: Maybe<string>,
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
): ExecutionResult;

View File

@@ -13,6 +13,7 @@
// Dylan Stewart <https://github.com/dyst5422>
// Alessio Dionisi <https://github.com/adnsio>
// Divyendu Singh <https://github.com/divyenduz>
// Brad Zacher <https://github.com/bradzacher>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.3

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { ASTNode, ASTKindToNode } from "./ast";
import { TypeInfo } from "../utilities/TypeInfo";
@@ -157,4 +158,4 @@ export function visitWithTypeInfo(typeInfo: TypeInfo, visitor: Visitor<ASTKindTo
* Given a visitor instance, if it is leaving or not, and a node kind, return
* the function the visitor runtime should call.
*/
export function getVisitFn(visitor: Visitor<any>, kind: string, isLeaving: boolean): VisitFn<any> | void;
export function getVisitFn(visitor: Visitor<any>, kind: string, isLeaving: boolean): Maybe<VisitFn<any>>;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLSchema } from "../type/schema";
import { DocumentNode } from "../language/ast";
import { GraphQLFieldResolver } from "../type/definition";
@@ -28,10 +29,10 @@ export function subscribe(args: {
document: DocumentNode;
rootValue?: any;
contextValue?: any;
variableValues?: { [key: string]: any } | void;
operationName?: string | void;
fieldResolver?: GraphQLFieldResolver<any, any> | void;
subscribeFieldResolver?: GraphQLFieldResolver<any, any> | void;
variableValues?: Maybe<{ [key: string]: any }>;
operationName?: Maybe<string>;
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>;
}): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
export function subscribe(
@@ -39,10 +40,10 @@ export function subscribe(
document: DocumentNode,
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any } | void,
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void,
subscribeFieldResolver?: GraphQLFieldResolver<any, any> | void
variableValues?: Maybe<{ [key: string]: any }>,
operationName?: Maybe<string>,
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>,
subscribeFieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
): Promise<AsyncIterator<ExecutionResult> | ExecutionResult>;
/**
@@ -69,6 +70,6 @@ export function createSourceEventStream(
rootValue?: any,
contextValue?: any,
variableValues?: { [key: string]: any },
operationName?: string | void,
fieldResolver?: GraphQLFieldResolver<any, any> | void
operationName?: Maybe<string>,
fieldResolver?: Maybe<GraphQLFieldResolver<any, any>>
): Promise<AsyncIterable<any> | ExecutionResult>;

View File

@@ -7,7 +7,7 @@
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": false,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
@@ -21,4 +21,4 @@
"index.d.ts",
"graphql-tests.ts"
]
}
}

4
types/graphql/tsutils/Maybe.d.ts vendored Normal file
View File

@@ -0,0 +1,4 @@
// Conveniently represents flow's "Maybe" type https://flow.org/en/docs/types/maybe/
type Maybe<T> = null | undefined | T
export default Maybe

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { MaybePromise } from "../jsutils/MaybePromise";
import {
ScalarTypeDefinitionNode,
@@ -254,8 +255,8 @@ export type Thunk<T> = (() => T) | T;
*/
export class GraphQLScalarType {
name: string;
description: string | void;
astNode?: ScalarTypeDefinitionNode | void;
description: Maybe<string>;
astNode?: Maybe<ScalarTypeDefinitionNode>;
constructor(config: GraphQLScalarTypeConfig<any, any>);
// Serializes an internal value to include in a response.
@@ -265,7 +266,7 @@ export class GraphQLScalarType {
parseValue(value: any): any;
// Parses an externally provided literal value to use as an input.
parseLiteral(valueNode: ValueNode, variables?: { [key: string]: any } | void): any;
parseLiteral(valueNode: ValueNode, variables?: Maybe<{ [key: string]: any }>): any;
toString(): string;
toJSON(): string;
@@ -274,11 +275,11 @@ export class GraphQLScalarType {
export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
name: string;
description?: string | void;
astNode?: ScalarTypeDefinitionNode | void;
serialize(value: any): TExternal | void;
parseValue?(value: any): TInternal | void;
parseLiteral?(valueNode: ValueNode, variables: { [key: string]: any } | void): TInternal | void;
description?: Maybe<string>;
astNode?: Maybe<ScalarTypeDefinitionNode>;
serialize(value: any): Maybe<TExternal>;
parseValue?(value: any): Maybe<TInternal>;
parseLiteral?(valueNode: ValueNode, variables: Maybe<{ [key: string]: any }>): Maybe<TInternal>;
}
/**
@@ -320,10 +321,10 @@ export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
*/
export class GraphQLObjectType {
name: string;
description: string | void;
astNode: ObjectTypeDefinitionNode | void;
extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode> | void;
isTypeOf: GraphQLIsTypeOfFn<any, any> | void;
description: Maybe<string>;
astNode: Maybe<ObjectTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
isTypeOf: Maybe<GraphQLIsTypeOfFn<any, any>>;
constructor(config: GraphQLObjectTypeConfig<any, any>);
getFields(): GraphQLFieldMap<any, any>;
@@ -335,19 +336,19 @@ export class GraphQLObjectType {
export interface GraphQLObjectTypeConfig<TSource, TContext> {
name: string;
interfaces?: Thunk<GraphQLInterfaceType[] | void>;
interfaces?: Thunk<Maybe<GraphQLInterfaceType[]>>;
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext>>;
isTypeOf?: GraphQLIsTypeOfFn<TSource, TContext> | void;
description?: string | void;
astNode?: ObjectTypeDefinitionNode | void;
extensionASTNodes?: ReadonlyArray<ObjectTypeExtensionNode> | void;
isTypeOf?: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
description?: Maybe<string>;
astNode?: Maybe<ObjectTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
}
export type GraphQLTypeResolver<TSource, TContext> = (
value: TSource,
context: TContext,
info: GraphQLResolveInfo
) => MaybePromise<GraphQLObjectType | string | void>;
) => MaybePromise<Maybe<GraphQLObjectType | string>>;
export type GraphQLIsTypeOfFn<TSource, TContext> = (
source: TSource,
@@ -385,9 +386,9 @@ export interface GraphQLFieldConfig<TSource, TContext, TArgs = { [argName: strin
args?: GraphQLFieldConfigArgumentMap;
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
deprecationReason?: string | void;
description?: string | void;
astNode?: FieldDefinitionNode | void;
deprecationReason?: Maybe<string>;
description?: Maybe<string>;
astNode?: Maybe<FieldDefinitionNode>;
}
export type GraphQLFieldConfigArgumentMap = { [key: string]: GraphQLArgumentConfig };
@@ -395,8 +396,8 @@ export type GraphQLFieldConfigArgumentMap = { [key: string]: GraphQLArgumentConf
export interface GraphQLArgumentConfig {
type: GraphQLInputType;
defaultValue?: any;
description?: string | void;
astNode?: InputValueDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<InputValueDefinitionNode>;
}
export type GraphQLFieldConfigMap<TSource, TContext> = {
@@ -405,22 +406,22 @@ export type GraphQLFieldConfigMap<TSource, TContext> = {
export interface GraphQLField<TSource, TContext, TArgs = { [key: string]: any }> {
name: string;
description: string | void;
description: Maybe<string>;
type: GraphQLOutputType;
args: GraphQLArgument[];
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
isDeprecated?: boolean;
deprecationReason?: string | void;
astNode?: FieldDefinitionNode | void;
deprecationReason?: Maybe<string>;
astNode?: Maybe<FieldDefinitionNode>;
}
export interface GraphQLArgument {
name: string;
type: GraphQLInputType;
defaultValue?: any;
description?: string | void;
astNode?: InputValueDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<InputValueDefinitionNode>;
}
export type GraphQLFieldMap<TSource, TContext> = {
@@ -447,10 +448,10 @@ export type GraphQLFieldMap<TSource, TContext> = {
*/
export class GraphQLInterfaceType {
name: string;
description: string | void;
astNode?: InterfaceTypeDefinitionNode | void;
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode> | void;
resolveType: GraphQLTypeResolver<any, any> | void;
description: Maybe<string>;
astNode?: Maybe<InterfaceTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
constructor(config: GraphQLInterfaceTypeConfig<any, any>);
@@ -469,10 +470,10 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: GraphQLTypeResolver<TSource, TContext> | void;
description?: string | void;
astNode?: InterfaceTypeDefinitionNode | void;
extensionASTNodes?: ReadonlyArray<InterfaceTypeExtensionNode> | void;
resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext>>;
description?: Maybe<string>;
astNode?: Maybe<InterfaceTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
}
/**
@@ -500,9 +501,9 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
*/
export class GraphQLUnionType {
name: string;
description: string | void;
astNode?: UnionTypeDefinitionNode | void;
resolveType: GraphQLTypeResolver<any, any> | void;
description: Maybe<string>;
astNode?: Maybe<UnionTypeDefinitionNode>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
constructor(config: GraphQLUnionTypeConfig<any, any>);
@@ -521,9 +522,9 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: GraphQLTypeResolver<TSource, TContext> | void;
description?: string | void;
astNode?: UnionTypeDefinitionNode | void;
resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext>>;
description?: Maybe<string>;
astNode?: Maybe<UnionTypeDefinitionNode>;
}
/**
@@ -549,15 +550,15 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
*/
export class GraphQLEnumType {
name: string;
description: string | void;
astNode: EnumTypeDefinitionNode | void;
description: Maybe<string>;
astNode: Maybe<EnumTypeDefinitionNode>;
constructor(config: GraphQLEnumTypeConfig);
getValues(): GraphQLEnumValue[];
getValue(name: string): GraphQLEnumValue | void;
serialize(value: any): string | void;
parseValue(value: any): any;
parseLiteral(valueNode: ValueNode, _variables: { [key: string]: any } | void): any;
getValue(name: string): Maybe<GraphQLEnumValue>;
serialize(value: any): Maybe<string>;
parseValue(value: any): Maybe<any>;
parseLiteral(valueNode: ValueNode, _variables: Maybe<{ [key: string]: any }>): Maybe<any>;
toString(): string;
toJSON(): string;
inspect(): string;
@@ -566,25 +567,25 @@ export class GraphQLEnumType {
export interface GraphQLEnumTypeConfig {
name: string;
values: GraphQLEnumValueConfigMap;
description?: string | void;
astNode?: EnumTypeDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<EnumTypeDefinitionNode>;
}
export type GraphQLEnumValueConfigMap = { [key: string]: GraphQLEnumValueConfig };
export interface GraphQLEnumValueConfig {
value?: any;
deprecationReason?: string | void;
description?: string | void;
astNode?: EnumValueDefinitionNode | void;
deprecationReason?: Maybe<string>;
description?: Maybe<string>;
astNode?: Maybe<EnumValueDefinitionNode>;
}
export interface GraphQLEnumValue {
name: string;
description: string | void;
description: Maybe<string>;
isDeprecated?: boolean;
deprecationReason: string | void;
astNode?: EnumValueDefinitionNode | void;
deprecationReason: Maybe<string>;
astNode?: Maybe<EnumValueDefinitionNode>;
value: any;
}
@@ -610,8 +611,8 @@ export interface GraphQLEnumValue {
*/
export class GraphQLInputObjectType {
name: string;
description: string | void;
astNode: InputObjectTypeDefinitionNode | void;
description: Maybe<string>;
astNode: Maybe<InputObjectTypeDefinitionNode>;
constructor(config: GraphQLInputObjectTypeConfig);
getFields(): GraphQLInputFieldMap;
toString(): string;
@@ -622,15 +623,15 @@ export class GraphQLInputObjectType {
export interface GraphQLInputObjectTypeConfig {
name: string;
fields: Thunk<GraphQLInputFieldConfigMap>;
description?: string | void;
astNode?: InputObjectTypeDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<InputObjectTypeDefinitionNode>;
}
export interface GraphQLInputFieldConfig {
type: GraphQLInputType;
defaultValue?: any;
description?: string | void;
astNode?: InputValueDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<InputValueDefinitionNode>;
}
export type GraphQLInputFieldConfigMap = {
@@ -641,8 +642,8 @@ export interface GraphQLInputField {
name: string;
type: GraphQLInputType;
defaultValue?: any;
description?: string | void;
astNode?: InputValueDefinitionNode | void;
description?: Maybe<string>;
astNode?: Maybe<InputValueDefinitionNode>;
}
export type GraphQLInputFieldMap = { [key: string]: GraphQLInputField };

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLFieldConfigArgumentMap, GraphQLArgument } from "./definition";
import { DirectiveDefinitionNode } from "../language/ast";
import { DirectiveLocationEnum } from "../language/directiveLocation";
@@ -13,20 +14,20 @@ export function isDirective(directive: any): directive is GraphQLDirective;
*/
export class GraphQLDirective {
name: string;
description: string | void;
description: Maybe<string>;
locations: DirectiveLocationEnum[];
args: GraphQLArgument[];
astNode: DirectiveDefinitionNode | void;
astNode: Maybe<DirectiveDefinitionNode>;
constructor(config: GraphQLDirectiveConfig);
}
export interface GraphQLDirectiveConfig {
name: string;
description?: string | void;
description?: Maybe<string>;
locations: DirectiveLocationEnum[];
args?: GraphQLFieldConfigArgumentMap | void;
astNode?: DirectiveDefinitionNode | void;
args?: Maybe<GraphQLFieldConfigArgumentMap>;
astNode?: Maybe<DirectiveDefinitionNode>;
}
/**

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLObjectType } from "./definition";
import { GraphQLType, GraphQLNamedType, GraphQLAbstractType } from "./definition";
import { SchemaDefinitionNode } from "../language/ast";
@@ -35,21 +36,21 @@ export function isSchema(schema: any): schema is GraphQLSchema;
*
*/
export class GraphQLSchema {
astNode: SchemaDefinitionNode | void;
astNode: Maybe<SchemaDefinitionNode>;
constructor(config: GraphQLSchemaConfig);
getQueryType(): GraphQLObjectType | void;
getMutationType(): GraphQLObjectType | void;
getSubscriptionType(): GraphQLObjectType | void;
getQueryType(): Maybe<GraphQLObjectType>;
getMutationType(): Maybe<GraphQLObjectType>;
getSubscriptionType(): Maybe<GraphQLObjectType>;
getTypeMap(): TypeMap;
getType(name: string): GraphQLNamedType | void;
getType(name: string): Maybe<GraphQLNamedType>;
getPossibleTypes(abstractType: GraphQLAbstractType): ReadonlyArray<GraphQLObjectType>;
isPossibleType(abstractType: GraphQLAbstractType, possibleType: GraphQLObjectType): boolean;
getDirectives(): ReadonlyArray<GraphQLDirective>;
getDirective(name: string): GraphQLDirective | void;
getDirective(name: string): Maybe<GraphQLDirective>;
}
type TypeMap = { [key: string]: GraphQLNamedType };
@@ -72,14 +73,14 @@ export interface GraphQLSchemaValidationOptions {
* This option is provided to ease adoption and may be removed in a future
* major release.
*/
allowedLegacyNames?: ReadonlyArray<string> | void;
allowedLegacyNames?: Maybe<ReadonlyArray<string>>;
}
export interface GraphQLSchemaConfig extends GraphQLSchemaValidationOptions {
query: GraphQLObjectType | void;
mutation?: GraphQLObjectType | void;
subscription?: GraphQLObjectType | void;
types?: GraphQLNamedType[] | void;
directives?: GraphQLDirective[] | void;
astNode?: SchemaDefinitionNode | void;
query: Maybe<GraphQLObjectType>;
mutation?: Maybe<GraphQLObjectType>;
subscription?: Maybe<GraphQLObjectType>;
types?: Maybe<GraphQLNamedType[]>;
directives?: Maybe<GraphQLDirective[]>;
astNode?: Maybe<SchemaDefinitionNode>;
}

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLSchema } from "../type/schema";
import {
GraphQLOutputType,
@@ -28,14 +29,15 @@ export class TypeInfo {
initialType?: GraphQLType
);
getType(): GraphQLOutputType | void;
getParentType(): GraphQLCompositeType | void;
getInputType(): GraphQLInputType | void;
getParentInputType(): GraphQLInputType | void;
getFieldDef(): GraphQLField<any, any> | void;
getDirective(): GraphQLDirective | void;
getArgument(): GraphQLArgument | void;
getEnumValue(): GraphQLEnumValue | void;
getType(): Maybe<GraphQLOutputType>;
getParentType(): Maybe<GraphQLCompositeType>;
getInputType(): Maybe<GraphQLInputType>;
getParentInputType(): Maybe<GraphQLInputType>;
getFieldDef(): GraphQLField<any, Maybe<any>>;
getDefaultValue(): Maybe<any>;
getDirective(): Maybe<GraphQLDirective>;
getArgument(): Maybe<GraphQLArgument>;
getEnumValue(): Maybe<GraphQLEnumValue>;
enter(node: ASTNode): any;
leave(node: ASTNode): any;
}
@@ -44,4 +46,4 @@ type getFieldDef = (
schema: GraphQLSchema,
parentType: GraphQLType,
fieldNode: FieldNode
) => GraphQLField<any, any> | void;
) => Maybe<GraphQLField<any, any>>;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { ValueNode } from "../language/ast";
import { GraphQLInputType } from "../type/definition";
@@ -18,4 +19,4 @@ import { GraphQLInputType } from "../type/definition";
* | null | NullValue |
*
*/
export function astFromValue(value: any, type: GraphQLInputType): ValueNode | void;
export function astFromValue(value: any, type: GraphQLInputType): Maybe<ValueNode>;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import {
DocumentNode,
Location,
@@ -47,7 +48,7 @@ type TypeDefinitionsMap = { [key: string]: TypeDefinitionNode };
type TypeResolver = (typeRef: NamedTypeNode) => GraphQLNamedType;
export class ASTDefinitionBuilder {
constructor(typeDefinitionsMap: TypeDefinitionsMap, options: BuildSchemaOptions | void, resolveType: TypeResolver);
constructor(typeDefinitionsMap: TypeDefinitionsMap, options: Maybe<BuildSchemaOptions>, resolveType: TypeResolver);
buildTypes(nodes: ReadonlyArray<NamedTypeNode | TypeDefinitionNode>): Array<GraphQLNamedType>;
@@ -69,7 +70,7 @@ export class ASTDefinitionBuilder {
*/
export function getDescription(
node: { readonly description?: StringValueNode; readonly loc?: Location },
options: BuildSchemaOptions | void
options: Maybe<BuildSchemaOptions>
): string | undefined;
/**

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { DocumentNode, OperationDefinitionNode } from "../language/ast";
/**
@@ -7,5 +8,5 @@ import { DocumentNode, OperationDefinitionNode } from "../language/ast";
*/
export function getOperationAST(
documentAST: DocumentNode,
operationName: string | void
): OperationDefinitionNode | void;
operationName: Maybe<string>
): Maybe<OperationDefinitionNode>;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { DirectiveLocationEnum } from "../language/directiveLocation";
export interface IntrospectionOptions {
@@ -16,8 +17,8 @@ export interface IntrospectionQuery {
export interface IntrospectionSchema {
readonly queryType: IntrospectionNamedTypeRef<IntrospectionObjectType>;
readonly mutationType: IntrospectionNamedTypeRef<IntrospectionObjectType> | void;
readonly subscriptionType: IntrospectionNamedTypeRef<IntrospectionObjectType> | void;
readonly mutationType: Maybe<IntrospectionNamedTypeRef<IntrospectionObjectType>>;
readonly subscriptionType: Maybe<IntrospectionNamedTypeRef<IntrospectionObjectType>>;
readonly types: ReadonlyArray<IntrospectionType>;
readonly directives: ReadonlyArray<IntrospectionDirective>;
}
@@ -42,13 +43,13 @@ export type IntrospectionInputType = IntrospectionScalarType | IntrospectionEnum
export interface IntrospectionScalarType {
readonly kind: "SCALAR";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
}
export interface IntrospectionObjectType {
readonly kind: "OBJECT";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly fields: ReadonlyArray<IntrospectionField>;
readonly interfaces: ReadonlyArray<IntrospectionNamedTypeRef<IntrospectionInterfaceType>>;
}
@@ -56,7 +57,7 @@ export interface IntrospectionObjectType {
export interface IntrospectionInterfaceType {
readonly kind: "INTERFACE";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly fields: ReadonlyArray<IntrospectionField>;
readonly possibleTypes: ReadonlyArray<IntrospectionNamedTypeRef<IntrospectionObjectType>>;
}
@@ -64,21 +65,21 @@ export interface IntrospectionInterfaceType {
export interface IntrospectionUnionType {
readonly kind: "UNION";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly possibleTypes: ReadonlyArray<IntrospectionNamedTypeRef<IntrospectionObjectType>>;
}
export interface IntrospectionEnumType {
readonly kind: "ENUM";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly enumValues: ReadonlyArray<IntrospectionEnumValue>;
}
export interface IntrospectionInputObjectType {
readonly kind: "INPUT_OBJECT";
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly inputFields: ReadonlyArray<IntrospectionInputValue>;
}
@@ -114,30 +115,30 @@ export interface IntrospectionNamedTypeRef<T extends IntrospectionType = Introsp
export interface IntrospectionField {
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly args: ReadonlyArray<IntrospectionInputValue>;
readonly type: IntrospectionOutputTypeRef;
readonly isDeprecated: boolean;
readonly deprecationReason?: string | void;
readonly deprecationReason?: Maybe<string>;
}
export interface IntrospectionInputValue {
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly type: IntrospectionInputTypeRef;
readonly defaultValue?: string | void;
readonly defaultValue?: Maybe<string>;
}
export interface IntrospectionEnumValue {
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly isDeprecated: boolean;
readonly deprecationReason?: string | void;
readonly deprecationReason?: Maybe<string>;
}
export interface IntrospectionDirective {
readonly name: string;
readonly description?: string | void;
readonly description?: Maybe<string>;
readonly locations: ReadonlyArray<DirectiveLocationEnum>;
readonly args: ReadonlyArray<IntrospectionInputValue>;
}

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLInputType } from "../type/definition";
import { ValueNode, VariableNode, ListValueNode, ObjectValueNode } from "../language/ast";
@@ -22,7 +23,7 @@ import { ValueNode, VariableNode, ListValueNode, ObjectValueNode } from "../lang
*
*/
export function valueFromAST(
valueNode: ValueNode | void,
valueNode: Maybe<ValueNode>,
type: GraphQLInputType,
variables?: { [key: string]: any } | void
variables?: Maybe<{ [key: string]: any }>
): any;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { ValueNode } from "../language/ast";
/**
@@ -16,4 +17,4 @@ import { ValueNode } from "../language/ast";
* | Null | null |
*
*/
export function valueFromASTUntyped(valueNode: ValueNode, variables?: { [key: string]: any } | void): any;
export function valueFromASTUntyped(valueNode: ValueNode, variables?: Maybe<{ [key: string]: any }>): any;

View File

@@ -1,3 +1,4 @@
import Maybe from "../tsutils/Maybe";
import { GraphQLError } from "../error";
import {
DocumentNode,
@@ -19,7 +20,11 @@ import { GraphQLDirective } from "../type/directives";
import { TypeInfo } from "../utilities/TypeInfo";
type NodeWithSelectionSet = OperationDefinitionNode | FragmentDefinitionNode;
type VariableUsage = { node: VariableNode; type: GraphQLInputType | void };
type VariableUsage = {
readonly node: VariableNode;
readonly type: Maybe<GraphQLInputType>;
readonly defaultValue: Maybe<any>;
};
/**
* An instance of this class is passed as the "this" context to all validators,
@@ -37,7 +42,7 @@ export default class ValidationContext {
getDocument(): DocumentNode;
getFragment(name: string): FragmentDefinitionNode | void;
getFragment(name: string): Maybe<FragmentDefinitionNode>;
getFragmentSpreads(node: SelectionSetNode): ReadonlyArray<FragmentSpreadNode>;
@@ -47,17 +52,17 @@ export default class ValidationContext {
getRecursiveVariableUsages(operation: OperationDefinitionNode): ReadonlyArray<VariableUsage>;
getType(): GraphQLOutputType | void;
getType(): Maybe<GraphQLOutputType>;
getParentType(): GraphQLCompositeType | void;
getParentType(): Maybe<GraphQLCompositeType>;
getInputType(): GraphQLInputType | void;
getInputType(): Maybe<GraphQLInputType>;
getParentInputType(): GraphQLInputType | void;
getParentInputType(): Maybe<GraphQLInputType>;
getFieldDef(): GraphQLField<any, any> | void;
getFieldDef(): Maybe<GraphQLField<any, any>>;
getDirective(): GraphQLDirective | void;
getDirective(): Maybe<GraphQLDirective>;
getArgument(): GraphQLArgument | void;
getArgument(): Maybe<GraphQLArgument>;
}

View File

@@ -1,7 +1,8 @@
import Maybe from "../../tsutils/Maybe";
import ValidationContext from "../ValidationContext";
import { ASTVisitor } from "../../language/visitor";
export function undefinedVarMessage(varName: string, opName: string | void): string;
export function undefinedVarMessage(varName: string, opName: Maybe<string>): string;
/**
* No undefined variables

View File

@@ -1,7 +1,8 @@
import Maybe from "../../tsutils/Maybe";
import ValidationContext from "../ValidationContext";
import { ASTVisitor } from "../../language/visitor";
export function unusedVariableMessage(varName: string, opName: string | void): string;
export function unusedVariableMessage(varName: string, opName: Maybe<string>): string;
/**
* No unused variables

View File

@@ -1,7 +1,8 @@
import Maybe from "../../tsutils/Maybe";
import ValidationContext from "../ValidationContext";
import { ASTVisitor } from "../../language/visitor";
export function singleFieldOnlyMessage(name: string | void): string;
export function singleFieldOnlyMessage(name: Maybe<string>): string;
/**
* Subscriptions must only include one field.