vektah / dataloaden

go generate based DataLoader
MIT License
528 stars 79 forks source link

Does the dataloader need to be constructed for every request? #38

Closed nii236 closed 5 years ago

nii236 commented 5 years ago

I noticed that a lot of examples seem to construct new instances in the handlers. I would prefer to create my dataloaders while initialising the server.

This way I can avoid using context.

Can this be done? Can I embed a single instance of the dataloaders into the resolver struct to be reused across requests or does it need to be created every time? Will it keep track of what requests requested which IDs?

nii236 commented 5 years ago

After some time with the library, I believe the answer is yes. Dataloader needs a new instance so that you can give it a specific context for that request.