graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
709 stars 94 forks source link

ApolloServer Context Help with addRelation using mongooseResolvers DataLoader #393

Closed MasterWorksHappy closed 2 years ago

MasterWorksHappy commented 2 years ago

I am creating an 'addRelation' using a dataLoader resolver. The testing results with Jest are as expected using the server's graphQL schemas and mongoose models. The relation data is returned correctly. However, when I execute the same query from Apollo GraphQL Playground, the result contains null for the relation. The rest of the result is correct.

I believe this is related to using the dataLoader and ApolloServer not having 'context' for the dataLoader query. I am actually not really sure. I am hoping someone can share how they setup ApolloServer 'context' for use with 'mongooseResolvers.dataLoader'. Thank you!

MasterWorksHappy commented 2 years ago

The bane of my existence is mongoose.Types.ObjectId() fields created in my synthetic data that load one way in production and another way in my test environment ... the old string versus ObjectId mismatch issue. At any rate, I have solved my issue.

Thank you for your work on this. It is a great time saver and quality enhancer!