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

directive on FIELD_DEFINITION doesn't get called when subscribe #6328

Open
4 tasks
UchihaYuki opened this issue Jul 8, 2024 · 0 comments
Open
4 tasks

directive on FIELD_DEFINITION doesn't get called when subscribe #6328

UchihaYuki opened this issue Jul 8, 2024 · 0 comments

Comments

@UchihaYuki
Copy link

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

To Reproduce Steps to reproduce the behavior:

extend type Subscription {
  authenticated: String @authenticated
}
const typeDefs = `
  directive @authenticated on FIELD_DEFINITION
`;

function transformer(openidConfigurationUrl: string) {
  return (schema: GraphQLSchema) =>
    mapSchema(schema, {
      [MapperKind.OBJECT_FIELD]: (
        fieldConfig: GraphQLFieldConfig<any, IamGraphqlServerContext, any>,
      ) => {
        const options = getDirective(schema, fieldConfig, "authenticated")?.[0];
        if (!options) return fieldConfig;

        const { resolve = defaultFieldResolver } = fieldConfig;
        fieldConfig.resolve = async (source, args, context, info) => {
          console.log("@authenticated");
          const idTokenPayload =
            await getIdTokenPayloadFromContext(openidConfigurationUrl)(context);
          if (!idTokenPayload) throw new Error401();

          context.idTokenPayload = idTokenPayload;

          return await resolve(source, args, context, info);
        };
        return fieldConfig;
      },
    });
}
  Subscription: {
    authenticated: {
      subscribe: async (_, __, context) => {
        console.log("subscribe authenticated", context.idTokenPayload, context.connectionParams);
        return (async function* () {
          for (const i of [0, 1, 2]) {
            yield { authenticated: "authenticated" };
          }
        })();
      },
    },
  },

Expected behavior
console.log("@authenticated");
should be executed before
console.log("subscribe authenticated", context.idTokenPayload, context.connectionParams);
But
console.log("@authenticated");
is executed after every emitted value

Environment:

  • OS: Windows 10
  • @graphql-tools/...: 10.3.1
  • NodeJS: 20.14.0

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant