UNPKG

1.03 kBJavaScriptView Raw
1import { GraphQLError } from "../error/GraphQLError.mjs";
2
3/**
4 * Extracts the root type of the operation from the schema.
5 */
6export function getOperationRootType(schema, operation) {
7 if (operation.operation === 'query') {
8 var queryType = schema.getQueryType();
9
10 if (!queryType) {
11 throw new GraphQLError('Schema does not define the required query root type.', operation);
12 }
13
14 return queryType;
15 }
16
17 if (operation.operation === 'mutation') {
18 var mutationType = schema.getMutationType();
19
20 if (!mutationType) {
21 throw new GraphQLError('Schema is not configured for mutations.', operation);
22 }
23
24 return mutationType;
25 }
26
27 if (operation.operation === 'subscription') {
28 var subscriptionType = schema.getSubscriptionType();
29
30 if (!subscriptionType) {
31 throw new GraphQLError('Schema is not configured for subscriptions.', operation);
32 }
33
34 return subscriptionType;
35 }
36
37 throw new GraphQLError('Can only have query, mutation and subscription operations.', operation);
38}