apollographql / apollographql/apollo-server

Execution instrumentation requires shallow-cloning the context value, which has negative side effects

Open
#3,146 4 comments 15 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
14k
Forks
2k
Avg merge
2d 14h
Merged PRs (30d)
2

Description

If the context is a javascript Proxy, Apollo Server fails to bring the proxy in the resolver due to the fact the the context gets cloned on each and every request. Callining the proxy will return the underlying target but will fail to bring the context as a Proxy in the resolver, losing all traps.

Please refer to line **242**: `const context = cloneObject(options.context);`
https://github.com/apollographql/apollo-server/blob/master/packages/apollo-server-core/src/runHttpQuery.ts

```
function cloneObject(object: T): T {
return Object.assign(Object.create(Object.getPrototypeOf(object)), object);
}
```

Is it possible to avoid cloning? Since the application creates the context, seems normal to expect the same object created to get into the resolver and not a clone.

Contributor guide

Open the contributing guide

Research direction

Start in packages/apollo-server-core/src/runHttpQuery.ts at line 242 and inspect cloneObject and how the context reaches the resolver. Verify the behavior with a JavaScript Proxy context; done means the resolver receives the original Proxy with its traps preserved rather than a shallow clone.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, typescript
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.