-
-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rootValue and authed user #10
Comments
const fields = {
user: UsersTC.getResolver('findOne')
.wrapResolve(next => resolveParams => {
let rootValue = resolveParams.info.rootValue
return next(resolveParams);
})
.getFieldConfig()
} Altho this is not working: UsersTC.getResolver('findOne')
.removeArg('sort')
.wrapResolve(next => resolveParams => {
return next(resolveParams);
})
.getFieldConfig() removeArg() |
First of all use app.use('/graphql',
graphqlHTTP(req => ({
schema: GraphQLSchema,
graphiql: true,
context: {
userId: req.session.userId,
// ... some other params
},
}))
); If you want to connect some types, I recommend use In your case better to use ViewerTC.addRelation(
'user',
() => ({
resolver: UsersTC.getResolver('findById'),
args: {
_id: (source, args, context) => context.userId,
},
})
); If you want more complex user fetching, then you may use ViewerTC.addRelation(
'user',
() => ({
resolver: UsersTC.getResolver('findOne'),
args: {
filter: (source, args, context) => ({ _id: context.userId, actived: true, blocked: false }),
sort: null, // for removing arg from schema
},
})
); |
@nodkz big thanks, this is really a awesome API 🎉 |
Try to not modify basic resolvers, generated by Resolver - is a helper/prototype which you may use many times when you connect types with each other in your schema. Of course, you may change default resolvers if you want to do it globally for all future use case. If it is desired behavior. But when you converting mongoose models, I recommend use customization options (to disable some fields, args, resolvers), rather than change it via calling resolver methods. |
|
Could you explain how to get the current user if you have a id set at graphql
rootValue
the id is accessed from
rootValue.id
Schema file have this right now:
The text was updated successfully, but these errors were encountered: