graphql-shield: Error thrown inside an async rule are not sent to the fallbackError function
Describe the bug
If an async rule throws inside a chain, the error is not sent to the fallbackError
function. The value is null.
Example
const editorIsEventOwner= chain(
isPromoterStaff,
rule({ cache: PermissionCache.STRICT })(
async (_parent: {}, args: { id: string }, ctx: Context) => {
const { id } = args;
const event = await findEvent(toInt(id), ctx); // This can throw an Error
if (!event) return false;
return event.ownerId === ctx.user?.id;
}
)
);
This will correctly not allow the user to proceed if the findEvent
fails, but it will not put the Error
in the first parameter of the the function.
About this issue
- Original URL
- State: open
- Created 4 years ago
- Reactions: 7
- Comments: 16 (8 by maintainers)
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
I created a wrapper for the rule function. I would be willing to rewrite part of the lib to support more native feature if @maticzav let me. I basically did it with nexus-shield. I think the shift to
throw
would be better.The workaround for us is to set
debug
totrue
in development. This way we can find out errors that are thrown instead of returned.https://codesandbox.io/s/example-graphl-shield-throw-mfgle?file=/index.js
Could you create a reproduction CodeSandbox?