graphql-compose / graphql-compose/graphql-compose-mongoose

graphql-compose-mongoose with serverless environment missing mongooseResolvers

Open
#362 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
706
Forks
98
PR merge metrics
No merged PRs in 30d

Description

Hey,

i am trying to integrate `graphql-compose-mongoose` with a serverless framework, in my case `nextjs`.

I was getting the following error:

```
Error: You try to generate GraphQL Type with name from mongoose model but this type already exists in SchemaComposer. Please choose another type name "composeWithMongoose(model, { name: 'NewTypeName' })", or reuse existed type "schemaComposer.getOTC('TypeName')", or remove type from SchemaComposer before calling composeWithMongoose method "schemaComposer.delete('TypeName')".
```

So i created the following helper function that will look for the previously created ObjectType or add it to the schemaComposer:

```js
const createObjectTC = ({
model,
customizationOptions = {},
}: {
model: Model, {}, {}>;
customizationOptions: any;
}) => {
let ModelTC = null;

try {
ModelTC = schemaComposer.getOTC(model.modelName)
} catch {
ModelTC = composeMongoose(model, customizationOptions);
}

return ModelTC;
};
```

I would use it like this:

```js
...

export const UserTC = createObjectTC({
model: User,
customizationOptions: {},
});
```

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:

```js
serSchemaComposer.Query.addFields({
userSignUp: UserTC.mongooseResolvers.findById(),
});
```

The error:

```js
Property 'mongooseResolvers' does not exist on type 'ObjectTypeComposer | (ObjectTypeComposer, any> & { mongooseResolvers: GenerateResolverType, any>; })'.
Property 'mongooseResolvers' does not exist on type 'ObjectTypeComposer'.
```


Is there any function than will do the same as `getOTC` but also add the `mongooseResolvers`?

Thank you.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.