1 | import type { ExecutionResult, GraphQLSchema } from 'graphql'
|
2 | import { execute as graphqlExecute, graphql } from 'graphql'
|
3 | import type { BaseInput } from './types.js'
|
4 |
|
5 | interface Input extends BaseInput {
|
6 | schema: GraphQLSchema
|
7 | }
|
8 |
|
9 | export 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 |
|
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 |
|
25 | variableValues: input.variables,
|
26 | operationName: input.operationName,
|
27 | })
|
28 | }
|
29 | default:
|
30 | throw new Error(`Unsupported GraphQL document type: ${String(document)}`)
|
31 | }
|
32 | }
|