-
Notifications
You must be signed in to change notification settings - Fork 9
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
Hiding operations based on the result of a function #9
Comments
I think the schema transformation should be a static and stateless operation. Other patterns are possible for adding conditional logic. I don't think that should be part of the defined transform, but should be dealt with on a higher level (conditional transformSchema, not conditional transform inside it). if (req.user.role != 'ADMIN') {
finalSchema = transformSchema(schema, {
Mutation: {
'deleteUser': false
}
})
} |
That's a good point @kbrandwijk. You're basically saying you can do that logic somewhere else (either by surrounding it in a conditional, or running a function that returns transformSchema(schema, {
Mutation: {
'deleteUser': (fieldMap, fieldName) => { ...perform some magic with args passed... },
}
}); As I said before, I'm starting to side with you. The only way something like this would be useful is if there are significant changes/processing done to the rules you pass. Otherwise, you can just do as you say: process/inspect the rules beforehand and come up with the result you need and stick it into |
Can you share a concrete example of the kind of arguments that you want to process in a function like that? Because I can't envision it right now. |
As mentioned in the schema transformation documentation, one can hide operations in a
transformSchema
call by setting boolean values against desired queries/mutations like so:However, there may be situations where you'd want to conditionally hide one query/mutation or another. This functionality could be provided by functions, but I'm still on the fence how, especially when functions are used to modify arguments before they hit a resolve (so how could you tell a "hiding" function from a "modifying" function?). I still feel this could be a good feature.
The text was updated successfully, but these errors were encountered: