Repository URL to install this package:
|
Version:
0.0.1 ▾
|
// export { createTestClient } from 'apollo-server-testing'
import { makeExecutableSchema } from 'graphql-tools'
import { ApolloServer } from 'apollo-server'
import { Config } from 'apollo-server-core'
// @todo issue with graphql versions
// import { directivesIndexed } from '../../src/directives'
import { createTestClient, MockRequestInternals } from './createTestClient'
export { gql } from 'apollo-server'
export { createTestClient, MockRequestInternals } from './createTestClient'
export { makeExecutableSchema } from 'graphql-tools'
export const onListen = (value: { url: string }) => {
console.log(`🚀 Server ready at ${value.url}`)
}
export type ServerOptions = Config & { listen?: boolean }
export const toServer = (options: ServerOptions) =>
new ApolloServer({
context: (request: Request) => ({ env: {} }),
tracing: false,
debug: false,
playground: false,
introspection: false,
/**
* @see https://github.com/apollographql/apollo-client/issues/1649
*/
formatError(error) {
// require('fliplog').quick(error)
console.error(error)
// @todo - could always pass in in a preset
// throw error
return JSON.stringify(error, undefined, 2)
},
formatResponse(response) {
return response
},
...options,
})
export interface ToTestArgs {
typeDefs: any
resolvers: any
options?: ServerOptions
mockRequestInternals?: MockRequestInternals
}
export const toTest = (args: ToTestArgs) => {
const schema = makeExecutableSchema({
typeDefs: args.typeDefs,
resolvers: args.resolvers,
// schemaDirectives: directivesIndexed,
})
const serverArgs = { schema, ...args.options }
const server = toServer(serverArgs)
const { query, mutate } = createTestClient({
server,
mockRequestInternals: args.mockRequestInternals,
})
return {
query,
mutate,
server,
schema,
mockRequestInternals: args.mockRequestInternals,
}
}