Skip to content

Commit

Permalink
fix(gql-fastify): update types for graphql-fastify
Browse files Browse the repository at this point in the history
  • Loading branch information
jmcdo29 committed Jul 18, 2020
1 parent a097842 commit 83335e6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 11 deletions.
13 changes: 6 additions & 7 deletions integration/src/gql/gql.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import { GqlResolver } from './gql.resolver';
@Module({
imports: [
GraphQLModule.forRoot({
context: ({ req, res, request, reply }) => {
if (req && res) {
return { req, res };
} else if (request && reply) {
return { req: request, res: reply };
}
},
context: ({ req, res, request, reply }) => ({
req,
res,
request,
reply,
}),
autoSchemaFile: true,
}),
],
Expand Down
4 changes: 2 additions & 2 deletions packages/platform-graphql-fastify/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export class AppModule {}

> Note: Due to the nature of subscriptions and the data available from the base ones, it is not possible at this time to log what subscriptions are made in the Ogma fashion.
Because the interceptor needs access to the request and response objects, when configuring the `GraphqlModule` from Nest, you need to add the `req` to the GraphQL context. to do this, while configuring the `GraphqlModule`, set the `context` property as such:
Because the interceptor needs access to the request and response objects, when configuring the `GraphqlModule` from Nest, you need to add the `request` and `reply` to the GraphQL context. to do this, while configuring the `GraphqlModule`, set the `context` property as such:

```ts
GraphqlModule.forRoot({
context: ({ req }) => ({ req })
context: ({ request, reply }) => ({ request, reply })
});
```
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ export class GraphQLFastifyParser extends FastifyParser {
}

getRequest(context: ExecutionContext): FastifyRequest {
return this.getContext(context).getContext().req;
return this.getContext(context).getContext().request;
}

getResponse(context: ExecutionContext): FastifyReply<any> {
return this.getContext(context).getContext().res;
return this.getContext(context).getContext().reply;
}
}

0 comments on commit 83335e6

Please sign in to comment.