UNPKG

1.51 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 *
13 * @deprecated Please use `GraphQLSchema.getRootType` instead. Will be removed in v17
14 */
15function getOperationRootType(schema, operation) {
16 if (operation.operation === 'query') {
17 const queryType = schema.getQueryType();
18
19 if (!queryType) {
20 throw new _GraphQLError.GraphQLError(
21 'Schema does not define the required query root type.',
22 {
23 nodes: operation,
24 },
25 );
26 }
27
28 return queryType;
29 }
30
31 if (operation.operation === 'mutation') {
32 const mutationType = schema.getMutationType();
33
34 if (!mutationType) {
35 throw new _GraphQLError.GraphQLError(
36 'Schema is not configured for mutations.',
37 {
38 nodes: operation,
39 },
40 );
41 }
42
43 return mutationType;
44 }
45
46 if (operation.operation === 'subscription') {
47 const subscriptionType = schema.getSubscriptionType();
48
49 if (!subscriptionType) {
50 throw new _GraphQLError.GraphQLError(
51 'Schema is not configured for subscriptions.',
52 {
53 nodes: operation,
54 },
55 );
56 }
57
58 return subscriptionType;
59 }
60
61 throw new _GraphQLError.GraphQLError(
62 'Can only have query, mutation and subscription operations.',
63 {
64 nodes: operation,
65 },
66 );
67}