From a482d3b24d7a6d4a8027614ab6304e980548e16f Mon Sep 17 00:00:00 2001 From: Jackson Kearl Date: Fri, 23 Aug 2019 11:31:28 -0700 Subject: [PATCH] Sync type TS definitions with Flow (#2109) * Sync type TS definitions with Flow Specifically: Add `extensions` field in lots of places Reorder fields Both this and #2106 add Path.d.ts, but they're the same. If theres a merge conflict, just pick one. * `unknown` => `any`, to target TS@2.6 * Widen `introspectionTypes` type to `GraphQLType[]` * use Maybe>> as `extension` type * Remove `ResponsePath` export (now `jsutils/Path`) * More removal of `ResponsePath` --- tstypes/index.d.ts | 1 - tstypes/type/definition.d.ts | 77 +++++++++++++++++++++++---------- tstypes/type/directives.d.ts | 12 ++++- tstypes/type/index.d.ts | 5 ++- tstypes/type/introspection.d.ts | 11 ++--- tstypes/type/scalars.d.ts | 2 +- tstypes/type/schema.d.ts | 12 +++-- tstypes/type/validate.d.ts | 2 +- 8 files changed, 82 insertions(+), 40 deletions(-) diff --git a/tstypes/index.d.ts b/tstypes/index.d.ts index f9a5acbdd7..b5d39379d0 100644 --- a/tstypes/index.d.ts +++ b/tstypes/index.d.ts @@ -128,7 +128,6 @@ export { GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, GraphQLResolveInfo, - ResponsePath, GraphQLScalarTypeConfig, GraphQLTypeResolver, GraphQLUnionTypeConfig, diff --git a/tstypes/type/definition.d.ts b/tstypes/type/definition.d.ts index 28b68dd7ac..b468797748 100644 --- a/tstypes/type/definition.d.ts +++ b/tstypes/type/definition.d.ts @@ -1,5 +1,6 @@ import Maybe from '../tsutils/Maybe'; import { PromiseOrValue } from '../jsutils/PromiseOrValue'; +import { Path } from '../jsutils/Path'; import { ScalarTypeDefinitionNode, ObjectTypeDefinitionNode, @@ -75,6 +76,7 @@ export function assertNonNullType(type: any): 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 @@ -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 @@ -285,13 +288,16 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; constructor(config: GraphQLScalarTypeConfig); toConfig(): GraphQLScalarTypeConfig & { + serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; + extensions: Maybe>>; extensionASTNodes: ReadonlyArray; }; @@ -320,6 +326,7 @@ export interface GraphQLScalarTypeConfig { parseValue?: GraphQLScalarValueParser; // Parses an externally provided literal value to use as an input. parseLiteral?: GraphQLScalarLiteralParser; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -368,9 +375,10 @@ export class GraphQLObjectType< > { name: string; description: Maybe; + isTypeOf: Maybe>; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; - isTypeOf: Maybe>; constructor(config: GraphQLObjectTypeConfig); getFields(): GraphQLFieldMap; @@ -387,20 +395,27 @@ export class GraphQLObjectType< inspect(): string; } +export function argsToArgsConfig( + args: ReadonlyArray, +): GraphQLFieldConfigArgumentMap; + +// TS_SPECIFIC: TArgs export interface GraphQLObjectTypeConfig< TSource, TContext, TArgs = { [key: string]: any } > { name: string; + description?: Maybe; interfaces?: Thunk>; fields: Thunk>; isTypeOf?: Maybe>; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } +// TS_SPECIFIC: TArgs export type GraphQLTypeResolver< TSource, TContext, @@ -435,7 +450,7 @@ export interface GraphQLResolveInfo { readonly fieldNodes: ReadonlyArray; readonly returnType: GraphQLOutputType; readonly parentType: GraphQLObjectType; - readonly path: ResponsePath; + readonly path: Path; readonly schema: GraphQLSchema; readonly fragments: { [key: string]: FragmentDefinitionNode }; readonly rootValue: any; @@ -443,22 +458,18 @@ export interface GraphQLResolveInfo { 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; type: GraphQLOutputType; args?: GraphQLFieldConfigArgumentMap; resolve?: GraphQLFieldResolver; subscribe?: GraphQLFieldResolver; deprecationReason?: Maybe; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; } @@ -467,12 +478,14 @@ export type GraphQLFieldConfigArgumentMap = { }; export interface GraphQLArgumentConfig { + description?: Maybe; type: GraphQLInputType; defaultValue?: any; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; } +// TS_SPECIFIC: TArgs export type GraphQLFieldConfigMap< TSource, TContext, @@ -494,19 +507,22 @@ export interface GraphQLField< subscribe?: GraphQLFieldResolver; isDeprecated?: boolean; deprecationReason?: Maybe; + extensions: Maybe>>; astNode?: Maybe; } export interface GraphQLArgument { name: string; + description: Maybe; type: GraphQLInputType; - defaultValue?: any; - description?: Maybe; - astNode?: Maybe; + defaultValue: any; + extensions: Maybe>>; + astNode: Maybe; } export function isRequiredArgument(arg: GraphQLArgument): boolean; +// TS_SPECIFIC: TArgs export type GraphQLFieldMap< TSource, TContext, @@ -536,9 +552,10 @@ export type GraphQLFieldMap< export class GraphQLInterfaceType { name: string; description: Maybe; + resolveType: Maybe>; + extensions: Maybe>>; astNode?: Maybe; extensionASTNodes: Maybe>; - resolveType: Maybe>; constructor(config: GraphQLInterfaceTypeConfig); @@ -546,6 +563,7 @@ export class GraphQLInterfaceType { toConfig(): GraphQLInterfaceTypeConfig & { fields: GraphQLFieldConfigMap; + extensions: Maybe>>; extensionASTNodes: ReadonlyArray; }; @@ -554,12 +572,14 @@ export class GraphQLInterfaceType { inspect(): string; } +// TS_SPECIFIC: TArgs export interface GraphQLInterfaceTypeConfig< TSource, TContext, TArgs = { [key: string]: any } > { name: string; + description?: Maybe; fields: Thunk>; /** * Optionally provide a custom type resolver function. If one is not provided, @@ -567,7 +587,7 @@ export interface GraphQLInterfaceTypeConfig< * Object type. */ resolveType?: Maybe>; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -598,9 +618,10 @@ export interface GraphQLInterfaceTypeConfig< export class GraphQLUnionType { name: string; description: Maybe; + resolveType: Maybe>; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; - resolveType: Maybe>; constructor(config: GraphQLUnionTypeConfig); @@ -618,6 +639,7 @@ export class GraphQLUnionType { export interface GraphQLUnionTypeConfig { name: string; + description?: Maybe; types: Thunk; /** * Optionally provide a custom type resolver function. If one is not provided, @@ -625,7 +647,7 @@ export interface GraphQLUnionTypeConfig { * Object type. */ resolveType?: Maybe>; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -654,6 +676,7 @@ export interface GraphQLUnionTypeConfig { export class GraphQLEnumType { name: string; description: Maybe; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -678,8 +701,9 @@ export class GraphQLEnumType { export interface GraphQLEnumTypeConfig { name: string; - values: GraphQLEnumValueConfigMap; description?: Maybe; + values: GraphQLEnumValueConfigMap; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -689,19 +713,21 @@ export type GraphQLEnumValueConfigMap = { }; export interface GraphQLEnumValueConfig { + description?: Maybe; value?: any; deprecationReason?: Maybe; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; } export interface GraphQLEnumValue { name: string; description: Maybe; + value: any; isDeprecated?: boolean; deprecationReason: Maybe; + extensions: Maybe>>; astNode?: Maybe; - value: any; } /** @@ -727,6 +753,7 @@ export interface GraphQLEnumValue { export class GraphQLInputObjectType { name: string; description: Maybe; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; constructor(config: GraphQLInputObjectTypeConfig); @@ -734,6 +761,7 @@ export class GraphQLInputObjectType { toConfig(): GraphQLInputObjectTypeConfig & { fields: GraphQLInputFieldConfigMap; + extensions: Maybe>>; extensionASTNodes: ReadonlyArray; }; @@ -744,16 +772,18 @@ export class GraphQLInputObjectType { export interface GraphQLInputObjectTypeConfig { name: string; - fields: Thunk; description?: Maybe; + fields: Thunk; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } export interface GraphQLInputFieldConfig { + description?: Maybe; type: GraphQLInputType; defaultValue?: any; - description?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; } @@ -763,9 +793,10 @@ export type GraphQLInputFieldConfigMap = { export interface GraphQLInputField { name: string; + description?: Maybe; type: GraphQLInputType; defaultValue?: any; - description?: Maybe; + extensions: Maybe>>; astNode?: Maybe; } diff --git a/tstypes/type/directives.d.ts b/tstypes/type/directives.d.ts index c085aee35b..9719bf600e 100644 --- a/tstypes/type/directives.d.ts +++ b/tstypes/type/directives.d.ts @@ -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. @@ -18,12 +18,17 @@ export class GraphQLDirective { locations: DirectiveLocationEnum[]; isRepeatable: boolean; args: GraphQLArgument[]; + extensions?: Maybe>>; astNode: Maybe; constructor(config: GraphQLDirectiveConfig); + toString(): string; + toConfig(): GraphQLDirectiveConfig & { args: GraphQLFieldConfigArgumentMap; + extensions?: Maybe>>; + isRepeatable: boolean; }; } @@ -33,6 +38,7 @@ export interface GraphQLDirectiveConfig { locations: DirectiveLocationEnum[]; args?: Maybe; isRepeatable?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; } @@ -61,4 +67,6 @@ export const GraphQLDeprecatedDirective: GraphQLDirective; */ export const specifiedDirectives: ReadonlyArray; -export function isSpecifiedDirective(directive: GraphQLDirective): boolean; +export function isSpecifiedDirective( + directive: any, +): directive is GraphQLDirective; diff --git a/tstypes/type/index.d.ts b/tstypes/type/index.d.ts index 209582cb46..f991561a4d 100644 --- a/tstypes/type/index.d.ts +++ b/tstypes/type/index.d.ts @@ -1,6 +1,8 @@ export { // Predicate isSchema, + // Assertion + assertSchema, // GraphQL Schema definition GraphQLSchema, GraphQLSchemaConfig, @@ -90,7 +92,6 @@ export { GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, GraphQLResolveInfo, - ResponsePath, GraphQLScalarTypeConfig, GraphQLTypeResolver, GraphQLUnionTypeConfig, @@ -102,6 +103,8 @@ export { export { // Predicate isDirective, + // Assertion + assertDirective, // Directives Definition GraphQLDirective, // Built-in Directives defined by the Spec diff --git a/tstypes/type/introspection.d.ts b/tstypes/type/introspection.d.ts index 9a4dd874ed..3acfe6e210 100644 --- a/tstypes/type/introspection.d.ts +++ b/tstypes/type/introspection.d.ts @@ -1,14 +1,9 @@ import { - GraphQLScalarType, GraphQLObjectType, - GraphQLInterfaceType, - GraphQLUnionType, + GraphQLField, GraphQLEnumType, - GraphQLInputObjectType, - GraphQLList, - GraphQLNonNull, + GraphQLType, } from './definition'; -import { GraphQLField } from './definition'; export const __Schema: GraphQLObjectType; export const __Directive: GraphQLObjectType; @@ -40,6 +35,6 @@ export const SchemaMetaFieldDef: GraphQLField; export const TypeMetaFieldDef: GraphQLField; export const TypeNameMetaFieldDef: GraphQLField; -export const introspectionTypes: ReadonlyArray; +export const introspectionTypes: ReadonlyArray; export function isIntrospectionType(type: any): boolean; diff --git a/tstypes/type/scalars.d.ts b/tstypes/type/scalars.d.ts index 3cd8ad537c..fe16fd5cad 100644 --- a/tstypes/type/scalars.d.ts +++ b/tstypes/type/scalars.d.ts @@ -8,4 +8,4 @@ export const GraphQLID: GraphQLScalarType; export const specifiedScalarTypes: ReadonlyArray; -export function isSpecifiedScalarType(type: GraphQLScalarType): boolean; +export function isSpecifiedScalarType(type: any): type is GraphQLScalarType; diff --git a/tstypes/type/schema.d.ts b/tstypes/type/schema.d.ts index 749eae4a92..5cbddaed60 100644 --- a/tstypes/type/schema.d.ts +++ b/tstypes/type/schema.d.ts @@ -1,17 +1,18 @@ import Maybe from '../tsutils/Maybe'; -import { GraphQLObjectType } from './definition'; +import { SchemaDefinitionNode, SchemaExtensionNode } from '../language/ast'; +import { GraphQLDirective } from './directives'; import { GraphQLType, GraphQLNamedType, GraphQLAbstractType, + GraphQLObjectType, } from './definition'; -import { SchemaDefinitionNode, SchemaExtensionNode } from '../language/ast'; -import { GraphQLDirective } from './directives'; /** * Test if the given value is a GraphQL schema. */ export function isSchema(schema: any): schema is GraphQLSchema; +export function assertSchema(schema: any): GraphQLSchema; /** * Schema Definition @@ -40,6 +41,7 @@ export function isSchema(schema: any): schema is GraphQLSchema; * */ export class GraphQLSchema { + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -65,7 +67,10 @@ export class GraphQLSchema { toConfig(): GraphQLSchemaConfig & { types: GraphQLNamedType[]; directives: GraphQLDirective[]; + extensions: Maybe>>; extensionASTNodes: ReadonlyArray; + assumeValid: boolean; + allowedLegacyNames: ReadonlyArray; }; } @@ -97,6 +102,7 @@ export interface GraphQLSchemaConfig extends GraphQLSchemaValidationOptions { subscription?: Maybe; types?: Maybe; directives?: Maybe; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } diff --git a/tstypes/type/validate.d.ts b/tstypes/type/validate.d.ts index f6283f652a..9573befe3a 100644 --- a/tstypes/type/validate.d.ts +++ b/tstypes/type/validate.d.ts @@ -1,5 +1,5 @@ -import { GraphQLSchema } from './schema'; import { GraphQLError } from '../error/GraphQLError'; +import { GraphQLSchema } from './schema'; /** * Implements the "Type Validation" sub-sections of the specification's