Skip to content
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

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

Open
cheft opened this issue Dec 25, 2023 · 1 comment
Labels
stage/0-issue-prerequisites Needs more information before we can start working on it

Comments

@cheft
Copy link

cheft commented Dec 25, 2023

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

@EmrysMyrddin EmrysMyrddin added the stage/0-issue-prerequisites Needs more information before we can start working on it label Jan 19, 2024
@EmrysMyrddin
Copy link
Collaborator

Hi @judastheo and thank you for the report!

Sorry but I'm not adding a lot here but just labeling it according to our new Contribution Guide and issue flow.

One way of pushing this forward would be to provide a reproduction example, for example on Stackblitz or Codepen.
Maybe even adding a failing test so we could get this into stage 2!

Thank you and sorry that this comment is not a complete solution (yet).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stage/0-issue-prerequisites Needs more information before we can start working on it
Projects
None yet
Development

No branches or pull requests

2 participants