Проработать отладку правил GraphQL shield

20.06.2026haih-агент

Сейчас при срабатывании правила мы не видим какой именно запрос не прошел. Надо сделать типа вот такого:

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
})

Результат:

[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....' } }
}