This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
admin-panel/graphql-types/node_modules/graphql/utilities/getOperationRootType.mjs

39 lines
1.0 KiB
JavaScript

import { GraphQLError } from "../error/GraphQLError.mjs";
/**
* Extracts the root type of the operation from the schema.
*/
export function getOperationRootType(schema, operation) {
if (operation.operation === 'query') {
var queryType = schema.getQueryType();
if (!queryType) {
throw new GraphQLError('Schema does not define the required query root type.', operation);
}
return queryType;
}
if (operation.operation === 'mutation') {
var mutationType = schema.getMutationType();
if (!mutationType) {
throw new GraphQLError('Schema is not configured for mutations.', operation);
}
return mutationType;
}
if (operation.operation === 'subscription') {
var subscriptionType = schema.getSubscriptionType();
if (!subscriptionType) {
throw new GraphQLError('Schema is not configured for subscriptions.', operation);
}
return subscriptionType;
}
throw new GraphQLError('Can only have query, mutation and subscription operations.', operation);
}