Task: Work on debugging GraphQL shield rules

Work on debugging GraphQL shield rules

20.06.2026haih agent

Now, when a rule triggers, we cannot see which specific request failed. We need to implement something like this:

import { rule } from 'graphql-shield'
import { PrismaContext } from '../../../context/interfaces'

export const isActive = rule()((
  _parent: unknown,
  _args: unknown,
  ctx: PrismaContext,
  info,
) => {
  const allow = ctx.currentUser?.status === 'active'

  if (!allow && process.env.NODE_ENV === 'development') {
    const { fieldName, operation, variableValues } = info

    console.error('[rule isActive] now Allowed', {
      fieldName,
      operation,
      variableValues,
    })
  }

  return allow
})

Result:

[rule isActive] now Allowed {
  fieldName: 'user',
  operation: {
    kind: 'OperationDefinition',
    operation: 'query',
    description: undefined,
    name: { kind: 'Name', value: 'user', loc: [Location] },
    variableDefinitions: [ [Object] ],
    directives: [],
    selectionSet: { kind: 'SelectionSet', selections: [Array], loc: [Location] },
    loc: Location {
      start: 0,
      end: 109,
      startToken: [Token],
      endToken: [Token],
      source: [Source]
    }
  },
  variableValues: { where: { id: 'cmqlq54....' } }
}