Skip to content

Added runAuthAfterResolver option to change execution order of authorization rules and resolvers. #1518

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions packages/graphql-shield/src/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,20 @@ function generateFieldMiddlewareFromRule(

// Execution
try {
const res = await rule.resolve(parent, args, ctx, info, options)

let res

if (!options.runAuthAfterResolver) {
res = await rule.resolve(parent, args, ctx, info, options)
}

const resolverResult = await resolve(parent, args, ctx, info)

if (options.runAuthAfterResolver) {
res = await rule.resolve(parent, args, ctx, info, options)
}

if (res === true) {
return await resolve(parent, args, ctx, info)
return resolverResult
} else if (res === false) {
if (typeof options.fallbackError === 'function') {
return await options.fallbackError(null, parent, args, ctx, info)
Expand Down
1 change: 1 addition & 0 deletions packages/graphql-shield/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export type IFallbackErrorType = Error | IFallbackErrorMapperType
// Generator Options

export interface IOptions {
runAuthAfterResolver: boolean
debug: boolean
allowExternalErrors: boolean
fallbackRule: ShieldRule
Expand Down