1 | 'use strict';
|
2 |
|
3 | const graphql = require('graphql');
|
4 | const core = require('@graphql-toolkit/core');
|
5 | const graphqlFileLoader = require('@graphql-toolkit/graphql-file-loader');
|
6 | const codeFileLoader = require('@graphql-toolkit/code-file-loader');
|
7 |
|
8 | const extendTransform = async ({ schema, config, }) => {
|
9 | try {
|
10 | const sources = await core.loadTypedefs(config, {
|
11 | loaders: [new graphqlFileLoader.GraphQLFileLoader(), new codeFileLoader.CodeFileLoader()],
|
12 | assumeValid: true,
|
13 | assumeValidSDL: true,
|
14 | });
|
15 | const mergedDefinitions = graphql.concatAST(sources.map(source => source.document));
|
16 | return graphql.extendSchema(schema, mergedDefinitions);
|
17 | }
|
18 | catch (e) {
|
19 | throw new Error(`'extend' transform requires a valid SDL string!`);
|
20 | }
|
21 | };
|
22 |
|
23 | module.exports = extendTransform;
|
24 |
|