1 | import { buildASTSchema, buildSchema, isSchema } from 'graphql';
|
2 | import { applyExtensions, mergeResolvers, mergeTypeDefs } from '@graphql-tools/merge';
|
3 | import { asArray } from '@graphql-tools/utils';
|
4 | import { addResolversToSchema } from './addResolversToSchema.js';
|
5 | import { assertResolversPresent } from './assertResolversPresent.js';
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 | export function makeExecutableSchema({ typeDefs, resolvers = {}, resolverValidationOptions = {}, inheritResolversFromInterfaces = false, updateResolversInPlace = false, schemaExtensions, defaultFieldResolver, ...otherOptions }) {
|
50 |
|
51 | if (typeof resolverValidationOptions !== 'object') {
|
52 | throw new Error('Expected `resolverValidationOptions` to be an object');
|
53 | }
|
54 | if (!typeDefs) {
|
55 | throw new Error('Must provide typeDefs');
|
56 | }
|
57 | let schema;
|
58 | if (isSchema(typeDefs)) {
|
59 | schema = typeDefs;
|
60 | }
|
61 | else if (otherOptions?.commentDescriptions) {
|
62 | const mergedTypeDefs = mergeTypeDefs(typeDefs, {
|
63 | ...otherOptions,
|
64 | commentDescriptions: true,
|
65 | });
|
66 | schema = buildSchema(mergedTypeDefs, otherOptions);
|
67 | }
|
68 | else {
|
69 | const mergedTypeDefs = mergeTypeDefs(typeDefs, otherOptions);
|
70 | schema = buildASTSchema(mergedTypeDefs, otherOptions);
|
71 | }
|
72 |
|
73 | schema = addResolversToSchema({
|
74 | schema,
|
75 | resolvers: mergeResolvers(resolvers),
|
76 | resolverValidationOptions,
|
77 | inheritResolversFromInterfaces,
|
78 | updateResolversInPlace,
|
79 | defaultFieldResolver,
|
80 | });
|
81 | if (Object.keys(resolverValidationOptions).length > 0) {
|
82 | assertResolversPresent(schema, resolverValidationOptions);
|
83 | }
|
84 | if (schemaExtensions) {
|
85 | for (const schemaExtension of asArray(schemaExtensions)) {
|
86 | applyExtensions(schema, schemaExtension);
|
87 | }
|
88 | }
|
89 | return schema;
|
90 | }
|