Skip to content

Commit

Permalink
Merge pull request #2 from steinroe/main
Browse files Browse the repository at this point in the history
fix: replace fastify.inject with supertest and set useEnterWith for mercurius
  • Loading branch information
Papooch authored Oct 5, 2021
2 parents ebb28fd + 7c378d5 commit 185b4ca
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,8 @@ This package is 100% compatible with Nest-supported REST controllers.

For GraphQL, the ClsMiddleware needs to be [mounted manually](#manually-mounting-the-middleware) with `app.use(...)` in order to correctly set up the context for resolvers.

- ✔ Mercurius (Fastify)
- ⚠ Mercurius (Fastify)
- There's an [issue with CLS and Mercurius](https://github.com/Papooch/nestjs-cls/issues/1), so in order to work around it, you have to pass `useEnterWith: true` to the `ClsMiddleware` options.
- ⚠ Apollo (Express)
- There's an [issue with CLS and Apollo](https://github.com/apollographql/apollo-server/issues/2042), so in order to work around it, you have to pass `useEnterWith: true` to the `ClsMiddleware` options.

Expand Down
21 changes: 8 additions & 13 deletions test/gql/gql-mercurius.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { INestApplication } from '@nestjs/common';
import request from 'supertest';

import { Test, TestingModule } from '@nestjs/testing';
import { AppModule } from './gql-mercurius.app';
import { ClsMiddleware } from '../../src';
import {
Expand All @@ -19,28 +16,26 @@ describe('GQL Mercurius App', () => {
new FastifyAdapter(),
{ logger: false },
);
app.use(new ClsMiddleware({ generateId: true }).use);
app.use(new ClsMiddleware({ generateId: true, useEnterWith: true }).use);
await app.init();
await app.getHttpAdapter().getInstance().ready();
});

it('works with Mercurius', async () => {
const res = await app.inject({
method: 'POST',
url: '/graphql',
payload: {
const res = await request(app.getHttpServer())
.post('/graphql')
.send({
query: `query {
recipes {
id
title
description
}
}`,
},
});
const body = JSON.parse(res.body);
expect(body.data).toHaveProperty('recipes');
expect(body.data.recipes[0]).toEqual({
})
const data = res.body.data
expect(data).toHaveProperty('recipes');
expect(data.recipes[0]).toEqual({
id: 'OK',
title: 'OK',
description: 'OK',
Expand Down

0 comments on commit 185b4ca

Please sign in to comment.