UNPKG

1.41 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.getOperationRootType = getOperationRootType;
7
8var _GraphQLError = require("../error/GraphQLError");
9
10/**
11 * Copyright (c) 2015-present, Facebook, Inc.
12 *
13 * This source code is licensed under the MIT license found in the
14 * LICENSE file in the root directory of this source tree.
15 *
16 *
17 */
18
19/**
20 * Extracts the root type of the operation from the schema.
21 */
22function 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