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

Sync type TS definitions with Flow #2109

Merged
merged 7 commits into from
Aug 23, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion tstypes/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ export {
GraphQLIsTypeOfFn,
GraphQLObjectTypeConfig,
GraphQLResolveInfo,
ResponsePath,
GraphQLScalarTypeConfig,
GraphQLTypeResolver,
GraphQLUnionTypeConfig,
Expand Down
77 changes: 54 additions & 23 deletions tstypes/type/definition.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Maybe from '../tsutils/Maybe';
import { PromiseOrValue } from '../jsutils/PromiseOrValue';
import { Path } from '../jsutils/Path';
import {
ScalarTypeDefinitionNode,
ObjectTypeDefinitionNode,
Expand Down Expand Up @@ -75,6 +76,7 @@ export function assertNonNullType(type: any): GraphQLNonNull<any>;
/**
* 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
Expand All @@ -94,6 +96,7 @@ export function assertInputType(type: any): 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
Expand Down Expand Up @@ -285,13 +288,16 @@ export class GraphQLScalarType {
serialize: GraphQLScalarSerializer<any>;
parseValue: GraphQLScalarValueParser<any>;
parseLiteral: GraphQLScalarLiteralParser<any>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<ScalarTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
constructor(config: GraphQLScalarTypeConfig<any, any>);

toConfig(): GraphQLScalarTypeConfig<any, any> & {
serialize: GraphQLScalarSerializer<any>;
parseValue: GraphQLScalarValueParser<any>;
parseLiteral: GraphQLScalarLiteralParser<any>;
extensions: Maybe<Readonly<Record<string, any>>>;
extensionASTNodes: ReadonlyArray<ScalarTypeExtensionNode>;
};

Expand Down Expand Up @@ -320,6 +326,7 @@ export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
parseValue?: GraphQLScalarValueParser<TInternal>;
// Parses an externally provided literal value to use as an input.
parseLiteral?: GraphQLScalarLiteralParser<TInternal>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<ScalarTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
}
Expand Down Expand Up @@ -368,9 +375,10 @@ export class GraphQLObjectType<
> {
name: string;
description: Maybe<string>;
isTypeOf: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<ObjectTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
isTypeOf: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;

constructor(config: GraphQLObjectTypeConfig<TSource, TContext, TArgs>);
getFields(): GraphQLFieldMap<any, TContext, TArgs>;
Expand All @@ -387,20 +395,27 @@ export class GraphQLObjectType<
inspect(): string;
}

export function argsToArgsConfig(
args: ReadonlyArray<GraphQLArgument>,
): GraphQLFieldConfigArgumentMap;

// TS_SPECIFIC: TArgs
export interface GraphQLObjectTypeConfig<
TSource,
TContext,
TArgs = { [key: string]: any }
> {
name: string;
description?: Maybe<string>;
interfaces?: Thunk<Maybe<GraphQLInterfaceType[]>>;
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext, TArgs>>;
isTypeOf?: Maybe<GraphQLIsTypeOfFn<TSource, TContext>>;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<ObjectTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
}

// TS_SPECIFIC: TArgs
export type GraphQLTypeResolver<
TSource,
TContext,
Expand Down Expand Up @@ -435,30 +450,26 @@ export interface GraphQLResolveInfo {
readonly fieldNodes: ReadonlyArray<FieldNode>;
readonly returnType: GraphQLOutputType;
readonly parentType: GraphQLObjectType;
readonly path: ResponsePath;
readonly path: Path;
readonly schema: GraphQLSchema;
readonly fragments: { [key: string]: FragmentDefinitionNode };
readonly rootValue: any;
readonly operation: OperationDefinitionNode;
readonly variableValues: { [variableName: string]: any };
}

export type ResponsePath = {
readonly prev: ResponsePath | undefined;
readonly key: string | number;
};

export interface GraphQLFieldConfig<
TSource,
TContext,
TArgs = { [argName: string]: any }
> {
description?: Maybe<string>;
type: GraphQLOutputType;
args?: GraphQLFieldConfigArgumentMap;
resolve?: GraphQLFieldResolver<TSource, TContext, TArgs>;
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
deprecationReason?: Maybe<string>;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<FieldDefinitionNode>;
}

Expand All @@ -467,12 +478,14 @@ export type GraphQLFieldConfigArgumentMap = {
};

export interface GraphQLArgumentConfig {
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InputValueDefinitionNode>;
}

// TS_SPECIFIC: TArgs
export type GraphQLFieldConfigMap<
TSource,
TContext,
Expand All @@ -494,19 +507,22 @@ export interface GraphQLField<
subscribe?: GraphQLFieldResolver<TSource, TContext, TArgs>;
isDeprecated?: boolean;
deprecationReason?: Maybe<string>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<FieldDefinitionNode>;
}

export interface GraphQLArgument {
name: string;
description: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
description?: Maybe<string>;
astNode?: Maybe<InputValueDefinitionNode>;
defaultValue: any;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<InputValueDefinitionNode>;
}

export function isRequiredArgument(arg: GraphQLArgument): boolean;

// TS_SPECIFIC: TArgs
export type GraphQLFieldMap<
TSource,
TContext,
Expand Down Expand Up @@ -536,16 +552,18 @@ export type GraphQLFieldMap<
export class GraphQLInterfaceType {
name: string;
description: Maybe<string>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InterfaceTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;

constructor(config: GraphQLInterfaceTypeConfig<any, any>);

getFields(): GraphQLFieldMap<any, any>;

toConfig(): GraphQLInterfaceTypeConfig<any, any> & {
fields: GraphQLFieldConfigMap<any, any>;
extensions: Maybe<Readonly<Record<string, any>>>;
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
};

Expand All @@ -554,20 +572,22 @@ export class GraphQLInterfaceType {
inspect(): string;
}

// TS_SPECIFIC: TArgs
export interface GraphQLInterfaceTypeConfig<
TSource,
TContext,
TArgs = { [key: string]: any }
> {
name: string;
description?: Maybe<string>;
fields: Thunk<GraphQLFieldConfigMap<TSource, TContext, TArgs>>;
/**
* Optionally provide a custom type resolver function. If one is not provided,
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext, TArgs>>;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InterfaceTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
}
Expand Down Expand Up @@ -598,9 +618,10 @@ export interface GraphQLInterfaceTypeConfig<
export class GraphQLUnionType {
name: string;
description: Maybe<string>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<UnionTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
resolveType: Maybe<GraphQLTypeResolver<any, any>>;

constructor(config: GraphQLUnionTypeConfig<any, any>);

Expand All @@ -618,14 +639,15 @@ export class GraphQLUnionType {

export interface GraphQLUnionTypeConfig<TSource, TContext> {
name: string;
description?: Maybe<string>;
types: Thunk<GraphQLObjectType[]>;
/**
* Optionally provide a custom type resolver function. If one is not provided,
* the default implementation will call `isTypeOf` on each implementing
* Object type.
*/
resolveType?: Maybe<GraphQLTypeResolver<TSource, TContext>>;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<UnionTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
}
Expand Down Expand Up @@ -654,6 +676,7 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
export class GraphQLEnumType {
name: string;
description: Maybe<string>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<EnumTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;

Expand All @@ -678,8 +701,9 @@ export class GraphQLEnumType {

export interface GraphQLEnumTypeConfig {
name: string;
values: GraphQLEnumValueConfigMap;
description?: Maybe<string>;
values: GraphQLEnumValueConfigMap;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<EnumTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
}
Expand All @@ -689,19 +713,21 @@ export type GraphQLEnumValueConfigMap = {
};

export interface GraphQLEnumValueConfig {
description?: Maybe<string>;
value?: any;
deprecationReason?: Maybe<string>;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<EnumValueDefinitionNode>;
}

export interface GraphQLEnumValue {
name: string;
description: Maybe<string>;
value: any;
isDeprecated?: boolean;
deprecationReason: Maybe<string>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<EnumValueDefinitionNode>;
value: any;
}

/**
Expand All @@ -727,13 +753,15 @@ export interface GraphQLEnumValue {
export class GraphQLInputObjectType {
name: string;
description: Maybe<string>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<InputObjectTypeDefinitionNode>;
extensionASTNodes: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
constructor(config: GraphQLInputObjectTypeConfig);
getFields(): GraphQLInputFieldMap;

toConfig(): GraphQLInputObjectTypeConfig & {
fields: GraphQLInputFieldConfigMap;
extensions: Maybe<Readonly<Record<string, any>>>;
extensionASTNodes: ReadonlyArray<InputObjectTypeExtensionNode>;
};

Expand All @@ -744,16 +772,18 @@ export class GraphQLInputObjectType {

export interface GraphQLInputObjectTypeConfig {
name: string;
fields: Thunk<GraphQLInputFieldConfigMap>;
description?: Maybe<string>;
fields: Thunk<GraphQLInputFieldConfigMap>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InputObjectTypeDefinitionNode>;
extensionASTNodes?: Maybe<ReadonlyArray<InputObjectTypeExtensionNode>>;
}

export interface GraphQLInputFieldConfig {
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
description?: Maybe<string>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InputValueDefinitionNode>;
}

Expand All @@ -763,9 +793,10 @@ export type GraphQLInputFieldConfigMap = {

export interface GraphQLInputField {
name: string;
description?: Maybe<string>;
type: GraphQLInputType;
defaultValue?: any;
description?: Maybe<string>;
extensions: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<InputValueDefinitionNode>;
}

Expand Down
12 changes: 10 additions & 2 deletions tstypes/type/directives.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { DirectiveLocationEnum } from '../language/directiveLocation';
* Test if the given value is a GraphQL directive.
*/
export function isDirective(directive: any): directive is GraphQLDirective;

export function assertDirective(directive: any): GraphQLDirective;
/**
* Directives are used by the GraphQL runtime as a way of modifying execution
* behavior. Type system creators will usually not create these directly.
Expand All @@ -18,12 +18,17 @@ export class GraphQLDirective {
locations: DirectiveLocationEnum[];
isRepeatable: boolean;
args: GraphQLArgument[];
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode: Maybe<DirectiveDefinitionNode>;

constructor(config: GraphQLDirectiveConfig);

toString(): string;

toConfig(): GraphQLDirectiveConfig & {
args: GraphQLFieldConfigArgumentMap;
extensions?: Maybe<Readonly<Record<string, any>>>;
isRepeatable: boolean;
};
}

Expand All @@ -33,6 +38,7 @@ export interface GraphQLDirectiveConfig {
locations: DirectiveLocationEnum[];
args?: Maybe<GraphQLFieldConfigArgumentMap>;
isRepeatable?: Maybe<boolean>;
extensions?: Maybe<Readonly<Record<string, any>>>;
astNode?: Maybe<DirectiveDefinitionNode>;
}

Expand Down Expand Up @@ -61,4 +67,6 @@ export const GraphQLDeprecatedDirective: GraphQLDirective;
*/
export const specifiedDirectives: ReadonlyArray<GraphQLDirective>;

export function isSpecifiedDirective(directive: GraphQLDirective): boolean;
export function isSpecifiedDirective(
directive: any,
): directive is GraphQLDirective;
Loading