swc/bundler/tests/.cache/deno/8c1f385f47be317fcd56c78a920aed329ae26cbf.ts
강동윤 bbaf619f63
fix(bundler): Fix bugs (#1437)
swc_bundler:
 - [x] Fix wrapped esms. (denoland/deno#9307)
 - [x] Make test secure.
2021-03-02 17:33:03 +09:00

41 lines
1.1 KiB
TypeScript

// Loaded from https://deno.land/x/graphql_deno@v15.0.0/lib/utilities/getOperationRootType.js
import { GraphQLError } from '../error/GraphQLError.js';
/**
* Extracts the root type of the operation from the schema.
*/
export function getOperationRootType(schema, operation) {
if (operation.operation === 'query') {
const queryType = schema.getQueryType();
if (!queryType) {
throw new GraphQLError('Schema does not define the required query root type.', operation);
}
return queryType;
}
if (operation.operation === 'mutation') {
const mutationType = schema.getMutationType();
if (!mutationType) {
throw new GraphQLError('Schema is not configured for mutations.', operation);
}
return mutationType;
}
if (operation.operation === 'subscription') {
const 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);
}