UNPKG

1.21 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getOperationRootType = getOperationRootType;
7
8var _GraphQLError = require("../error/GraphQLError.js");
9
10/**
11 * Extracts the root type of the operation from the schema.
12 */
13function getOperationRootType(schema, operation) {
14 if (operation.operation === 'query') {
15 var queryType = schema.getQueryType();
16
17 if (!queryType) {
18 throw new _GraphQLError.GraphQLError('Schema does not define the required query root type.', operation);
19 }
20
21 return queryType;
22 }
23
24 if (operation.operation === 'mutation') {
25 var mutationType = schema.getMutationType();
26
27 if (!mutationType) {
28 throw new _GraphQLError.GraphQLError('Schema is not configured for mutations.', operation);
29 }
30
31 return mutationType;
32 }
33
34 if (operation.operation === 'subscription') {
35 var subscriptionType = schema.getSubscriptionType();
36
37 if (!subscriptionType) {
38 throw new _GraphQLError.GraphQLError('Schema is not configured for subscriptions.', operation);
39 }
40
41 return subscriptionType;
42 }
43
44 throw new _GraphQLError.GraphQLError('Can only have query, mutation and subscription operations.', operation);
45}