MCPcopy
hub / github.com/ardatan/graphql-tools / appendObjectFields

Function appendObjectFields

packages/utils/src/fields.ts:11–49  ·  view source on GitHub ↗
(
  schema: GraphQLSchema,
  typeName: string,
  additionalFields: GraphQLFieldConfigMap<any, any>,
)

Source from the content-addressed store, hash-verified

9import { correctASTNodes, mapSchema } from './mapSchema.js';
10
11export function appendObjectFields(
12 schema: GraphQLSchema,
13 typeName: string,
14 additionalFields: GraphQLFieldConfigMap<any, any>,
15): GraphQLSchema {
16 if (schema.getType(typeName) == null) {
17 return addTypes(schema, [
18 new GraphQLObjectType({
19 name: typeName,
20 fields: additionalFields,
21 }),
22 ]);
23 }
24
25 return mapSchema(schema, {
26 [MapperKind.OBJECT_TYPE]: type => {
27 if (type.name === typeName) {
28 const config = type.toConfig();
29 const originalFieldConfigMap = config.fields;
30
31 const newFieldConfigMap = {};
32
33 for (const fieldName in originalFieldConfigMap) {
34 newFieldConfigMap[fieldName] = originalFieldConfigMap[fieldName];
35 }
36 for (const fieldName in additionalFields) {
37 newFieldConfigMap[fieldName] = additionalFields[fieldName];
38 }
39
40 return correctASTNodes(
41 new GraphQLObjectType({
42 ...config,
43 fields: newFieldConfigMap,
44 }),
45 );
46 }
47 },
48 });
49}
50
51export function removeObjectFields(
52 schema: GraphQLSchema,

Callers

nothing calls this directly

Calls 4

addTypesFunction · 0.85
mapSchemaFunction · 0.85
correctASTNodesFunction · 0.85
getTypeMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…