UNPKG

983 BPlain TextView Raw
1import type { ExecutionResult, GraphQLSchema } from 'graphql'
2import { execute as graphqlExecute, graphql } from 'graphql'
3import type { BaseInput } from './types.js'
4
5interface Input extends BaseInput {
6 schema: GraphQLSchema
7}
8
9export const execute = async (input: Input): Promise<ExecutionResult> => {
10 switch (typeof input.document) {
11 case `string`: {
12 return await graphql({
13 schema: input.schema,
14 source: input.document,
15 // contextValue: createContextValue(), // todo
16 variableValues: input.variables,
17 operationName: input.operationName,
18 })
19 }
20 case `object`: {
21 return await graphqlExecute({
22 schema: input.schema,
23 document: input.document,
24 // contextValue: createContextValue(), // todo
25 variableValues: input.variables,
26 operationName: input.operationName,
27 })
28 }
29 default:
30 throw new Error(`Unsupported GraphQL document type: ${String(document)}`)
31 }
32}