graphql
Version:
A Query Language and Runtime which can target any service.
46 lines (33 loc) • 1.21 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getOperationRootType = getOperationRootType;
var _GraphQLError = require("../error/GraphQLError");
/**
* Extracts the root type of the operation from the schema.
*/
function getOperationRootType(schema, operation) {
if (operation.operation === 'query') {
var queryType = schema.getQueryType();
if (!queryType) {
throw new _GraphQLError.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.GraphQLError('Schema is not configured for mutations.', operation);
}
return mutationType;
}
if (operation.operation === 'subscription') {
var subscriptionType = schema.getSubscriptionType();
if (!subscriptionType) {
throw new _GraphQLError.GraphQLError('Schema is not configured for subscriptions.', operation);
}
return subscriptionType;
}
throw new _GraphQLError.GraphQLError('Can only have query, mutation and subscription operations.', operation);
}
;