Skip to content

Accessing graphql context from loader #28

Description

@andreialecu

In loaders it is usually necessary to access the graphql execution context.

As per NestJS documentation I attempted to do it like this:

import { CONTEXT } from "@nestjs/graphql";

@Injectable({ scope: Scope.REQUEST })
export class CanEditMatchdayLoader implements NestDataLoader<string, boolean> {
  constructor(
    private readonly matchdayService: MatchdayService,
    @Inject(CONTEXT) private context: any,
  ) {
    console.log(context); // prints undefined
  }

  generateDataLoader(): DataLoader<string, boolean> {
     ...
  }
}

But context appears to be undefined no matter what I do. I assume this is caused by nestjs-dataloader somehow, because the nestjs documentation specifically mentions this use case.

Alternatively, this would also seem to be fixed by #11

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions