Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

property 'requestId' of 'context._tgdContext' is undefined #37

Open
benja128 opened this issue Jul 15, 2022 · 6 comments
Open

property 'requestId' of 'context._tgdContext' is undefined #37

benja128 opened this issue Jul 15, 2022 · 6 comments

Comments

@benja128
Copy link

Im trying to load a list of workout-sessions and then load them into the dataloader.
The dataloader is being used in a fieldresolver. The goal is to check if any of the workout-sessions, exist in another collection and then return either true or false.

For testing, i have just tried to return a list with all true...

The fieldresolver:

@FieldResolver(returns => Boolean)
@Loader<string, Boolean>(async ids => {
	const userSelections = await Userselections.find({ _id: { $in: ids } });
	return [true];
})
is_favorite(@Root() root: WorkoutSession) {
	return (dataloader: DataLoader<string, Boolean>) =>
		dataloader.load(root._id.toString());
}

I get this error:

Screenshot 2022-07-15 at 11 30 41

Does anyone know a solution?

I am using TypeScript, Express and MongoDB

@alfonsogarza
Copy link

Seems like Apollo Server is required. Did you configure it?

@alfonsogarza
Copy link

I was able to get this to 'work' with TypeGraphQL without Apollo by doing this in my GraphQl configs. I based it of this.

Caution I haven't tested it fully and not sure the delete is the same as reset in Container.

async customExecuteFn (args: ExecutionArgs) {
    args.contextValue._tgdContext = {
        requestId: uuidv4(),
        typeormGetConnection: <... typeormconnection ... >
    };

    const result = await execute(args);

    delete args.contextValue._tgdContext;

    return result;
}

@planecore
Copy link

@alfonsogarza Hey! Did you find a better way or is this the best way you've found?

@alfonsogarza
Copy link

I ended up using DataLoader directly and keeping a cache of loaders in the graphQL context instead of using this library - flip side is that I, of course, can't simply use decorators and have to manually call the loaders (which I really only do inside my field resolvers).

@laukaichung
Copy link

laukaichung commented Aug 22, 2022

I ran into this error with Automatic Persisted Queries (APQ) enabled for the apollo server v3. The first request sent to the server returns this error, and APQ isn't working:

 Internal server error Cannot read properties of undefined (reading 'requestId') {"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"stacktrace":["TypeError: Cannot read properties of undefined (reading 'requestId')","    at Object.willSendResponse (/home/project/watch/web/node_modules/type-graphql-dataloader/dist/plugins/apollo-server/ApolloServerLoaderPlugin.js:17:73)"

I have to manually add _tgdContext to the context in the apollo server config to make APQ work again, not ideal at all:

  const apolloServer = new ApolloServer({
    cache: new BaseRedisCache({
      client: redisClient,
    }),
    context: async ({ req, res }) => {
      const context = {} as GqlContext;
      context["_tgdContext"] = {
        requestId: uuidv4(),
        typeormGetConnection: () => AppDataSource,
      };
      return context;
    },
 })

Has anyone run into this similar issue with APQ enabled?

@geoyws
Copy link

geoyws commented Jan 10, 2024

This has been working for us since March 2023. The new pull request with tests passing is below 🙂:
https://github.com/slaypni/type-graphql-dataloader/pull/41/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants