graphql-hive / graphql-hive/envelop

testkit addPlugin behavior does not match envelop's

Open
#2,185 1 comment 0 reactions 1 assignee Claimed by @EmrysMyrddin View on GitHub
kind/bug stage/0-issue-prerequisites stage/2-failing-test
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

### Issue workflow progress

_Progress of the issue based on the
[Contributor Workflow](https://github.com/the-guild-org/Stack/blob/master/CONTRIBUTING.md#a-typical-contributor-workflow)_

- [ ] 1. The issue provides a
[minimal reproduction](https://en.wikipedia.org/wiki/Minimal_reproducible_example) available on
[Stackblitz](https://stackblitz.com/fork/node).
- _Please install the latest `@envelop/*` packages that you are using._
- _Please make sure the reproduction is as small as possible._
- [x] 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:

```ts
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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.