Skip to content

Commit

Permalink
Create symbols with Symbol.for() (#5131)
Browse files Browse the repository at this point in the history
* Create symbols with Symbol.for()

When multiple copies of `@graphql-tools/delegate` are available in a workspace (eg: because `stitch` and `wrap` depend on different versions), creating symbols with `Symbol()` can lead to bugs when one version of `delegate` sets an object property using its version of the symbol which the other `delegate` instance will not be able to access. Using `Symbol.for()` fixes this: as long as both versions of delegate use the same string description, they will refer to the same symbol.

* Add changeset
  • Loading branch information
neumark authored Mar 31, 2023
1 parent e8f0b0e commit f26392a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/bright-glasses-watch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphql-tools/delegate': patch
---

Create symbols with Symbol.for() because multiple copies of delegate cause stitching bugs otherwise.
6 changes: 3 additions & 3 deletions packages/delegate/src/symbols.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const UNPATHED_ERRORS_SYMBOL = Symbol('subschemaErrors');
export const OBJECT_SUBSCHEMA_SYMBOL = Symbol('initialSubschema');
export const FIELD_SUBSCHEMA_MAP_SYMBOL = Symbol('subschemaMap');
export const UNPATHED_ERRORS_SYMBOL = Symbol.for('subschemaErrors');
export const OBJECT_SUBSCHEMA_SYMBOL = Symbol.for('initialSubschema');
export const FIELD_SUBSCHEMA_MAP_SYMBOL = Symbol.for('subschemaMap');

0 comments on commit f26392a

Please sign in to comment.