Comments (3)
Here is a solution that worked for me with respect to client instantiation with request scoped headers
// gql-client.module.ts
import { GraphQLRequestModule } from '@golevelup/nestjs-graphql-request';
import { Global, Module } from '@nestjs/common';
import { moduleConfig } from '~/config';
@Global()
@Module({
imports: [
GraphQLRequestModule.forRoot(GraphQLRequestModule, moduleConfig.gqlClient),
],
providers: [],
exports: [GraphQLRequestModule],
})
export class GqlClientModule {}
// gql-client.decorator.ts
import { InjectGraphQLClient } from '@golevelup/nestjs-graphql-request';
import { Injectable, PipeTransform, createParamDecorator } from '@nestjs/common';
import { GraphQLClient } from 'graphql-request';
import { getSdk, type Sdk } from './generated';
export type IGql = Sdk;
@Injectable()
export class GqlClientPipe implements PipeTransform<ExecutionContext, Sdk> {
constructor(@InjectGraphQLClient() private readonly client: GraphQLClient) {}
transform(ctx: ExecutionContext) {
// Your logic to build headers
const headers = {
'X-SOURCE': createHmac(....)
};
return getSdk(this.client, (action) => action(headers));
}
}
export const Gql = () => createParamDecorator((data,ctx)=>ctx)(GqlClientPipe);
Example usage
// hi-command.ts
@Injectable()
export class HiCommand {
@TextCommand({ name: 'hi'})
async onHi(@Reply() reply: EventReply, @Gql() gql: IGql) {
const { me } = await gql.Me();
return reply.text(JSON.stringify(me));
}
}
from nestjs.
Thanks, @wolffparkinson!
from nestjs.
It looks like @wolffparkinson solution should work enough for your use case but if you feel that you're able to have a PR with this feature implemented, I'll be happy to review but meanwhile, I'm marking this as closed
from nestjs.
Related Issues (20)
- Single Channel Configuration Across Multiple @RabbitSubscribe Decorators Not Working as Expected
- No delivery mode option on AmqpConnection.request method HOT 2
- RabbitMQ: RabbitSubscribe using a handler name without corresponding handler config asserts randomized queues HOT 3
- rabbitmq: consumerTags are not cleaned up on connection/channel disconnect
- rabbitmq: canceled consumers are resumed if connection/channel reconnects HOT 1
- rabbitmq: direct sending to queue without the need for exchanges HOT 1
- rabbitmq: binding a queue to exchange without a routingKey
- ts-jest: Cannot create mock of a class which has private dependencies in constructor HOT 1
- rabbitmq: handlers didn't works in app-non-pub HOT 1
- golevelup/nestjs-stripe: project can not compile
- Stripe Test Webhook HOT 1
- Stripe webhooks - "undefined" is not valid JSON HOT 2
- How should I use this within RabbitSubscribe method?
- ts-vitest: using with `vi.spyOn` isn't working
- golevelup/nestjs-graphql-request: update dependencies [email protected]
- NestJs-rabbitmq Connection loss without reason && No reconnect
- Vhost connection HOT 1
- decorators param for Stripe webhook not works HOT 1
- Problem to connect RabbitMQ in Docker HOT 3
- Stripe v15 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs.