Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
fix(cloneSchema): cloneSchema should preserve extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
yaacovCR committed Sep 15, 2019
1 parent 10c41c3 commit 9b97797
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/utils/clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,25 +56,15 @@ export function cloneSchema(schema: GraphQLSchema): GraphQLSchema {

healTypes(newTypeMap, newDirectives);

const selectors = {
query: 'getQueryType',
mutation: 'getMutationType',
subscription: 'getSubscriptionType',
};

const rootTypes = Object.create(null);

Object.keys(selectors).forEach(op => {
const rootType = schema[selectors[op]]();
if (rootType) {
rootTypes[op] = newTypeMap[rootType.name];
}
});
const query = schema.getQueryType();
const mutation = schema.getMutationType();
const subscription = schema.getSubscriptionType();

return new GraphQLSchema({
query: rootTypes.query,
mutation: rootTypes.mutation,
subscription: rootTypes.subscription,
...schema.toConfig(),
query: query ? newTypeMap[query.name] : undefined,
mutation: mutation ? newTypeMap[mutation.name] : undefined,
subscription: subscription ? newTypeMap[subscription.name] : undefined,
types: Object.keys(newTypeMap).map(typeName => newTypeMap[typeName]),
directives: newDirectives,
});
Expand Down

0 comments on commit 9b97797

Please sign in to comment.