Skip to content

Commit

Permalink
introduces mapSchemaConfig function
Browse files Browse the repository at this point in the history
extracting this from lexicographicallySortSchema
and extendSchemaImpl

motivation:
1. to use to further enhance extendSchema/buildASTSchema/buildSchema to take resolvers, etc, and
2. to expose a generic safe mapSchemaConfig
  • Loading branch information
yaacovCR committed Nov 21, 2024
1 parent 1d98a6a commit f6325d3
Show file tree
Hide file tree
Showing 5 changed files with 919 additions and 627 deletions.
57 changes: 45 additions & 12 deletions src/type/definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ export interface GraphQLScalarTypeConfig<TInternal, TExternal> {
extensionASTNodes?: Maybe<ReadonlyArray<ScalarTypeExtensionNode>>;
}

interface GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>
export interface GraphQLScalarTypeNormalizedConfig<TInternal, TExternal>
extends GraphQLScalarTypeConfig<TInternal, TExternal> {
serialize: GraphQLScalarSerializer<TExternal>;
parseValue: GraphQLScalarValueParser<TInternal>;
Expand Down Expand Up @@ -914,7 +914,7 @@ export function defineArguments(

function fieldsToFieldsConfig<TSource, TContext>(
fields: GraphQLFieldMap<TSource, TContext>,
): GraphQLFieldConfigMap<TSource, TContext> {
): GraphQLFieldNormalizedConfigMap<TSource, TContext> {
return mapValue(fields, (field) => ({
description: field.description,
type: field.type,
Expand All @@ -932,7 +932,7 @@ function fieldsToFieldsConfig<TSource, TContext>(
*/
export function argsToArgsConfig(
args: ReadonlyArray<GraphQLArgument>,
): GraphQLFieldConfigArgumentMap {
): GraphQLFieldNormalizedConfigArgumentMap {
return keyValMap(
args,
(arg) => arg.name,
Expand All @@ -959,10 +959,10 @@ export interface GraphQLObjectTypeConfig<TSource, TContext> {
extensionASTNodes?: Maybe<ReadonlyArray<ObjectTypeExtensionNode>>;
}

interface GraphQLObjectTypeNormalizedConfig<TSource, TContext>
export interface GraphQLObjectTypeNormalizedConfig<TSource, TContext>
extends GraphQLObjectTypeConfig<any, any> {
interfaces: ReadonlyArray<GraphQLInterfaceType>;
fields: GraphQLFieldConfigMap<any, any>;
fields: GraphQLFieldNormalizedConfigMap<any, any>;
extensions: Readonly<GraphQLObjectTypeExtensions<TSource, TContext>>;
extensionASTNodes: ReadonlyArray<ObjectTypeExtensionNode>;
}
Expand Down Expand Up @@ -1035,8 +1035,17 @@ export interface GraphQLFieldConfig<TSource, TContext, TArgs = any> {
astNode?: Maybe<FieldDefinitionNode>;
}

export interface GraphQLFieldNormalizedConfig<TSource, TContext, TArgs = any>
extends GraphQLFieldConfig<TSource, TContext, TArgs> {
args: GraphQLFieldNormalizedConfigArgumentMap;
extensions: Readonly<GraphQLFieldExtensions<TSource, TContext, TArgs>>;
}

export type GraphQLFieldConfigArgumentMap = ObjMap<GraphQLArgumentConfig>;

export type GraphQLFieldNormalizedConfigArgumentMap =
ObjMap<GraphQLArgumentNormalizedConfig>;

/**
* Custom extensions
*
Expand All @@ -1060,10 +1069,18 @@ export interface GraphQLArgumentConfig {
astNode?: Maybe<InputValueDefinitionNode>;
}

export interface GraphQLArgumentNormalizedConfig extends GraphQLArgumentConfig {
extensions: Readonly<GraphQLArgumentExtensions>;
}

export type GraphQLFieldConfigMap<TSource, TContext> = ObjMap<
GraphQLFieldConfig<TSource, TContext>
>;

export type GraphQLFieldNormalizedConfigMap<TSource, TContext> = ObjMap<
GraphQLFieldNormalizedConfig<TSource, TContext>
>;

export interface GraphQLField<TSource, TContext, TArgs = any> {
name: string;
description: Maybe<string>;
Expand Down Expand Up @@ -1229,10 +1246,10 @@ export interface GraphQLInterfaceTypeConfig<TSource, TContext> {
extensionASTNodes?: Maybe<ReadonlyArray<InterfaceTypeExtensionNode>>;
}

interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
export interface GraphQLInterfaceTypeNormalizedConfig<TSource, TContext>
extends GraphQLInterfaceTypeConfig<any, any> {
interfaces: ReadonlyArray<GraphQLInterfaceType>;
fields: GraphQLFieldConfigMap<TSource, TContext>;
fields: GraphQLFieldNormalizedConfigMap<TSource, TContext>;
extensions: Readonly<GraphQLInterfaceTypeExtensions>;
extensionASTNodes: ReadonlyArray<InterfaceTypeExtensionNode>;
}
Expand Down Expand Up @@ -1348,7 +1365,7 @@ export interface GraphQLUnionTypeConfig<TSource, TContext> {
extensionASTNodes?: Maybe<ReadonlyArray<UnionTypeExtensionNode>>;
}

interface GraphQLUnionTypeNormalizedConfig
export interface GraphQLUnionTypeNormalizedConfig
extends GraphQLUnionTypeConfig<any, any> {
types: ReadonlyArray<GraphQLObjectType>;
extensions: Readonly<GraphQLUnionTypeExtensions>;
Expand Down Expand Up @@ -1594,15 +1611,18 @@ export interface GraphQLEnumTypeConfig {
extensionASTNodes?: Maybe<ReadonlyArray<EnumTypeExtensionNode>>;
}

interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig {
values: ObjMap<GraphQLEnumValueConfig /* <T> */>;
export interface GraphQLEnumTypeNormalizedConfig extends GraphQLEnumTypeConfig {
values: GraphQLEnumValueNormalizedConfigMap;
extensions: Readonly<GraphQLEnumTypeExtensions>;
extensionASTNodes: ReadonlyArray<EnumTypeExtensionNode>;
}

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

export type GraphQLEnumValueNormalizedConfigMap /* <T> */ =
ObjMap<GraphQLEnumValueNormalizedConfig /* <T> */>;

/**
* Custom extensions
*
Expand All @@ -1624,6 +1644,11 @@ export interface GraphQLEnumValueConfig {
astNode?: Maybe<EnumValueDefinitionNode>;
}

export interface GraphQLEnumValueNormalizedConfig
extends GraphQLEnumValueConfig {
extensions: Readonly<GraphQLEnumValueExtensions>;
}

export interface GraphQLEnumValue {
name: string;
description: Maybe<string>;
Expand Down Expand Up @@ -1755,9 +1780,9 @@ export interface GraphQLInputObjectTypeConfig {
isOneOf?: boolean;
}

interface GraphQLInputObjectTypeNormalizedConfig
export interface GraphQLInputObjectTypeNormalizedConfig
extends GraphQLInputObjectTypeConfig {
fields: GraphQLInputFieldConfigMap;
fields: GraphQLInputFieldNormalizedConfigMap;
extensions: Readonly<GraphQLInputObjectTypeExtensions>;
extensionASTNodes: ReadonlyArray<InputObjectTypeExtensionNode>;
}
Expand Down Expand Up @@ -1787,6 +1812,14 @@ export interface GraphQLInputFieldConfig {

export type GraphQLInputFieldConfigMap = ObjMap<GraphQLInputFieldConfig>;

export interface GraphQLInputFieldNormalizedConfig
extends GraphQLInputFieldConfig {
extensions: Readonly<GraphQLInputFieldExtensions>;
}

export type GraphQLInputFieldNormalizedConfigMap =
ObjMap<GraphQLInputFieldNormalizedConfig>;

export interface GraphQLInputField {
name: string;
description: Maybe<string>;
Expand Down
6 changes: 4 additions & 2 deletions src/type/directives.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { assertName } from './assertName.js';
import type {
GraphQLArgument,
GraphQLFieldConfigArgumentMap,
GraphQLFieldNormalizedConfigArgumentMap,
} from './definition.js';
import {
argsToArgsConfig,
Expand Down Expand Up @@ -107,8 +108,9 @@ export interface GraphQLDirectiveConfig {
astNode?: Maybe<DirectiveDefinitionNode>;
}

interface GraphQLDirectiveNormalizedConfig extends GraphQLDirectiveConfig {
args: GraphQLFieldConfigArgumentMap;
export interface GraphQLDirectiveNormalizedConfig
extends GraphQLDirectiveConfig {
args: GraphQLFieldNormalizedConfigArgumentMap;
isRepeatable: boolean;
extensions: Readonly<GraphQLDirectiveExtensions>;
}
Expand Down
Loading

0 comments on commit f6325d3

Please sign in to comment.