Skip to content

Commit

Permalink
add failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
EmrysMyrddin committed Apr 28, 2023
1 parent 39714eb commit 283e7ab
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
17 changes: 11 additions & 6 deletions examples/express/__integration-tests__/express.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,15 @@ import { buildApp } from '../src/app.js'
import request from 'supertest'
import express from 'express'

function getTests(app: Express.Application) {
function getTests(app: Express.Application, endpoint = '/graphql') {
it('should show GraphiQL', async () => {
const response = await request(app)
.get('/graphql')
.set('Accept', 'text/html')
const response = await request(app).get(endpoint).set('Accept', 'text/html')
expect(response.statusCode).toBe(200)
expect(response.headers['content-type']).toContain('text/html')
})
it('should handle POST requests', async () => {
const response = await request(app)
.post('/graphql')
.post(endpoint)
.send({ query: '{ hello }' })
expect(response.statusCode).toBe(200)
expect(response.body).toStrictEqual({
Expand All @@ -23,7 +21,7 @@ function getTests(app: Express.Application) {
})
it('should handle file uploads', async () => {
const response = await request(app)
.post('/graphql')
.post(endpoint)
.field(
'operations',
JSON.stringify({
Expand Down Expand Up @@ -60,3 +58,10 @@ describe('express + body parser', () => {

getTests(app)
})

describe('express + custom endpoint', () => {
const app = express()
buildApp(app, '/api/graphql/v1')

getTests(app, '/api/graphql/v1')
})
7 changes: 5 additions & 2 deletions examples/express/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { createYoga, createSchema } from 'graphql-yoga'
import express from 'express'

export function buildApp(app: ReturnType<typeof express>) {
export function buildApp(
app: ReturnType<typeof express>,
endpoint = '/graphql',
) {
const graphQLServer = createYoga({
schema: createSchema({
typeDefs: /* GraphQL */ `
Expand Down Expand Up @@ -38,7 +41,7 @@ export function buildApp(app: ReturnType<typeof express>) {
logging: false,
})

app.use('/graphql', graphQLServer)
app.use(endpoint, graphQLServer)

return app
}

0 comments on commit 283e7ab

Please sign in to comment.