1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.getOperationRootType = getOperationRootType;
|
7 |
|
8 | var _GraphQLError = require("../error/GraphQLError");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 | function getOperationRootType(schema, operation) {
|
23 | switch (operation.operation) {
|
24 | case 'query':
|
25 | var queryType = schema.getQueryType();
|
26 |
|
27 | if (!queryType) {
|
28 | throw new _GraphQLError.GraphQLError('Schema does not define the required query root type.', [operation]);
|
29 | }
|
30 |
|
31 | return queryType;
|
32 |
|
33 | case 'mutation':
|
34 | var mutationType = schema.getMutationType();
|
35 |
|
36 | if (!mutationType) {
|
37 | throw new _GraphQLError.GraphQLError('Schema is not configured for mutations.', [operation]);
|
38 | }
|
39 |
|
40 | return mutationType;
|
41 |
|
42 | case 'subscription':
|
43 | var subscriptionType = schema.getSubscriptionType();
|
44 |
|
45 | if (!subscriptionType) {
|
46 | throw new _GraphQLError.GraphQLError('Schema is not configured for subscriptions.', [operation]);
|
47 | }
|
48 |
|
49 | return subscriptionType;
|
50 |
|
51 | default:
|
52 | throw new _GraphQLError.GraphQLError('Can only have query, mutation and subscription operations.', [operation]);
|
53 | }
|
54 | } |
\ | No newline at end of file |