Files
speckle-server/packages/server/test/graphqlHelper.ts
T
Kristaps Fabians Geikins 05f11a26da feat: batch commit delete/move (#1016)
* feat: batch delete/move commits

* fix: ts linter issue
2022-09-22 16:49:18 +03:00

28 lines
838 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 extends Record<string, any> = Record<string, any>,
V extends Record<string, any> = Record<string, any>
>(
apollo: ApolloServer,
query: DocumentNode,
variables?: V
): Promise<TypedGraphqlResponse<R>> {
return (await apollo.executeOperation({
query,
variables
})) as TypedGraphqlResponse<R>
}