Skip to content

Commit cba1bb6

Browse files
committed
introduce mapSchemaConfig
motivation: 1. can be used to extract common logic from extendSchemaImpl and lexicographicSortSchema 2. can be used further enhance extendSchemaImpl to take resolvers 3. can be exposed to provide a generic safe mapSchemaConfig
1 parent 3675046 commit cba1bb6

File tree

4 files changed

+1484
-14
lines changed

4 files changed

+1484
-14
lines changed

src/type/definition.ts

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
738738
extensionASTNodes?: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
739739
}
740740

741-
interface GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>
741+
export interface GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>
742742
extends GraphQLScalarTypeConfig<TInternal, TExternal> {
743743
serialize: GraphQLScalarSerializer<TExternal>;
744744
parseValue: GraphQLScalarValueParser<TInternal>;
@@ -914,7 +914,7 @@ export function defineArguments(
914914

915915
function fieldsToFieldsConfig<TSource, TContext>(
916916
fields: GraphQLFieldMap<TSource, TContext>,
917-
): GraphQLFieldConfigMap<TSource, TContext> {
917+
): GraphQLFieldNormalizedConfigMap<TSource, TContext> {
918918
return mapValue(fields, (field) => ({
919919
description: field.description,
920920
type: field.type,
@@ -932,7 +932,7 @@ function fieldsToFieldsConfig<TSource, TContext>(
932932
*/
933933
export function argsToArgsConfig(
934934
args: ReadonlyArray<GraphQLArgument>,
935-
): GraphQLFieldConfigArgumentMap {
935+
): GraphQLFieldNormalizedConfigArgumentMap {
936936
return keyValMap(
937937
args,
938938
(arg) => arg.name,
@@ -959,10 +959,10 @@ export interface GraphQLObjectTypeConfig<TSource, TContext> {
959959
extensionASTNodes?: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
960960
}
961961

962-
interface GraphQLObjectTypeNormalizedConfig<TSource, TContext>
962+
export interface GraphQLObjectTypeNormalizedConfig<TSource, TContext>
963963
extends GraphQLObjectTypeConfig<any, any> {
964964
interfaces: ReadonlyArray<GraphQLInterfaceType>;
965-
fields: GraphQLFieldConfigMap<any, any>;
965+
fields: GraphQLFieldNormalizedConfigMap<any, any>;
966966
extensions: Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>;
967967
extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>;
968968
}
@@ -1035,8 +1035,17 @@ export interface GraphQLFieldConfig<TSource, TContext, TArgs = any> {
10351035
astNode?: Maybe<FieldDefinitionNode>;
10361036
}
10371037

1038+
export interface GraphQLFieldNormalizedConfig<TSource, TContext, TArgs = any>
1039+
extends GraphQLFieldConfig<TSource, TContext, TArgs> {
1040+
args: GraphQLFieldNormalizedConfigArgumentMap;
1041+
extensions: Readonly<GraphQLFieldExtensions<TSource, TContext, TArgs>>;
1042+
}
1043+
10381044
export type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;
10391045

1046+
export type GraphQLFieldNormalizedConfigArgumentMap =
1047+
ObjMap<GraphQLArgumentNormalizedConfig>;
1048+
10401049
/**
10411050
* Custom extensions
10421051
*
@@ -1060,10 +1069,18 @@ export interface GraphQLArgumentConfig {
10601069
astNode?: Maybe<InputValueDefinitionNode>;
10611070
}
10621071

1072+
export interface GraphQLArgumentNormalizedConfig extends GraphQLArgumentConfig {
1073+
extensions: Readonly<GraphQLArgumentExtensions>;
1074+
}
1075+
10631076
export type GraphQLFieldConfigMap<TSource, TContext> = ObjMap<
10641077
GraphQLFieldConfig<TSource, TContext>
10651078
>;
10661079

1080+
export type GraphQLFieldNormalizedConfigMap<TSource, TContext> = ObjMap<
1081+
GraphQLFieldNormalizedConfig<TSource, TContext>
1082+
>;
1083+
10671084
export interface GraphQLField<TSource, TContext, TArgs = any> {
10681085
name: string;
10691086
description: Maybe<string>;
@@ -1229,10 +1246,10 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
12291246
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
12301247
}
12311248

1232-
interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
1249+
export interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
12331250
extends GraphQLInterfaceTypeConfig<any, any> {
12341251
interfaces: ReadonlyArray<GraphQLInterfaceType>;
1235-
fields: GraphQLFieldConfigMap<TSource, TContext>;
1252+
fields: GraphQLFieldNormalizedConfigMap<TSource, TContext>;
12361253
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
12371254
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
12381255
}
@@ -1348,7 +1365,7 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
13481365
extensionASTNodes?: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
13491366
}
13501367

1351-
interface GraphQLUnionTypeNormalizedConfig
1368+
export interface GraphQLUnionTypeNormalizedConfig
13521369
extends GraphQLUnionTypeConfig<any, any> {
13531370
types: ReadonlyArray<GraphQLObjectType>;
13541371
extensions: Readonly<GraphQLUnionTypeExtensions>;
@@ -1596,15 +1613,18 @@ export interface GraphQLEnumTypeConfig {
15961613
extensionASTNodes?: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
15971614
}
15981615

1599-
interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig {
1600-
values: ObjMap<GraphQLEnumValueConfig /* <T> */>;
1616+
export interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig {
1617+
values: GraphQLEnumValueNormalizedConfigMap;
16011618
extensions: Readonly<GraphQLEnumTypeExtensions>;
16021619
extensionASTNodes: ReadonlyArray<EnumTypeExtensionNode>;
16031620
}
16041621

16051622
export type GraphQLEnumValueConfigMap /* <T> */ =
16061623
ObjMap<GraphQLEnumValueConfig /* <T> */>;
16071624

1625+
export type GraphQLEnumValueNormalizedConfigMap /* <T> */ =
1626+
ObjMap<GraphQLEnumValueNormalizedConfig /* <T> */>;
1627+
16081628
/**
16091629
* Custom extensions
16101630
*
@@ -1626,6 +1646,11 @@ export interface GraphQLEnumValueConfig {
16261646
astNode?: Maybe<EnumValueDefinitionNode>;
16271647
}
16281648

1649+
export interface GraphQLEnumValueNormalizedConfig
1650+
extends GraphQLEnumValueConfig {
1651+
extensions: Readonly<GraphQLEnumValueExtensions>;
1652+
}
1653+
16291654
export interface GraphQLEnumValue {
16301655
name: string;
16311656
description: Maybe<string>;
@@ -1757,9 +1782,9 @@ export interface GraphQLInputObjectTypeConfig {
17571782
isOneOf?: boolean;
17581783
}
17591784

1760-
interface GraphQLInputObjectTypeNormalizedConfig
1785+
export interface GraphQLInputObjectTypeNormalizedConfig
17611786
extends GraphQLInputObjectTypeConfig {
1762-
fields: GraphQLInputFieldConfigMap;
1787+
fields: GraphQLInputFieldNormalizedConfigMap;
17631788
extensions: Readonly<GraphQLInputObjectTypeExtensions>;
17641789
extensionASTNodes: ReadonlyArray<InputObjectTypeExtensionNode>;
17651790
}
@@ -1789,6 +1814,14 @@ export interface GraphQLInputFieldConfig {
17891814

17901815
export type GraphQLInputFieldConfigMap = ObjMap<GraphQLInputFieldConfig>;
17911816

1817+
export interface GraphQLInputFieldNormalizedConfig
1818+
extends GraphQLInputFieldConfig {
1819+
extensions: Readonly<GraphQLInputFieldExtensions>;
1820+
}
1821+
1822+
export type GraphQLInputFieldNormalizedConfigMap =
1823+
ObjMap<GraphQLInputFieldNormalizedConfig>;
1824+
17921825
export interface GraphQLInputField {
17931826
name: string;
17941827
description: Maybe<string>;

src/type/directives.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { assertName } from './assertName.js';
1010
import type {
1111
GraphQLArgument,
1212
GraphQLFieldConfigArgumentMap,
13+
GraphQLFieldNormalizedConfigArgumentMap,
1314
} from './definition.js';
1415
import {
1516
argsToArgsConfig,
@@ -107,8 +108,9 @@ export interface GraphQLDirectiveConfig {
107108
astNode?: Maybe<DirectiveDefinitionNode>;
108109
}
109110

110-
interface GraphQLDirectiveNormalizedConfig extends GraphQLDirectiveConfig {
111-
args: GraphQLFieldConfigArgumentMap;
111+
export interface GraphQLDirectiveNormalizedConfig
112+
extends GraphQLDirectiveConfig {
113+
args: GraphQLFieldNormalizedConfigArgumentMap;
112114
isRepeatable: boolean;
113115
extensions: Readonly<GraphQLDirectiveExtensions>;
114116
}

0 commit comments

Comments
 (0)