Skip to content

Commit

Permalink
Merge pull request #2 from stevefan1999/patch-1
Browse files Browse the repository at this point in the history
Patch 1
  • Loading branch information
stevefan1999-personal authored Sep 3, 2018
2 parents ec32fb9 + 26d28f9 commit eed669a
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions lib/graphql.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,41 @@ export class GraphQLFactory {
this.scalarsExplorerService.explore(),
this.resolversExplorerService.explore(),
);
const schema = makeExecutableSchema({
resolvers: extend(resolvers, options.resolvers),
typeDefs: gql`
${options.typeDefs}
`,
})

let schema;

try {
schema = makeExecutableSchema({
resolvers: extend(resolvers, options.resolvers),
typeDefs: gql`
${options.typeDefs}
`,
});

// if we had an original schema, then merge both through the use of schema stitching
// you could also opt to do it yourself though
if (options.schema) {
schema = mergeSchemas({
schemas: [
options.schema,
schema
]
// XXX: Type resolution not yet implemented, please use mergeSchemas yourself
});
}
} catch (err) {
// if the original schema is still there, use it as a fallback
if (options.schema) {
schema = options.schema;
} else {
throw err; // otherwise re-throw it
}
}

return {
...options,
typeDefs: undefined,
schema: options.schema ? mergeSchemas({
schemas: [
options.schema,
schema
],
}) : schema
schema
};
}

Expand Down

0 comments on commit eed669a

Please sign in to comment.