Skip to content

The expansion of the auth directive function is employed, whereby each procurement of authorization is identical #3152

Open
@cheft

Description

@cheft

Describe the bug

the expansion of the auth directive function is employed, whereby each procurement of authorization is identical, as though it has been cached.

import { getDirective, MapperKind, mapSchema } from '@graphql-tools/utils'

export default function authDirective() {
  return {
    authDirectiveTypeDefs: 'directive @auth(role: String) on FIELD_DEFINITION',
    authDirectiveTransformer: (schema) => mapSchema(schema, {
      [MapperKind.OBJECT_FIELD](fieldConfig) {
        const directive = getDirective(schema, fieldConfig, 'auth')?.[0]
        if (directive) {
          const { resolve } = fieldConfig
          fieldConfig.resolve = async (source, args, ctx, info) => {
            try {
              let token = ctx.request.headers.get('authorization') || ''
              console.log('111', ctx.request.headers)
              return resolve(source, args, ctx, info)
            } catch (e) {
              ctx.log.info(e)
            }
          }
          return fieldConfig
        }
      },
    }),
  }
}

Your Example Website or App

https://stackoverflow.com/help/mcve

Steps to Reproduce the Bug or Issue

In graphql-yoga version 5.1.0, utilizing graphql-tools/utils version 10.0.11, the expansion of the auth directive function is employed, whereby each procurement of authorization is identical, as though it has been cached. Reverting yoga to version 4.0.0 restores normalcy.

Expected behavior

Aspiring for functionality within graphql-yoga version 5.1.0.

Screenshots or Videos

No response

Platform

  • OS: [macOS]
  • NodeJS: v18.18.0
  • graphql-yoga 5.1.0
  • @graphql-tools/utils 10.0.11

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    stage/0-issue-prerequisitesNeeds more information before we can start working on it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions