Skip to content

Middlewares are skipped #13

@benknab

Description

@benknab

Customer middleware is called after shield plugin.

● nexus:server listening  --  url: 'http://localhost:4000/graphql'
● nexus:server:request Authentication Rule
● nexus:server:request Before Resolver
● nexus:server:request After Resolver
// app.ts
schema.middleware((_config) => {
  return async (root, args, ctx, info, next) => {
    ctx.log.info('Before Resolver')
    await next(root, args, ctx, info)
    ctx.log.info('After Resolver')
  }
})

use(
  shield({
    rules,
  }),
)

// permissions.ts
const isAuthenticated = rule({ cache: 'contextual' })(
  async (parent, args, ctx, info) => {
    ctx.log.info('Authentication Rule')
    const userId = ctx.req.headers.authorization
    return Boolean(userId)
  },
)

I would expect the custom middlewares, defined before the shield plugin, to be called before the shield rules.
I'm not sure if this is a bug originating from this plugin, or the Nexus core's plugin/middleware behavior is bugged.

Repo for reproduction: https://github.com/bkiac/nexus-graphql-middleware-order

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions