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

testkit addPlugin behavior does not match envelop's #2185

Open
1 of 4 tasks
jdolle opened this issue Mar 20, 2024 · 1 comment
Open
1 of 4 tasks

testkit addPlugin behavior does not match envelop's #2185

jdolle opened this issue Mar 20, 2024 · 1 comment
Assignees
Labels
kind/bug Something isn't working stage/0-issue-prerequisites Needs more information before we can start working on it stage/2-failing-test A failing test was created that describes the issue

Comments

@jdolle
Copy link

jdolle commented Mar 20, 2024

Issue workflow progress

Progress of the issue based on the
Contributor Workflow

  • 1. The issue provides a
    minimal reproduction available on
    Stackblitz.
    • Please install the latest @envelop/* packages that you are using.
    • Please make sure the reproduction is as small as possible.
  • 2. A failing test has been provided
  • 3. A local solution has been provided
  • 4. A pull request is pending review

Describe the bug

addPlugin behavior differs for createTestkit vs passing plugins into graphql-yoga's createYoga

To Reproduce Steps to reproduce the behavior:

import { useApolloTracing } from "@envelop/apollo-tracing";
import { handleStreamOrSingleExecutionResult } from "@envelop/core";

import { assertSingleExecutionValue, createTestkit } from "@envelop/testing";
import { makeExecutableSchema } from "@graphql-tools/schema";

const useExample = () => {
  return {
    onPluginInit({ addPlugin }) {
      addPlugin(useApolloTracing());
    },
    onExecute() {
      return {
        onExecuteDone(payload) {
          handleStreamOrSingleExecutionResult(payload, ({ result, args, setResult }) => {
            // during test, this will log without the trace
            // but during normal execution, this will log with the trace
            console.log(result);
          });
        }
      }
    },
  }
}


// JEST TEST
test("calls #track", async () => {
  const schema = makeExecutableSchema({
    typeDefs: `
      type Query {
        foo: String
      }
      `,
    resolvers: {
      Query: {
        foo: jest.fn().mockResolveValue("ok"),
      },
    },
  });
  const testInstance = createTestkit([useExample()], schema);
  const result = await testInstance.execute(`{ errors }`);
});

Expected behavior

test kit flow call order should match yoga server / envelop server.
In both cases for the example above, the result should include the trace data.

Environment:

  • OS:
  • NodeJS:
  • @envelop/* versions:
    • @envelop/core: 5.0.0
    • graphql-yoga: 5.1.1
    • envelop/testing: 7.0.0

Additional context

If instead of implementing onExecute, I use addPlugin to add the same logic, it calls in the expected order from the testkit

@EmrysMyrddin EmrysMyrddin added kind/bug Something isn't working stage/2-failing-test A failing test was created that describes the issue labels Mar 20, 2024
@EmrysMyrddin EmrysMyrddin self-assigned this Mar 20, 2024
@EmrysMyrddin
Copy link
Collaborator

EmrysMyrddin commented Mar 22, 2024

Hi, thank you for raising this to our attention!

I have just added a test to our testing kit, and it appears the execution order is correct in both Envelop and Testkit.
So the problem you are facing is probably not related to this.

In fact, from what I see, it's a bit strange that you are seeing traces in the the normal execution, since your plugin's hooks should be executed before useApolloTracing ones (and if I well remember, it adds the tracing in onExecuteDone too. So if it happens in normal execution, it means something else is actually putting this tracing information elsewhere. Are you sure you don't also have the tracing plugin directly in your yoga configuration?

Can you provide a minimal reproduction with a Stackblitz or a repo we can clone?

@EmrysMyrddin EmrysMyrddin added the stage/0-issue-prerequisites Needs more information before we can start working on it label Mar 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working stage/0-issue-prerequisites Needs more information before we can start working on it stage/2-failing-test A failing test was created that describes the issue
Projects
None yet
Development

No branches or pull requests

2 participants