( schema: GraphQLSchema, typeName: string, additionalFields: GraphQLFieldConfigMap<any, any>, )
| 9 | import { correctASTNodes, mapSchema } from './mapSchema.js'; |
| 10 | |
| 11 | export 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 | |
| 51 | export function removeObjectFields( |
| 52 | schema: GraphQLSchema, |
nothing calls this directly
no test coverage detected
searching dependent graphs…