graphql-compose / graphql-compose/graphql-compose-mongoose
Example for proper definition of addResolver with typescript and v9.x.x
- Dominant language
- TypeScript
- Stars
- 706
- Forks
- 98
- PR merge metrics
- No merged PRs in 30d
Description
hey there,
i am having trouble defining a new `addResolver` with the right types. This is the user:
```js
export interface IUser extends IBaseAttributes {
email: string;
password: string;
passwordResetToken: string;
passwordResetExpires: number;
activated: boolean;
activationToken: string;
}
const UserSchema = new mongoose.Schema(
{
email: { type: String, required: true, unique: true },
password: { type: String, required: true },
passwordResetToken: { type: String },
passwordResetExpires: { type: Number },
activated: { type: Boolean },
activationToken: { type: String },
},
{ timestamps: true, collection: "user" }
);
export const User = mongoose.model(
"User",
UserSchema
);
export const UserTC = composeMongoose(User);
```
This is how i would add a new resolver:
```js
UserTC.addResolver({
name: "signUp",
type: UserTC.mongooseResolvers.createOne().getType(),
args: UserTC.mongooseResolvers.createOne().args,
resolve: async ({ source, args, context, info }) => {
// Here it says that source, args etc are of type 'any'. I was expecting the types to be inferred.
// if not, which types should be used? and is there a best practice or a
},
});
```
Since a hell lot of types are defined, my understanding was, that the types for `resolve` should be infered. I could not find any documentation on this.
In another issue i read that the "addResolver" is more or less deprecated in the sense that one should use the new factory functions because they have quite a few benifits over the "old way".
For that i wasnt able to find any documentation also. How would i go and add a custom resolver with the factory?
Thank you!
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.