graphql-hive / graphql-hive/envelop

useContextValuePerExecuteSubscriptionEvent: Spread operator fails to merge objects when contextValue is a class

Open
#2,397 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
827
Forks
132
PR merge metrics
No merged PRs in 30d

Description

### Issue workflow progress

**Describe the bug**

- A spread operator is being used to merge the previous context and the new context. If the context is a class and there are methods in its prototype, it will lose the prototype methods during this merging.
- Code from [https://github.com/n1ru4l/envelop/blob/main/packages/plugins/execute-subscription-event/src/index.ts](https://github.com/n1ru4l/envelop/blob/main/packages/plugins/execute-subscription-event/src/index.ts)
```js
onSubscribe({ args, setSubscribeFn }) {
const executeNew = makeExecute(async executionArgs => {
const context = await createContext({ args });
try {
return await execute({
...executionArgs,
// GraphQL.js 16 changed the type of contextValue to unknown
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
contextValue: { ...executionArgs.contextValue, ...context?.contextPartial },
});
} finally {
context?.onEnd?.();
}
});
setSubscribeFn(subscribe(executeNew));
},
```

**Expected behavior**
- The object's property should be replaced with a new value, rather than merging the objects using the spread operator.

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.