Files
speckle-server/packages/server/test/graphqlHelper.ts
T
Kristaps Fabians Geikins b966f20fdb refactor(server): typescript support (#874)
Co-authored-by: Gergő Jedlicska <gergo@jedlicska.com>
2022-08-04 14:21:39 +02:00

28 lines
786 B
TypeScript

/* eslint-disable @typescript-eslint/no-explicit-any */
import { ApolloServer } from 'apollo-server-express'
import { GraphQLResponse } from 'apollo-server-types'
import { DocumentNode } from 'graphql'
import { Nullable } from '@/modules/shared/helpers/typeHelper'
type TypedGraphqlResponse<R = Record<string, any>> = GraphQLResponse & {
data: Nullable<R>
}
/**
* Use this to execute GQL operations from tests against an Apollo instance and get
* a properly typed response
*/
export async function executeOperation<
R = Record<string, any>,
V = Record<string, unknown>
>(
apollo: ApolloServer,
query: DocumentNode,
variables?: V
): Promise<TypedGraphqlResponse<R>> {
return (await apollo.executeOperation({
query,
variables
})) as TypedGraphqlResponse<R>
}