-
Notifications
You must be signed in to change notification settings - Fork 15
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
Filtering output #125
Filtering output #125
Conversation
basic tests are in there are designed correctly // replacement "output" is not yet in there
initial unit tests pass // need to ensure that we are "replacing" only on String scalar types. we are going to actually return an error at this point
Great work so far! Give me a shout when it's ready for review! :) |
make sure registration errors out correctly if not done correctly
how to use, but also some examples
@jonnydgreen So.. 2 issues.. I can't seem to generate unit tests for this line 59 or line 108-109. Ideas? Also the refresh.js unit test fails all 4. Not sure why. Also added some documentation in the mix. I will need some proof reading by a 2nd person after I re-read it tomorrow. It will form the basis of the example I place in the example folder once done. |
If you define a policy that returns an error instance that should do the trick!
If you define a field resolver this should also do the trick :)
Do you have any error logs? |
I am certain that this was passing prior to me starting... |
@jonnydgreen Ok. Throwing up the 'white' flag. Not sure how to generate an error that would trigger or the resolve. Also with the refresh not sure. I think it's also causing another line not to "pass" check with 100% coverage:
|
Thanks for the update @Bugs5382, fantastic work! I'm currently away but will be back on Sunday where I'll take a closer look and see what I can find/replicate :) |
Hi @Bugs5382 !
For this one, if you define a schema of the form, this should do the trick :) directive @filterData (disallow: String!) on FIELD_DEFINITION
type Message {
message: String!
notes: String
}
type Query {
publicMessages: @filterData (disallow: "no-public-messages")
} The reason why this is picked up the coverage is because the field
For this one, the following policy should do the trick async function hasFilterPolicyReturnError (authDirectiveAST, parent, args, context, info) {
const notNeeded = authDirectiveAST.arguments.find(arg => arg.name.value === 'disallow').value.value
const policyPassed = !context.auth.permission.includes(notNeeded)
if (!policyPassed) {
// This is the key bit
return new MER_AUTH_ERR_FAILED_POLICY_CHECK(info.fieldName)
}
} |
fixes unit testing Co-authored-by: Jonny Green <[email protected]>
I'll get the other two inserted and updated soon! |
Ok. So after you pointed that it is on a "resolver", I made it error out in the auth.js file: [kWrapFieldResolverReplace] (schemaTypeField, fieldPolicy, fieldReplace) {
// Overwrite field resolver
const fieldName = schemaTypeField.name
if (typeof schemaTypeField.resolve === 'function') {
throw new MER_AUTH_ERR_USAGE_ERROR('Replacement can not happen on a resolver. Only a field.')
} else {
schemaTypeField.resolve = this[kMakeProtectedResolverReplace](fieldPolicy, (parent) => parent[fieldName], fieldReplace)
}
} and updated the test to check for the error output. I am not sure doing filtering on the resolver/function does any good. I didn't want to have to check for string. Unless you think it's "needed". I never envisoneded it that way @jonnydgreen . 100% coverage coming! |
removed resolver filtering // fixed refresh test again // 100% code coverage!
🥳 🎉 |
Fantastic work! I'll take a detailed look tomorrow evening! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Functionally looks great, just some comments around testing and docs! 🚀 Could we add an example as well? :)
errors were still coming over for null values // unit tests updated and fixed code that does not send an error back
if outputPolicyErrors.enabled was 'true,' then no errors would show on a failure other than schema ones if they excited after a replacement
Example uploaded. Unit testing and come code fixed to solve them. 👍 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
@jonnydgreen Thank you!!! 🥇 |
You're welcome and thank you to you too! If it's okay, I'll get this deployed this week as I'd like to include this with another change! @mcollina I'm thinking of including this as part of v5 (semver major to remove Node.js v14+16 support and add Node.js v20 support), wdyt? |
@jonnydgreen Ya. Not a problem. I been coding with v20, and I found no issues. Version 14 is not on my internal software plan. |
add node v20
Registering a "directive" that can check a user's role could modify the "output" of string types if the directive "apply policy" returned 'false'. If the 'valueOverride' value has a string or a function that returns a string, that is what will go in it's place. Otherwise it will make the field null regardless of the graphql type. This will override any graphql errors that might say that something was missing.
Will Close #124