developer239/node-type-orm-graphql

View on GitHub
src/test-utils/gCall.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { graphql, GraphQLSchema } from 'graphql'
import { createSchema } from '~/createSchema'

// Conveniently represents flow's "Maybe" type https://flow.org/en/docs/types/maybe/
type Maybe<T> = null | undefined | T

interface Options {
  source: string
  variableValues?: Maybe<{
    [key: string]: string | number | object
  }>
  contextValue?: any
}

let schema: GraphQLSchema

export const gCall = async ({ source, variableValues, contextValue }: Options) => {
  if (!schema) {
    schema = await createSchema()
  }

  return graphql({
    schema,
    source,
    variableValues,
    contextValue,
  })
}