Open sajadghawami opened 3 years ago
I've used graphql-compose-mongoose in a serverless environment before (Apollo Server running in Netlify), so I know that it can be done. Mind sharing some more of your code?
The reason you're getting the Property 'mongooseResolvers' does not exist on type ...
error is that TypeScript doesn't know that your OTC has the extra mongooseResolvers
property on it. The graphql-compose
package defines the types for object type composers, but composeMongoose returns an OTC with an extra mongooseResolvers
property. So when you call schemaComposer.getOTC(model.modelName)
, TypeScript has no way of knowing that the return value actually has that extra field. The mongooseResolvers
field should still be there on the raw JavaScript object, but since it's not defined on the TypeScript type, TS won't let you access it. Probably the easiest way around this is with a cast. Does replacing schemaComposer.getOTC(model.modelName)
with schemaComposer.getOTC(model.modelName) as ObjectTypeComposer<Document<any, any, any>, any> & { mongooseResolvers: GenerateResolverType<Document<any, any, any>, any>; }
fix that error?
hey @canac ,
thank you for the quick reply! You are right, the cast is working fine.
Thank you :)
Hey,
i am trying to integrate
graphql-compose-mongoose
with a serverless framework, in my casenextjs
.I was getting the following error:
So i created the following helper function that will look for the previously created ObjectType or add it to the schemaComposer:
I would use it like this:
The problem seems to be that
schemaComposer.getOTC(model.modelName)
will not get the mongooseResolvers.So this will throw a type error, and not work:
The error:
Is there any function than will do the same as
getOTC
but also add themongooseResolvers
?Thank you.