From f3fb7b1b1c2b97c1d8ae4b3f0e61d8b04085b22f Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Fri, 28 Feb 2020 15:59:17 +0000 Subject: [PATCH 01/16] Change type of extensions from Record to extendable interfaces --- .eslintrc.yml | 2 +- src/type/definition.d.ts | 72 +++++++++++++++++++++++++--------------- src/type/index.d.ts | 10 ++++++ 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index ba6a67592c..74a3aef257 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -526,7 +526,7 @@ overrides: '@typescript-eslint/no-base-to-string': error '@typescript-eslint/no-confusing-non-null-assertion': error '@typescript-eslint/no-dynamic-delete': off - '@typescript-eslint/no-empty-interface': error + '@typescript-eslint/no-empty-interface': off '@typescript-eslint/no-explicit-any': off # TODO error '@typescript-eslint/no-extra-non-null-assertion': error '@typescript-eslint/no-extraneous-class': off # TODO consider diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index 7036861aab..007128501a 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -275,6 +275,8 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; */ export type Thunk = (() => T) | T; +export interface GraphQLScalarTypeExtensions {} + /** * Scalar Type Definition * @@ -299,7 +301,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -310,7 +312,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -340,11 +342,13 @@ export interface GraphQLScalarTypeConfig { parseValue?: GraphQLScalarValueParser; // Parses an externally provided literal value to use as an input. parseLiteral?: GraphQLScalarLiteralParser; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } +export interface GraphQLObjectTypeExtensions {} + /** * Object Type Definition * @@ -386,7 +390,7 @@ export class GraphQLObjectType { name: string; description: Maybe; isTypeOf: Maybe>; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -398,7 +402,7 @@ export class GraphQLObjectType { toConfig(): GraphQLObjectTypeConfig & { interfaces: Array; fields: GraphQLFieldConfigMap; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -417,7 +421,7 @@ export interface GraphQLObjectTypeConfig { interfaces?: Thunk>>; fields: Thunk>; isTypeOf?: Maybe>; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -459,6 +463,8 @@ export interface GraphQLResolveInfo { readonly variableValues: { [variableName: string]: any }; } +export interface GraphQLFieldExtensions {} + export interface GraphQLFieldConfig< TSource, TContext, @@ -470,7 +476,7 @@ export interface GraphQLFieldConfig< resolve?: GraphQLFieldResolver; subscribe?: GraphQLFieldResolver; deprecationReason?: Maybe; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; } @@ -478,11 +484,13 @@ export interface GraphQLFieldConfigArgumentMap { [key: string]: GraphQLArgumentConfig; } +export interface GraphQLArgumentExtensions {} + export interface GraphQLArgumentConfig { description?: Maybe; type: GraphQLInputType; defaultValue?: any; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; } @@ -503,7 +511,7 @@ export interface GraphQLField< subscribe?: GraphQLFieldResolver; isDeprecated: boolean; deprecationReason: Maybe; - extensions: Maybe>>; + extensions: Maybe>; astNode?: Maybe; } @@ -512,7 +520,7 @@ export interface GraphQLArgument { description: Maybe; type: GraphQLInputType; defaultValue: any; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; } @@ -522,6 +530,8 @@ export interface GraphQLFieldMap { [key: string]: GraphQLField; } +export interface GraphQLInterfaceTypeExtensions {} + /** * Interface Type Definition * @@ -544,7 +554,7 @@ export class GraphQLInterfaceType { name: string; description: Maybe; resolveType: Maybe>; - extensions: Maybe>>; + extensions: Maybe>; astNode?: Maybe; extensionASTNodes: Maybe>; @@ -555,7 +565,7 @@ export class GraphQLInterfaceType { toConfig(): GraphQLInterfaceTypeConfig & { interfaces: Array; fields: GraphQLFieldConfigMap; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -575,11 +585,13 @@ export interface GraphQLInterfaceTypeConfig { * Object type. */ resolveType?: Maybe>; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } +export interface GraphQLUnionTypeExtensions {} + /** * Union Type Definition * @@ -607,7 +619,7 @@ export class GraphQLUnionType { name: string; description: Maybe; resolveType: Maybe>; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -616,7 +628,7 @@ export class GraphQLUnionType { toConfig(): GraphQLUnionTypeConfig & { types: Array; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -635,11 +647,13 @@ export interface GraphQLUnionTypeConfig { * Object type. */ resolveType?: Maybe>; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } +export interface GraphQLEnumTypeExtensions {} + /** * Enum Type Definition * @@ -664,7 +678,7 @@ export interface GraphQLUnionTypeConfig { export class GraphQLEnumType { name: string; description: Maybe; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -679,7 +693,7 @@ export class GraphQLEnumType { ): Maybe; toConfig(): GraphQLEnumTypeConfig & { - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -692,7 +706,7 @@ export interface GraphQLEnumTypeConfig { name: string; description?: Maybe; values: GraphQLEnumValueConfigMap; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -701,11 +715,13 @@ export interface GraphQLEnumValueConfigMap { [key: string]: GraphQLEnumValueConfig; } +export interface GraphQLEnumValueExtensions {} + export interface GraphQLEnumValueConfig { description?: Maybe; value?: any; deprecationReason?: Maybe; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; } @@ -715,10 +731,12 @@ export interface GraphQLEnumValue { value: any; isDeprecated: boolean; deprecationReason: Maybe; - extensions: Maybe>>; + extensions: Maybe>; astNode?: Maybe; } +export interface GraphQLInputObjectTypeExtensions {} + /** * Input Object Type Definition * @@ -742,7 +760,7 @@ export interface GraphQLEnumValue { export class GraphQLInputObjectType { name: string; description: Maybe; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -751,7 +769,7 @@ export class GraphQLInputObjectType { toConfig(): GraphQLInputObjectTypeConfig & { fields: GraphQLInputFieldConfigMap; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; }; @@ -764,16 +782,18 @@ export interface GraphQLInputObjectTypeConfig { name: string; description?: Maybe; fields: Thunk; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } +export interface GraphQLInputFieldExtensions {} + export interface GraphQLInputFieldConfig { description?: Maybe; type: GraphQLInputType; defaultValue?: any; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; } @@ -786,7 +806,7 @@ export interface GraphQLInputField { description?: Maybe; type: GraphQLInputType; defaultValue?: any; - extensions: Maybe>>; + extensions: Maybe>; astNode?: Maybe; } diff --git a/src/type/index.d.ts b/src/type/index.d.ts index 3454d8e36b..111d9662f6 100644 --- a/src/type/index.d.ts +++ b/src/type/index.d.ts @@ -75,28 +75,38 @@ export { Thunk, GraphQLArgument, GraphQLArgumentConfig, + GraphQLArgumentExtensions, GraphQLEnumTypeConfig, + GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, GraphQLEnumValueConfigMap, + GraphQLEnumValueExtensions, GraphQLField, GraphQLFieldConfig, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, + GraphQLFieldExtensions, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, + GraphQLInputFieldExtensions, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, + GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, + GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, + GraphQLObjectTypeExtensions, GraphQLResolveInfo, GraphQLScalarTypeConfig, + GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, + GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, From eaf61b0fd20a93003353cd278bcd2a621d003910 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 11 Mar 2020 12:29:33 +0000 Subject: [PATCH 02/16] Add index signature to extension types --- src/type/definition.d.ts | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index 007128501a..fe99e5ffe5 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -275,7 +275,9 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; */ export type Thunk = (() => T) | T; -export interface GraphQLScalarTypeExtensions {} +export interface GraphQLScalarTypeExtensions { + [attributeName: string]: unknown; +} /** * Scalar Type Definition @@ -347,7 +349,9 @@ export interface GraphQLScalarTypeConfig { extensionASTNodes?: Maybe>; } -export interface GraphQLObjectTypeExtensions {} +export interface GraphQLObjectTypeExtensions { + [attributeName: string]: unknown; +} /** * Object Type Definition @@ -463,7 +467,9 @@ export interface GraphQLResolveInfo { readonly variableValues: { [variableName: string]: any }; } -export interface GraphQLFieldExtensions {} +export interface GraphQLFieldExtensions { + [attributeName: string]: unknown; +} export interface GraphQLFieldConfig< TSource, @@ -484,7 +490,9 @@ export interface GraphQLFieldConfigArgumentMap { [key: string]: GraphQLArgumentConfig; } -export interface GraphQLArgumentExtensions {} +export interface GraphQLArgumentExtensions { + [attributeName: string]: unknown; +} export interface GraphQLArgumentConfig { description?: Maybe; @@ -530,7 +538,9 @@ export interface GraphQLFieldMap { [key: string]: GraphQLField; } -export interface GraphQLInterfaceTypeExtensions {} +export interface GraphQLInterfaceTypeExtensions { + [attributeName: string]: unknown; +} /** * Interface Type Definition @@ -590,7 +600,9 @@ export interface GraphQLInterfaceTypeConfig { extensionASTNodes?: Maybe>; } -export interface GraphQLUnionTypeExtensions {} +export interface GraphQLUnionTypeExtensions { + [attributeName: string]: unknown; +} /** * Union Type Definition @@ -652,7 +664,9 @@ export interface GraphQLUnionTypeConfig { extensionASTNodes?: Maybe>; } -export interface GraphQLEnumTypeExtensions {} +export interface GraphQLEnumTypeExtensions { + [attributeName: string]: unknown; +} /** * Enum Type Definition @@ -715,7 +729,9 @@ export interface GraphQLEnumValueConfigMap { [key: string]: GraphQLEnumValueConfig; } -export interface GraphQLEnumValueExtensions {} +export interface GraphQLEnumValueExtensions { + [attributeName: string]: unknown; +} export interface GraphQLEnumValueConfig { description?: Maybe; @@ -735,7 +751,9 @@ export interface GraphQLEnumValue { astNode?: Maybe; } -export interface GraphQLInputObjectTypeExtensions {} +export interface GraphQLInputObjectTypeExtensions { + [attributeName: string]: unknown; +} /** * Input Object Type Definition @@ -787,7 +805,9 @@ export interface GraphQLInputObjectTypeConfig { extensionASTNodes?: Maybe>; } -export interface GraphQLInputFieldExtensions {} +export interface GraphQLInputFieldExtensions { + [attributeName: string]: unknown; +} export interface GraphQLInputFieldConfig { description?: Maybe; From 598c26d586a777da5fd75e8bc3ad81a5668b04d8 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 11 Mar 2020 12:36:09 +0000 Subject: [PATCH 03/16] Revert ESLint change --- .eslintrc.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 74a3aef257..ba6a67592c 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -526,7 +526,7 @@ overrides: '@typescript-eslint/no-base-to-string': error '@typescript-eslint/no-confusing-non-null-assertion': error '@typescript-eslint/no-dynamic-delete': off - '@typescript-eslint/no-empty-interface': off + '@typescript-eslint/no-empty-interface': error '@typescript-eslint/no-explicit-any': off # TODO error '@typescript-eslint/no-extra-non-null-assertion': error '@typescript-eslint/no-extraneous-class': off # TODO consider From 28be6e906f891aa217aa56619a4e7f32f9075184 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 11 Mar 2020 15:45:18 +0000 Subject: [PATCH 04/16] unknown -> any --- src/type/definition.d.ts | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index fe99e5ffe5..ea9c3e2884 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -276,7 +276,7 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; export type Thunk = (() => T) | T; export interface GraphQLScalarTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -350,7 +350,7 @@ export interface GraphQLScalarTypeConfig { } export interface GraphQLObjectTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -468,7 +468,7 @@ export interface GraphQLResolveInfo { } export interface GraphQLFieldExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } export interface GraphQLFieldConfig< @@ -491,7 +491,7 @@ export interface GraphQLFieldConfigArgumentMap { } export interface GraphQLArgumentExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } export interface GraphQLArgumentConfig { @@ -539,7 +539,7 @@ export interface GraphQLFieldMap { } export interface GraphQLInterfaceTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -601,7 +601,7 @@ export interface GraphQLInterfaceTypeConfig { } export interface GraphQLUnionTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -665,7 +665,7 @@ export interface GraphQLUnionTypeConfig { } export interface GraphQLEnumTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -730,7 +730,7 @@ export interface GraphQLEnumValueConfigMap { } export interface GraphQLEnumValueExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } export interface GraphQLEnumValueConfig { @@ -752,7 +752,7 @@ export interface GraphQLEnumValue { } export interface GraphQLInputObjectTypeExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } /** @@ -806,7 +806,7 @@ export interface GraphQLInputObjectTypeConfig { } export interface GraphQLInputFieldExtensions { - [attributeName: string]: unknown; + [attributeName: string]: any; } export interface GraphQLInputFieldConfig { From 7e2e0fbcc201bf23002b2f87b3f4ecfdca27cf16 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 3 Jun 2020 17:01:17 +0100 Subject: [PATCH 05/16] Add named flow typings for extensions --- src/type/definition.js | 72 +++++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/src/type/definition.js b/src/type/definition.js index ab94313263..d2a0c0d98c 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -548,6 +548,8 @@ function undefineIfEmpty(arr: ?$ReadOnlyArray): ?$ReadOnlyArray { return arr && arr.length > 0 ? arr : undefined; } +export type GraphQLScalarTypeExtensions = ReadOnlyObjMap; + /** * Scalar Type Definition * @@ -579,7 +581,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLScalarTypeExtensions; astNode: ?ScalarTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -624,7 +626,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer, parseValue: GraphQLScalarValueParser, parseLiteral: GraphQLScalarLiteralParser, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLScalarTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -680,11 +682,13 @@ export type GraphQLScalarTypeConfig = {| parseValue?: GraphQLScalarValueParser, // Parses an externally provided literal value to use as an input. parseLiteral?: GraphQLScalarLiteralParser, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLScalarTypeExtensions, astNode?: ?ScalarTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; +export type GraphQLObjectTypeExtensions = ReadOnlyObjMap; + /** * Object Type Definition * @@ -726,7 +730,7 @@ export class GraphQLObjectType { name: string; description: ?string; isTypeOf: ?GraphQLIsTypeOfFn; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLObjectTypeExtensions; astNode: ?ObjectTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -769,7 +773,7 @@ export class GraphQLObjectType { ...GraphQLObjectTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLObjectTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -914,7 +918,7 @@ export type GraphQLObjectTypeConfig = {| interfaces?: Thunk>, fields: Thunk>, isTypeOf?: ?GraphQLIsTypeOfFn, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLObjectTypeExtensions, astNode?: ?ObjectTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -967,7 +971,7 @@ export type GraphQLFieldConfig< resolve?: GraphQLFieldResolver, subscribe?: GraphQLFieldResolver, deprecationReason?: ?string, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLFieldExtensions, astNode?: ?FieldDefinitionNode, |}; @@ -977,7 +981,7 @@ export type GraphQLArgumentConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLArgumentExtensions, astNode?: ?InputValueDefinitionNode, |}; @@ -985,6 +989,8 @@ export type GraphQLFieldConfigMap = ObjMap< GraphQLFieldConfig, >; +export type GraphQLFieldExtensions = ReadOnlyObjMap; + export type GraphQLField< TSource, TContext, @@ -998,16 +1004,18 @@ export type GraphQLField< subscribe?: GraphQLFieldResolver, isDeprecated: boolean, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLFieldExtensions, astNode: ?FieldDefinitionNode, |}; +export type GraphQLArgumentExtensions = ReadOnlyObjMap; + export type GraphQLArgument = {| name: string, description: ?string, type: GraphQLInputType, defaultValue: mixed, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLArgumentExtensions, astNode: ?InputValueDefinitionNode, |}; @@ -1019,6 +1027,8 @@ export type GraphQLFieldMap = ObjMap< GraphQLField, >; +export type GraphQLInterfaceTypeExtensions = ReadOnlyObjMap; + /** * Interface Type Definition * @@ -1041,7 +1051,7 @@ export class GraphQLInterfaceType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLInterfaceTypeExtensions; astNode: ?InterfaceTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1084,7 +1094,7 @@ export class GraphQLInterfaceType { ...GraphQLInterfaceTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLInterfaceTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -1127,11 +1137,13 @@ export type GraphQLInterfaceTypeConfig = {| * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLInterfaceTypeExtensions, astNode?: ?InterfaceTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; +export type GraphQLUnionTypeExtensions = ReadOnlyObjMap; + /** * Union Type Definition * @@ -1159,7 +1171,7 @@ export class GraphQLUnionType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLUnionTypeExtensions; astNode: ?UnionTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1192,7 +1204,7 @@ export class GraphQLUnionType { toConfig(): {| ...GraphQLUnionTypeConfig, types: Array, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLUnionTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -1244,11 +1256,13 @@ export type GraphQLUnionTypeConfig = {| * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLUnionTypeExtensions, astNode?: ?UnionTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; +export type GraphQLEnumTypeExtensions = ReadOnlyObjMap; + /** * Enum Type Definition * @@ -1273,7 +1287,7 @@ export type GraphQLUnionTypeConfig = {| export class GraphQLEnumType /* */ { name: string; description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLEnumTypeExtensions; astNode: ?EnumTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1359,7 +1373,7 @@ export class GraphQLEnumType /* */ { toConfig(): {| ...GraphQLEnumTypeConfig, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLEnumTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { const values = keyValMap( @@ -1445,7 +1459,7 @@ export type GraphQLEnumTypeConfig /* */ = {| name: string, description?: ?string, values: GraphQLEnumValueConfigMap /* */, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLEnumTypeExtensions, astNode?: ?EnumTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -1456,20 +1470,24 @@ export type GraphQLEnumValueConfig /* */ = {| description?: ?string, value?: any /* T */, deprecationReason?: ?string, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLEnumValueExtensions, astNode?: ?EnumValueDefinitionNode, |}; +export type GraphQLEnumValueExtensions = ReadOnlyObjMap; + export type GraphQLEnumValue /* */ = {| name: string, description: ?string, value: any /* T */, isDeprecated: boolean, deprecationReason: ?string, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLEnumValueExtensions, astNode: ?EnumValueDefinitionNode, |}; +export type GraphQLInputObjectTypeExtensions = ReadOnlyObjMap; + /** * Input Object Type Definition * @@ -1493,7 +1511,7 @@ export type GraphQLEnumValue /* */ = {| export class GraphQLInputObjectType { name: string; description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLInputObjectTypeExtensions; astNode: ?InputObjectTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1520,7 +1538,7 @@ export class GraphQLInputObjectType { toConfig(): {| ...GraphQLInputObjectTypeConfig, fields: GraphQLInputFieldConfigMap, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLInputObjectTypeExtensions, extensionASTNodes: $ReadOnlyArray, |} { const fields = mapValue(this.getFields(), (field) => ({ @@ -1587,7 +1605,7 @@ export type GraphQLInputObjectTypeConfig = {| name: string, description?: ?string, fields: Thunk, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLInputObjectTypeExtensions, astNode?: ?InputObjectTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -1596,18 +1614,20 @@ export type GraphQLInputFieldConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLInputFieldExtensions, astNode?: ?InputValueDefinitionNode, |}; export type GraphQLInputFieldConfigMap = ObjMap; +export type GraphQLInputFieldExtensions = ReadOnlyObjMap; + export type GraphQLInputField = {| name: string, description: ?string, type: GraphQLInputType, defaultValue: mixed, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLInputFieldExtensions, astNode: ?InputValueDefinitionNode, |}; From 8791f1e1ec52452cbb6f0bc7f3b1d8659a47c0d9 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 3 Jun 2020 17:20:25 +0100 Subject: [PATCH 06/16] Also export in src/index.d.ts --- src/index.d.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/index.d.ts b/src/index.d.ts index 14a1551b4f..ea200af1fb 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -142,29 +142,39 @@ export { GraphQLDirectiveConfig, GraphQLArgument, GraphQLArgumentConfig, + GraphQLArgumentExtensions, GraphQLEnumTypeConfig, + GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, + GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, GraphQLField, GraphQLFieldConfig, + GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, + GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, + GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, + GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, + GraphQLObjectTypeExtensions, GraphQLResolveInfo, ResponsePath, GraphQLScalarTypeConfig, + GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, + GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, From 3efe79290c13041ffb44cca7c08c9c3c28937982 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 3 Jun 2020 17:25:24 +0100 Subject: [PATCH 07/16] Apply the changes to GraphQLSchema and GraphQLDirective --- src/index.d.ts | 2 ++ src/type/directives.d.ts | 11 ++++++++--- src/type/index.d.ts | 2 ++ src/type/schema.d.ts | 12 ++++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/index.d.ts b/src/index.d.ts index ea200af1fb..7ef7b650bc 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -139,7 +139,9 @@ export { GraphQLNamedType, Thunk, GraphQLSchemaConfig, + GraphQLSchemaExtensions, GraphQLDirectiveConfig, + GraphQLDirectiveExtensions, GraphQLArgument, GraphQLArgumentConfig, GraphQLArgumentExtensions, diff --git a/src/type/directives.d.ts b/src/type/directives.d.ts index 0d062e6a9c..d61759b2ed 100644 --- a/src/type/directives.d.ts +++ b/src/type/directives.d.ts @@ -13,6 +13,11 @@ import { GraphQLFieldConfigArgumentMap, GraphQLArgument } from './definition'; */ export function isDirective(directive: any): directive is GraphQLDirective; export function assertDirective(directive: any): GraphQLDirective; + +export interface GraphQLDirectiveExtensions { + [attributeName: string]: any; +} + /** * Directives are used by the GraphQL runtime as a way of modifying execution * behavior. Type system creators will usually not create these directly. @@ -23,7 +28,7 @@ export class GraphQLDirective { locations: Array; isRepeatable: boolean; args: Array; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; constructor(config: Readonly); @@ -31,7 +36,7 @@ export class GraphQLDirective { toConfig(): GraphQLDirectiveConfig & { args: GraphQLFieldConfigArgumentMap; isRepeatable: boolean; - extensions: Maybe>>; + extensions: Maybe>; }; toString(): string; @@ -45,7 +50,7 @@ export interface GraphQLDirectiveConfig { locations: Array; args?: Maybe; isRepeatable?: Maybe; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; } diff --git a/src/type/index.d.ts b/src/type/index.d.ts index 111d9662f6..9686f413b7 100644 --- a/src/type/index.d.ts +++ b/src/type/index.d.ts @@ -8,6 +8,7 @@ export { // GraphQL Schema definition GraphQLSchema, GraphQLSchemaConfig, + GraphQLSchemaExtensions, } from './schema'; export { @@ -130,6 +131,7 @@ export { DEFAULT_DEPRECATION_REASON, // type GraphQLDirectiveConfig, + GraphQLDirectiveExtensions, } from './directives'; // Common built-in scalar instances. diff --git a/src/type/schema.d.ts b/src/type/schema.d.ts index 1ae844362a..09fcfb9095 100644 --- a/src/type/schema.d.ts +++ b/src/type/schema.d.ts @@ -19,6 +19,10 @@ import { export function isSchema(schema: any): schema is GraphQLSchema; export function assertSchema(schema: any): GraphQLSchema; +export interface GraphQLSchemaExtensions { + [attributeName: string]: any; +} + /** * Schema Definition * @@ -47,7 +51,7 @@ export function assertSchema(schema: any): GraphQLSchema; */ export class GraphQLSchema { description: Maybe; - extensions: Maybe>>; + extensions: Maybe>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -83,7 +87,7 @@ export class GraphQLSchema { toConfig(): GraphQLSchemaConfig & { types: Array; directives: Array; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: ReadonlyArray; assumeValid: boolean; }; @@ -116,7 +120,7 @@ export interface GraphQLSchemaConfig extends GraphQLSchemaValidationOptions { subscription?: Maybe; types?: Maybe>; directives?: Maybe>; - extensions?: Maybe>>; + extensions?: Maybe>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -128,7 +132,7 @@ export interface GraphQLSchemaNormalizedConfig extends GraphQLSchemaConfig { description: Maybe; types: Array; directives: Array; - extensions: Maybe>>; + extensions: Maybe>; extensionASTNodes: Maybe>; assumeValid: boolean; } From 17b7d6bdda157c0e5da0405c208521a31dce90d9 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 3 Jun 2020 17:31:31 +0100 Subject: [PATCH 08/16] Mirror to flow --- src/index.js | 12 ++++++++++++ src/type/directives.js | 8 +++++--- src/type/index.js | 17 +++++++++++++++-- src/type/schema.js | 8 +++++--- 4 files changed, 37 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 8e2d9f4dd4..a7b9f744be 100644 --- a/src/index.js +++ b/src/index.js @@ -140,32 +140,44 @@ export type { GraphQLNamedType, Thunk, GraphQLSchemaConfig, + GraphQLSchemaExtensions, GraphQLDirectiveConfig, + GraphQLDirectiveExtensions, GraphQLArgument, GraphQLArgumentConfig, + GraphQLArgumentExtensions, GraphQLEnumTypeConfig, + GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, + GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, GraphQLField, GraphQLFieldConfig, + GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, + GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, + GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, + GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, + GraphQLObjectTypeExtensions, GraphQLResolveInfo, ResponsePath, GraphQLScalarTypeConfig, + GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, + GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, diff --git a/src/type/directives.js b/src/type/directives.js index b5074b8266..ee17b1b4fe 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -42,6 +42,8 @@ export function assertDirective(directive: mixed): GraphQLDirective { return directive; } +export type GraphQLDirectiveExtensions = ReadOnlyObjMap; + /** * Directives are used by the GraphQL runtime as a way of modifying execution * behavior. Type system creators will usually not create these directly. @@ -52,7 +54,7 @@ export class GraphQLDirective { locations: Array; args: Array; isRepeatable: boolean; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLDirectiveExtensions; astNode: ?DirectiveDefinitionNode; constructor(config: $ReadOnly): void { @@ -89,7 +91,7 @@ export class GraphQLDirective { ...GraphQLDirectiveConfig, args: GraphQLFieldConfigArgumentMap, isRepeatable: boolean, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLDirectiveExtensions, |} { return { name: this.name, @@ -125,7 +127,7 @@ export type GraphQLDirectiveConfig = {| locations: Array, args?: ?GraphQLFieldConfigArgumentMap, isRepeatable?: ?boolean, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLDirectiveExtensions, astNode?: ?DirectiveDefinitionNode, |}; diff --git a/src/type/index.js b/src/type/index.js index d15378b6cc..1199f96cfe 100644 --- a/src/type/index.js +++ b/src/type/index.js @@ -10,7 +10,7 @@ export { // GraphQL Schema definition GraphQLSchema, } from './schema'; -export type { GraphQLSchemaConfig } from './schema'; +export type { GraphQLSchemaConfig, GraphQLSchemaExtensions } from './schema'; export { // Predicates @@ -84,7 +84,10 @@ export { DEFAULT_DEPRECATION_REASON, } from './directives'; -export type { GraphQLDirectiveConfig } from './directives'; +export type { + GraphQLDirectiveConfig, + GraphQLDirectiveExtensions, +} from './directives'; // Common built-in scalar instances. export { @@ -133,28 +136,38 @@ export type { Thunk, GraphQLArgument, GraphQLArgumentConfig, + GraphQLArgumentExtensions, GraphQLEnumTypeConfig, + GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, + GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, GraphQLField, GraphQLFieldConfig, + GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, + GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, + GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, + GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, + GraphQLObjectTypeExtensions, GraphQLResolveInfo, GraphQLScalarTypeConfig, + GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, + GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, diff --git a/src/type/schema.js b/src/type/schema.js index 44d8c77262..0ee1e7cdc5 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -61,6 +61,8 @@ export function assertSchema(schema: mixed): GraphQLSchema { return schema; } +export type GraphQLSchemaExtensions = ReadOnlyObjMap; + /** * Schema Definition * @@ -126,7 +128,7 @@ export function assertSchema(schema: mixed): GraphQLSchema { */ export class GraphQLSchema { description: ?string; - extensions: ?ReadOnlyObjMap; + extensions: ?GraphQLSchemaExtensions; astNode: ?SchemaDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -383,7 +385,7 @@ export type GraphQLSchemaConfig = {| subscription?: ?GraphQLObjectType, types?: ?Array, directives?: ?Array, - extensions?: ?ReadOnlyObjMapLike, + extensions?: ?GraphQLSchemaExtensions, astNode?: ?SchemaDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, ...GraphQLSchemaValidationOptions, @@ -397,7 +399,7 @@ export type GraphQLSchemaNormalizedConfig = {| description: ?string, types: Array, directives: Array, - extensions: ?ReadOnlyObjMap, + extensions: ?GraphQLSchemaExtensions, extensionASTNodes: $ReadOnlyArray, assumeValid: boolean, |}; From c72abfbae5335ea0c21cb4e773d4a9d95be461ac Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 3 Jun 2020 17:42:55 +0100 Subject: [PATCH 09/16] Add a note not to conflict with other projects --- src/type/definition.d.ts | 40 ++++++++++++++++++++++++++++++++++++++++ src/type/directives.d.ts | 4 ++++ src/type/schema.d.ts | 4 ++++ 3 files changed, 48 insertions(+) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index ea9c3e2884..f5134d19ae 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -275,6 +275,10 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; */ export type Thunk = (() => T) | T; +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLScalarTypeExtensions { [attributeName: string]: any; } @@ -349,6 +353,10 @@ export interface GraphQLScalarTypeConfig { extensionASTNodes?: Maybe>; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLObjectTypeExtensions { [attributeName: string]: any; } @@ -467,6 +475,10 @@ export interface GraphQLResolveInfo { readonly variableValues: { [variableName: string]: any }; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLFieldExtensions { [attributeName: string]: any; } @@ -490,6 +502,10 @@ export interface GraphQLFieldConfigArgumentMap { [key: string]: GraphQLArgumentConfig; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLArgumentExtensions { [attributeName: string]: any; } @@ -538,6 +554,10 @@ export interface GraphQLFieldMap { [key: string]: GraphQLField; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLInterfaceTypeExtensions { [attributeName: string]: any; } @@ -600,6 +620,10 @@ export interface GraphQLInterfaceTypeConfig { extensionASTNodes?: Maybe>; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLUnionTypeExtensions { [attributeName: string]: any; } @@ -664,6 +688,10 @@ export interface GraphQLUnionTypeConfig { extensionASTNodes?: Maybe>; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLEnumTypeExtensions { [attributeName: string]: any; } @@ -729,6 +757,10 @@ export interface GraphQLEnumValueConfigMap { [key: string]: GraphQLEnumValueConfig; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLEnumValueExtensions { [attributeName: string]: any; } @@ -751,6 +783,10 @@ export interface GraphQLEnumValue { astNode?: Maybe; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLInputObjectTypeExtensions { [attributeName: string]: any; } @@ -805,6 +841,10 @@ export interface GraphQLInputObjectTypeConfig { extensionASTNodes?: Maybe>; } +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLInputFieldExtensions { [attributeName: string]: any; } diff --git a/src/type/directives.d.ts b/src/type/directives.d.ts index d61759b2ed..6250ecc5b4 100644 --- a/src/type/directives.d.ts +++ b/src/type/directives.d.ts @@ -14,6 +14,10 @@ import { GraphQLFieldConfigArgumentMap, GraphQLArgument } from './definition'; export function isDirective(directive: any): directive is GraphQLDirective; export function assertDirective(directive: any): GraphQLDirective; +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLDirectiveExtensions { [attributeName: string]: any; } diff --git a/src/type/schema.d.ts b/src/type/schema.d.ts index 09fcfb9095..ba38ef7c85 100644 --- a/src/type/schema.d.ts +++ b/src/type/schema.d.ts @@ -19,6 +19,10 @@ import { export function isSchema(schema: any): schema is GraphQLSchema; export function assertSchema(schema: any): GraphQLSchema; +/** + * It's strongly recommended that you prefix each added attribute's name with an + * identifier unique to your project to avoid conflicts with other projects. + */ export interface GraphQLSchemaExtensions { [attributeName: string]: any; } From 8bd6f832489d384d0c01c40c85b5b813ecc457ca Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 20 Jun 2020 10:56:58 +0100 Subject: [PATCH 10/16] Make Extensions types generic where appropriate --- src/type/definition.d.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index f5134d19ae..a4d8e0a7d5 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -357,7 +357,7 @@ export interface GraphQLScalarTypeConfig { * It's strongly recommended that you prefix each added attribute's name with an * identifier unique to your project to avoid conflicts with other projects. */ -export interface GraphQLObjectTypeExtensions { +export interface GraphQLObjectTypeExtensions { [attributeName: string]: any; } @@ -402,7 +402,7 @@ export class GraphQLObjectType { name: string; description: Maybe; isTypeOf: Maybe>; - extensions: Maybe>; + extensions: Maybe>>; astNode: Maybe; extensionASTNodes: Maybe>; @@ -414,7 +414,7 @@ export class GraphQLObjectType { toConfig(): GraphQLObjectTypeConfig & { interfaces: Array; fields: GraphQLFieldConfigMap; - extensions: Maybe>; + extensions: Maybe>>; extensionASTNodes: ReadonlyArray; }; @@ -433,7 +433,7 @@ export interface GraphQLObjectTypeConfig { interfaces?: Thunk>>; fields: Thunk>; isTypeOf?: Maybe>; - extensions?: Maybe>; + extensions?: Maybe>>; astNode?: Maybe; extensionASTNodes?: Maybe>; } @@ -479,7 +479,11 @@ export interface GraphQLResolveInfo { * It's strongly recommended that you prefix each added attribute's name with an * identifier unique to your project to avoid conflicts with other projects. */ -export interface GraphQLFieldExtensions { +export interface GraphQLFieldExtensions< + TSource, + TContext, + TArgs = { [argName: string]: any } +> { [attributeName: string]: any; } @@ -494,7 +498,9 @@ export interface GraphQLFieldConfig< resolve?: GraphQLFieldResolver; subscribe?: GraphQLFieldResolver; deprecationReason?: Maybe; - extensions?: Maybe>; + extensions?: Maybe< + Readonly> + >; astNode?: Maybe; } @@ -535,7 +541,7 @@ export interface GraphQLField< subscribe?: GraphQLFieldResolver; isDeprecated: boolean; deprecationReason: Maybe; - extensions: Maybe>; + extensions: Maybe>>; astNode?: Maybe; } From c6098399d94f78fe2c453e29b9a8ab3e2e476468 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 20 Jun 2020 11:07:04 +0100 Subject: [PATCH 11/16] Update comment. --- src/type/definition.d.ts | 90 +++++++++++++++++++++++++++++++--------- src/type/directives.d.ts | 9 +++- src/type/schema.d.ts | 9 +++- 3 files changed, 84 insertions(+), 24 deletions(-) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index a4d8e0a7d5..bc793722f7 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -276,8 +276,13 @@ export function getNamedType(type: GraphQLType): GraphQLNamedType; export type Thunk = (() => T) | T; /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLScalarTypeExtensions { [attributeName: string]: any; @@ -354,8 +359,13 @@ export interface GraphQLScalarTypeConfig { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLObjectTypeExtensions { [attributeName: string]: any; @@ -476,8 +486,13 @@ export interface GraphQLResolveInfo { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLFieldExtensions< TSource, @@ -509,8 +524,13 @@ export interface GraphQLFieldConfigArgumentMap { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLArgumentExtensions { [attributeName: string]: any; @@ -561,8 +581,13 @@ export interface GraphQLFieldMap { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLInterfaceTypeExtensions { [attributeName: string]: any; @@ -627,8 +652,13 @@ export interface GraphQLInterfaceTypeConfig { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLUnionTypeExtensions { [attributeName: string]: any; @@ -695,8 +725,13 @@ export interface GraphQLUnionTypeConfig { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLEnumTypeExtensions { [attributeName: string]: any; @@ -764,8 +799,13 @@ export interface GraphQLEnumValueConfigMap { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLEnumValueExtensions { [attributeName: string]: any; @@ -790,8 +830,13 @@ export interface GraphQLEnumValue { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLInputObjectTypeExtensions { [attributeName: string]: any; @@ -848,8 +893,13 @@ export interface GraphQLInputObjectTypeConfig { } /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLInputFieldExtensions { [attributeName: string]: any; diff --git a/src/type/directives.d.ts b/src/type/directives.d.ts index 6250ecc5b4..2c6de77b1d 100644 --- a/src/type/directives.d.ts +++ b/src/type/directives.d.ts @@ -15,8 +15,13 @@ export function isDirective(directive: any): directive is GraphQLDirective; export function assertDirective(directive: any): GraphQLDirective; /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLDirectiveExtensions { [attributeName: string]: any; diff --git a/src/type/schema.d.ts b/src/type/schema.d.ts index ba38ef7c85..4f759f9f27 100644 --- a/src/type/schema.d.ts +++ b/src/type/schema.d.ts @@ -20,8 +20,13 @@ export function isSchema(schema: any): schema is GraphQLSchema; export function assertSchema(schema: any): GraphQLSchema; /** - * It's strongly recommended that you prefix each added attribute's name with an - * identifier unique to your project to avoid conflicts with other projects. + * Custom extensions + * + * @remarks + * Use a unique identifier name for your extension, for example the name of + * your library or project. Do not use a shortened identifier as this increases + * the risk of conflicts. We recommend you add at most one extension field, + * an object which can contain all the values you need. */ export interface GraphQLSchemaExtensions { [attributeName: string]: any; From aa6ddc64102d59256cd4967215a4d3f23d40fca3 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 20 Jun 2020 11:10:13 +0100 Subject: [PATCH 12/16] Why template arguments? --- src/type/definition.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/type/definition.d.ts b/src/type/definition.d.ts index bc793722f7..aa3177a69d 100644 --- a/src/type/definition.d.ts +++ b/src/type/definition.d.ts @@ -366,6 +366,9 @@ export interface GraphQLScalarTypeConfig { * your library or project. Do not use a shortened identifier as this increases * the risk of conflicts. We recommend you add at most one extension field, * an object which can contain all the values you need. + * + * We've provided these template arguments because this is an open type and + * you may find them useful. */ export interface GraphQLObjectTypeExtensions { [attributeName: string]: any; @@ -493,6 +496,9 @@ export interface GraphQLResolveInfo { * your library or project. Do not use a shortened identifier as this increases * the risk of conflicts. We recommend you add at most one extension field, * an object which can contain all the values you need. + * + * We've provided these template arguments because this is an open type and + * you may find them useful. */ export interface GraphQLFieldExtensions< TSource, From 2dbc5ca4c168fe0c2aa44586ef8f9239b1f2bca4 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 20 Jun 2020 11:11:35 +0100 Subject: [PATCH 13/16] Revert named extension types in Flow --- src/index.js | 12 ------- src/type/definition.js | 72 +++++++++++++++--------------------------- src/type/directives.js | 8 ++--- src/type/index.js | 17 ++-------- src/type/schema.js | 8 ++--- 5 files changed, 34 insertions(+), 83 deletions(-) diff --git a/src/index.js b/src/index.js index a7b9f744be..8e2d9f4dd4 100644 --- a/src/index.js +++ b/src/index.js @@ -140,44 +140,32 @@ export type { GraphQLNamedType, Thunk, GraphQLSchemaConfig, - GraphQLSchemaExtensions, GraphQLDirectiveConfig, - GraphQLDirectiveExtensions, GraphQLArgument, GraphQLArgumentConfig, - GraphQLArgumentExtensions, GraphQLEnumTypeConfig, - GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, - GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, GraphQLField, GraphQLFieldConfig, - GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, - GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, - GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, - GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, - GraphQLObjectTypeExtensions, GraphQLResolveInfo, ResponsePath, GraphQLScalarTypeConfig, - GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, - GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, diff --git a/src/type/definition.js b/src/type/definition.js index d2a0c0d98c..ab94313263 100644 --- a/src/type/definition.js +++ b/src/type/definition.js @@ -548,8 +548,6 @@ function undefineIfEmpty(arr: ?$ReadOnlyArray): ?$ReadOnlyArray { return arr && arr.length > 0 ? arr : undefined; } -export type GraphQLScalarTypeExtensions = ReadOnlyObjMap; - /** * Scalar Type Definition * @@ -581,7 +579,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer; parseValue: GraphQLScalarValueParser; parseLiteral: GraphQLScalarLiteralParser; - extensions: ?GraphQLScalarTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?ScalarTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -626,7 +624,7 @@ export class GraphQLScalarType { serialize: GraphQLScalarSerializer, parseValue: GraphQLScalarValueParser, parseLiteral: GraphQLScalarLiteralParser, - extensions: ?GraphQLScalarTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -682,13 +680,11 @@ export type GraphQLScalarTypeConfig = {| parseValue?: GraphQLScalarValueParser, // Parses an externally provided literal value to use as an input. parseLiteral?: GraphQLScalarLiteralParser, - extensions?: ?GraphQLScalarTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?ScalarTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; -export type GraphQLObjectTypeExtensions = ReadOnlyObjMap; - /** * Object Type Definition * @@ -730,7 +726,7 @@ export class GraphQLObjectType { name: string; description: ?string; isTypeOf: ?GraphQLIsTypeOfFn; - extensions: ?GraphQLObjectTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?ObjectTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -773,7 +769,7 @@ export class GraphQLObjectType { ...GraphQLObjectTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?GraphQLObjectTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -918,7 +914,7 @@ export type GraphQLObjectTypeConfig = {| interfaces?: Thunk>, fields: Thunk>, isTypeOf?: ?GraphQLIsTypeOfFn, - extensions?: ?GraphQLObjectTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?ObjectTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -971,7 +967,7 @@ export type GraphQLFieldConfig< resolve?: GraphQLFieldResolver, subscribe?: GraphQLFieldResolver, deprecationReason?: ?string, - extensions?: ?GraphQLFieldExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?FieldDefinitionNode, |}; @@ -981,7 +977,7 @@ export type GraphQLArgumentConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, - extensions?: ?GraphQLArgumentExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputValueDefinitionNode, |}; @@ -989,8 +985,6 @@ export type GraphQLFieldConfigMap = ObjMap< GraphQLFieldConfig, >; -export type GraphQLFieldExtensions = ReadOnlyObjMap; - export type GraphQLField< TSource, TContext, @@ -1004,18 +998,16 @@ export type GraphQLField< subscribe?: GraphQLFieldResolver, isDeprecated: boolean, deprecationReason: ?string, - extensions: ?GraphQLFieldExtensions, + extensions: ?ReadOnlyObjMap, astNode: ?FieldDefinitionNode, |}; -export type GraphQLArgumentExtensions = ReadOnlyObjMap; - export type GraphQLArgument = {| name: string, description: ?string, type: GraphQLInputType, defaultValue: mixed, - extensions: ?GraphQLArgumentExtensions, + extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, |}; @@ -1027,8 +1019,6 @@ export type GraphQLFieldMap = ObjMap< GraphQLField, >; -export type GraphQLInterfaceTypeExtensions = ReadOnlyObjMap; - /** * Interface Type Definition * @@ -1051,7 +1041,7 @@ export class GraphQLInterfaceType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?GraphQLInterfaceTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?InterfaceTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1094,7 +1084,7 @@ export class GraphQLInterfaceType { ...GraphQLInterfaceTypeConfig, interfaces: Array, fields: GraphQLFieldConfigMap, - extensions: ?GraphQLInterfaceTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -1137,13 +1127,11 @@ export type GraphQLInterfaceTypeConfig = {| * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?GraphQLInterfaceTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InterfaceTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; -export type GraphQLUnionTypeExtensions = ReadOnlyObjMap; - /** * Union Type Definition * @@ -1171,7 +1159,7 @@ export class GraphQLUnionType { name: string; description: ?string; resolveType: ?GraphQLTypeResolver; - extensions: ?GraphQLUnionTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?UnionTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1204,7 +1192,7 @@ export class GraphQLUnionType { toConfig(): {| ...GraphQLUnionTypeConfig, types: Array, - extensions: ?GraphQLUnionTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { return { @@ -1256,13 +1244,11 @@ export type GraphQLUnionTypeConfig = {| * Object type. */ resolveType?: ?GraphQLTypeResolver, - extensions?: ?GraphQLUnionTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?UnionTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; -export type GraphQLEnumTypeExtensions = ReadOnlyObjMap; - /** * Enum Type Definition * @@ -1287,7 +1273,7 @@ export type GraphQLEnumTypeExtensions = ReadOnlyObjMap; export class GraphQLEnumType /* */ { name: string; description: ?string; - extensions: ?GraphQLEnumTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?EnumTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1373,7 +1359,7 @@ export class GraphQLEnumType /* */ { toConfig(): {| ...GraphQLEnumTypeConfig, - extensions: ?GraphQLEnumTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { const values = keyValMap( @@ -1459,7 +1445,7 @@ export type GraphQLEnumTypeConfig /* */ = {| name: string, description?: ?string, values: GraphQLEnumValueConfigMap /* */, - extensions?: ?GraphQLEnumTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?EnumTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -1470,24 +1456,20 @@ export type GraphQLEnumValueConfig /* */ = {| description?: ?string, value?: any /* T */, deprecationReason?: ?string, - extensions?: ?GraphQLEnumValueExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?EnumValueDefinitionNode, |}; -export type GraphQLEnumValueExtensions = ReadOnlyObjMap; - export type GraphQLEnumValue /* */ = {| name: string, description: ?string, value: any /* T */, isDeprecated: boolean, deprecationReason: ?string, - extensions: ?GraphQLEnumValueExtensions, + extensions: ?ReadOnlyObjMap, astNode: ?EnumValueDefinitionNode, |}; -export type GraphQLInputObjectTypeExtensions = ReadOnlyObjMap; - /** * Input Object Type Definition * @@ -1511,7 +1493,7 @@ export type GraphQLInputObjectTypeExtensions = ReadOnlyObjMap; export class GraphQLInputObjectType { name: string; description: ?string; - extensions: ?GraphQLInputObjectTypeExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?InputObjectTypeDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -1538,7 +1520,7 @@ export class GraphQLInputObjectType { toConfig(): {| ...GraphQLInputObjectTypeConfig, fields: GraphQLInputFieldConfigMap, - extensions: ?GraphQLInputObjectTypeExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, |} { const fields = mapValue(this.getFields(), (field) => ({ @@ -1605,7 +1587,7 @@ export type GraphQLInputObjectTypeConfig = {| name: string, description?: ?string, fields: Thunk, - extensions?: ?GraphQLInputObjectTypeExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputObjectTypeDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, |}; @@ -1614,20 +1596,18 @@ export type GraphQLInputFieldConfig = {| description?: ?string, type: GraphQLInputType, defaultValue?: mixed, - extensions?: ?GraphQLInputFieldExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?InputValueDefinitionNode, |}; export type GraphQLInputFieldConfigMap = ObjMap; -export type GraphQLInputFieldExtensions = ReadOnlyObjMap; - export type GraphQLInputField = {| name: string, description: ?string, type: GraphQLInputType, defaultValue: mixed, - extensions: ?GraphQLInputFieldExtensions, + extensions: ?ReadOnlyObjMap, astNode: ?InputValueDefinitionNode, |}; diff --git a/src/type/directives.js b/src/type/directives.js index ee17b1b4fe..b5074b8266 100644 --- a/src/type/directives.js +++ b/src/type/directives.js @@ -42,8 +42,6 @@ export function assertDirective(directive: mixed): GraphQLDirective { return directive; } -export type GraphQLDirectiveExtensions = ReadOnlyObjMap; - /** * Directives are used by the GraphQL runtime as a way of modifying execution * behavior. Type system creators will usually not create these directly. @@ -54,7 +52,7 @@ export class GraphQLDirective { locations: Array; args: Array; isRepeatable: boolean; - extensions: ?GraphQLDirectiveExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?DirectiveDefinitionNode; constructor(config: $ReadOnly): void { @@ -91,7 +89,7 @@ export class GraphQLDirective { ...GraphQLDirectiveConfig, args: GraphQLFieldConfigArgumentMap, isRepeatable: boolean, - extensions: ?GraphQLDirectiveExtensions, + extensions: ?ReadOnlyObjMap, |} { return { name: this.name, @@ -127,7 +125,7 @@ export type GraphQLDirectiveConfig = {| locations: Array, args?: ?GraphQLFieldConfigArgumentMap, isRepeatable?: ?boolean, - extensions?: ?GraphQLDirectiveExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?DirectiveDefinitionNode, |}; diff --git a/src/type/index.js b/src/type/index.js index 1199f96cfe..d15378b6cc 100644 --- a/src/type/index.js +++ b/src/type/index.js @@ -10,7 +10,7 @@ export { // GraphQL Schema definition GraphQLSchema, } from './schema'; -export type { GraphQLSchemaConfig, GraphQLSchemaExtensions } from './schema'; +export type { GraphQLSchemaConfig } from './schema'; export { // Predicates @@ -84,10 +84,7 @@ export { DEFAULT_DEPRECATION_REASON, } from './directives'; -export type { - GraphQLDirectiveConfig, - GraphQLDirectiveExtensions, -} from './directives'; +export type { GraphQLDirectiveConfig } from './directives'; // Common built-in scalar instances. export { @@ -136,38 +133,28 @@ export type { Thunk, GraphQLArgument, GraphQLArgumentConfig, - GraphQLArgumentExtensions, GraphQLEnumTypeConfig, - GraphQLEnumTypeExtensions, GraphQLEnumValue, GraphQLEnumValueConfig, - GraphQLEnumValueExtensions, GraphQLEnumValueConfigMap, GraphQLField, GraphQLFieldConfig, - GraphQLFieldExtensions, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldMap, GraphQLFieldResolver, GraphQLInputField, GraphQLInputFieldConfig, - GraphQLInputFieldExtensions, GraphQLInputFieldConfigMap, GraphQLInputFieldMap, GraphQLInputObjectTypeConfig, - GraphQLInputObjectTypeExtensions, GraphQLInterfaceTypeConfig, - GraphQLInterfaceTypeExtensions, GraphQLIsTypeOfFn, GraphQLObjectTypeConfig, - GraphQLObjectTypeExtensions, GraphQLResolveInfo, GraphQLScalarTypeConfig, - GraphQLScalarTypeExtensions, GraphQLTypeResolver, GraphQLUnionTypeConfig, - GraphQLUnionTypeExtensions, GraphQLScalarSerializer, GraphQLScalarValueParser, GraphQLScalarLiteralParser, diff --git a/src/type/schema.js b/src/type/schema.js index 0ee1e7cdc5..44d8c77262 100644 --- a/src/type/schema.js +++ b/src/type/schema.js @@ -61,8 +61,6 @@ export function assertSchema(schema: mixed): GraphQLSchema { return schema; } -export type GraphQLSchemaExtensions = ReadOnlyObjMap; - /** * Schema Definition * @@ -128,7 +126,7 @@ export type GraphQLSchemaExtensions = ReadOnlyObjMap; */ export class GraphQLSchema { description: ?string; - extensions: ?GraphQLSchemaExtensions; + extensions: ?ReadOnlyObjMap; astNode: ?SchemaDefinitionNode; extensionASTNodes: ?$ReadOnlyArray; @@ -385,7 +383,7 @@ export type GraphQLSchemaConfig = {| subscription?: ?GraphQLObjectType, types?: ?Array, directives?: ?Array, - extensions?: ?GraphQLSchemaExtensions, + extensions?: ?ReadOnlyObjMapLike, astNode?: ?SchemaDefinitionNode, extensionASTNodes?: ?$ReadOnlyArray, ...GraphQLSchemaValidationOptions, @@ -399,7 +397,7 @@ export type GraphQLSchemaNormalizedConfig = {| description: ?string, types: Array, directives: Array, - extensions: ?GraphQLSchemaExtensions, + extensions: ?ReadOnlyObjMap, extensionASTNodes: $ReadOnlyArray, assumeValid: boolean, |}; From 20d4f8ddcf4bea70493bd023aa56ae9567058004 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Sat, 20 Jun 2020 11:48:09 +0100 Subject: [PATCH 14/16] Add extensions to typescript integration test --- integrationTests/ts/index.ts | 43 +++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/integrationTests/ts/index.ts b/integrationTests/ts/index.ts index 7781e09b7f..d76bc4ea51 100644 --- a/integrationTests/ts/index.ts +++ b/integrationTests/ts/index.ts @@ -2,17 +2,58 @@ import { GraphQLString, GraphQLSchema, GraphQLObjectType } from 'graphql/type'; import { ExecutionResult } from 'graphql/execution'; import { graphqlSync } from 'graphql'; +interface SomeExtension { + number: number; + string: string; +} + +const example: SomeExtension = { + number: 42, + string: 'Meaning of life', +}; + +// The following code block requires a newer version of TypeScript +/*! >=3.2 + +declare module 'graphql' { + interface GraphQLObjectTypeExtensions { + someObjectExtension?: SomeExtension; + } + interface GraphQLFieldExtensions< + TSource, + TContext, + TArgs = { [argName: string]: any } + > { + someFieldExtension?: SomeExtension; + } + interface GraphQLArgumentExtensions { + someArgumentExtension?: SomeExtension; + } +} +*/ + const queryType: GraphQLObjectType = new GraphQLObjectType({ name: 'Query', fields: { sayHi: { type: GraphQLString, args: { - who: { type: GraphQLString }, + who: { + type: GraphQLString, + extensions: { + someArgumentExtension: example, + }, + }, }, resolve: (_root, args) => 'Hello ' + (args.who || 'World'), + extensions: { + someFieldExtension: example, + }, }, }, + extensions: { + someObjectExtension: example, + }, }); const schema: GraphQLSchema = new GraphQLSchema({ From 04c837a6caa3661bc317be33a7ef896ae51d2183 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Wed, 24 Jun 2020 10:09:36 +0100 Subject: [PATCH 15/16] Allow testing certain code blocks on only specific TypeScript versions --- integrationTests/ts/.gitignore | 2 + .../ts/{index.ts => index.ts.template} | 5 +-- integrationTests/ts/package.json | 2 + integrationTests/ts/test.js | 40 +++++++++++++++++++ 4 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 integrationTests/ts/.gitignore rename integrationTests/ts/{index.ts => index.ts.template} (98%) diff --git a/integrationTests/ts/.gitignore b/integrationTests/ts/.gitignore new file mode 100644 index 0000000000..26694ecad7 --- /dev/null +++ b/integrationTests/ts/.gitignore @@ -0,0 +1,2 @@ +# TypeScript files are generated from templates; see test.js +*.ts diff --git a/integrationTests/ts/index.ts b/integrationTests/ts/index.ts.template similarity index 98% rename from integrationTests/ts/index.ts rename to integrationTests/ts/index.ts.template index d76bc4ea51..996ab1b7e7 100644 --- a/integrationTests/ts/index.ts +++ b/integrationTests/ts/index.ts.template @@ -13,8 +13,7 @@ const example: SomeExtension = { }; // The following code block requires a newer version of TypeScript -/*! >=3.2 - +/*! >=3.2 !*/ declare module 'graphql' { interface GraphQLObjectTypeExtensions { someObjectExtension?: SomeExtension; @@ -30,7 +29,7 @@ declare module 'graphql' { someArgumentExtension?: SomeExtension; } } -*/ +/*!!*/ const queryType: GraphQLObjectType = new GraphQLObjectType({ name: 'Query', diff --git a/integrationTests/ts/package.json b/integrationTests/ts/package.json index a9090df232..fffd774bae 100644 --- a/integrationTests/ts/package.json +++ b/integrationTests/ts/package.json @@ -3,7 +3,9 @@ "test": "node test.js" }, "dependencies": { + "glob": "^7.1.6", "graphql": "file:../../npmDist", + "semver": "^7.3.2", "typescript-2.6": "npm:typescript@2.6.x", "typescript-2.7": "npm:typescript@2.7.x", "typescript-2.8": "npm:typescript@2.8.x", diff --git a/integrationTests/ts/test.js b/integrationTests/ts/test.js index a8bd1ef9ca..e3172925af 100644 --- a/integrationTests/ts/test.js +++ b/integrationTests/ts/test.js @@ -4,6 +4,11 @@ const path = require('path'); const childProcess = require('child_process'); +const assert = require('assert'); +const fs = require('fs'); + +const glob = require('glob'); +const semver = require('semver'); const { dependencies } = require('./package.json'); @@ -11,9 +16,44 @@ const tsVersions = Object.keys(dependencies) .filter((pkg) => pkg.startsWith('typescript-')) .sort((a, b) => b.localeCompare(a)); +// To allow omitting certain code from older versions of TypeScript, we have a +// "magic" comment syntax. We precede a block of code with: +// +// /*! SEMVER_RANGE !*/ +// +// replacing SEMVER_RANGE with a semver range spec, such as '>=3.2'; we +// terminate the block of code with: +// +// /*!!*/ +// +// We will only include the code between these comments if the TypeScript +// version being tested satisfies the semver range that was specified. NOTE: We +// currently do not allow nesting of these blocks. +const templates = glob.sync('./*.ts.template').map((filename) => { + const content = fs.readFileSync(filename, 'utf8'); + const targetFilename = filename.replace(/\.template$/, ''); + assert.notEqual(filename, targetFilename); + const writeFileSync = (version) => { + // Captures our magic comment syntax: `/*!(CAPTURE1)!*/(CAPTURE 2)/*!!*/` + const regex = /\/\*!([^!]+)!\*\/([\s\S]*?)\/\*!!\*\//g; + const finalContent = content.replace(regex, (_, versionRange, payload) => { + if (semver.satisfies(version, versionRange)) { + return payload; + } + return ''; + }); + fs.writeFileSync(targetFilename, finalContent); + }; + return { writeFileSync }; +}); + for (const version of tsVersions) { console.log(`Testing on ${version} ...`); + for (const template of templates) { + template.writeFileSync(version); + } + const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc'); childProcess.execSync(tscPath, { stdio: 'inherit' }); } From b33e65fb97dedbe9216cdef33d8df743c170d538 Mon Sep 17 00:00:00 2001 From: Benjie Gillam Date: Thu, 25 Jun 2020 18:06:40 +0100 Subject: [PATCH 16/16] Revert "Allow testing certain code blocks on only specific TypeScript versions" This reverts commit 04c837a6caa3661bc317be33a7ef896ae51d2183. --- integrationTests/ts/.gitignore | 2 - .../ts/{index.ts.template => index.ts} | 7 ++-- integrationTests/ts/package.json | 2 - integrationTests/ts/test.js | 40 ------------------- 4 files changed, 4 insertions(+), 47 deletions(-) delete mode 100644 integrationTests/ts/.gitignore rename integrationTests/ts/{index.ts.template => index.ts} (94%) diff --git a/integrationTests/ts/.gitignore b/integrationTests/ts/.gitignore deleted file mode 100644 index 26694ecad7..0000000000 --- a/integrationTests/ts/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -# TypeScript files are generated from templates; see test.js -*.ts diff --git a/integrationTests/ts/index.ts.template b/integrationTests/ts/index.ts similarity index 94% rename from integrationTests/ts/index.ts.template rename to integrationTests/ts/index.ts index 996ab1b7e7..eb989414b3 100644 --- a/integrationTests/ts/index.ts.template +++ b/integrationTests/ts/index.ts @@ -12,8 +12,9 @@ const example: SomeExtension = { string: 'Meaning of life', }; -// The following code block requires a newer version of TypeScript -/*! >=3.2 !*/ +// FIXME: The following code block requires a version of TypeScript >= 3.2 +/* + declare module 'graphql' { interface GraphQLObjectTypeExtensions { someObjectExtension?: SomeExtension; @@ -29,7 +30,7 @@ declare module 'graphql' { someArgumentExtension?: SomeExtension; } } -/*!!*/ +*/ const queryType: GraphQLObjectType = new GraphQLObjectType({ name: 'Query', diff --git a/integrationTests/ts/package.json b/integrationTests/ts/package.json index fffd774bae..a9090df232 100644 --- a/integrationTests/ts/package.json +++ b/integrationTests/ts/package.json @@ -3,9 +3,7 @@ "test": "node test.js" }, "dependencies": { - "glob": "^7.1.6", "graphql": "file:../../npmDist", - "semver": "^7.3.2", "typescript-2.6": "npm:typescript@2.6.x", "typescript-2.7": "npm:typescript@2.7.x", "typescript-2.8": "npm:typescript@2.8.x", diff --git a/integrationTests/ts/test.js b/integrationTests/ts/test.js index e3172925af..a8bd1ef9ca 100644 --- a/integrationTests/ts/test.js +++ b/integrationTests/ts/test.js @@ -4,11 +4,6 @@ const path = require('path'); const childProcess = require('child_process'); -const assert = require('assert'); -const fs = require('fs'); - -const glob = require('glob'); -const semver = require('semver'); const { dependencies } = require('./package.json'); @@ -16,44 +11,9 @@ const tsVersions = Object.keys(dependencies) .filter((pkg) => pkg.startsWith('typescript-')) .sort((a, b) => b.localeCompare(a)); -// To allow omitting certain code from older versions of TypeScript, we have a -// "magic" comment syntax. We precede a block of code with: -// -// /*! SEMVER_RANGE !*/ -// -// replacing SEMVER_RANGE with a semver range spec, such as '>=3.2'; we -// terminate the block of code with: -// -// /*!!*/ -// -// We will only include the code between these comments if the TypeScript -// version being tested satisfies the semver range that was specified. NOTE: We -// currently do not allow nesting of these blocks. -const templates = glob.sync('./*.ts.template').map((filename) => { - const content = fs.readFileSync(filename, 'utf8'); - const targetFilename = filename.replace(/\.template$/, ''); - assert.notEqual(filename, targetFilename); - const writeFileSync = (version) => { - // Captures our magic comment syntax: `/*!(CAPTURE1)!*/(CAPTURE 2)/*!!*/` - const regex = /\/\*!([^!]+)!\*\/([\s\S]*?)\/\*!!\*\//g; - const finalContent = content.replace(regex, (_, versionRange, payload) => { - if (semver.satisfies(version, versionRange)) { - return payload; - } - return ''; - }); - fs.writeFileSync(targetFilename, finalContent); - }; - return { writeFileSync }; -}); - for (const version of tsVersions) { console.log(`Testing on ${version} ...`); - for (const template of templates) { - template.writeFileSync(version); - } - const tscPath = path.join(__dirname, 'node_modules', version, 'bin/tsc'); childProcess.execSync(tscPath, { stdio: 'inherit' }); }