graphql-tools icon indicating copy to clipboard operation
graphql-tools copied to clipboard

Schema stitching bug when multiple versions of delegate in workspace

Open neumark opened this issue 2 years ago • 0 comments

Progress of the issue based on the Contributor Workflow

  • [ ] 1. The issue provides a reproduction available on Github, Stackblitz or CodeSandbox

    Make sure to fork this template and run yarn generate in the terminal.

    Please make sure the GraphQL Tools package versions under package.json matches yours.

  • [ ] 2. A failing test has been provided
  • [x] 3. A local solution has been provided
  • [x] 4. A pull request is pending review

Describe the bug

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.

The problem occurs in executeDelegationStage, when the selectionSet fields returned by the stitched subschema are merged with the existing fields. Due to multiple versions of delegate, each with it's own instance of OBJECT_SUBSCHEMA_SYMBOL, the subschema information associated with symbols set in annotateExternalObject() by one delegate instance cannot be accessed by executeDelegationStage() within another instance.

Using Symbol.for() fixes this: as long as both versions of delegate use the same string description, they will refer to the same symbol.

To Reproduce Steps to reproduce the behavior:

Our dependency tree:

└─ @cloud/unified@workspace:cloud/unified
   ├─ @graphql-tools/delegate@npm:8.4.2 [55f8a] (via npm:8.4.2 [55f8a])
   ├─ @graphql-tools/stitch@npm:8.4.2 [55f8a] (via npm:8.4.2 [55f8a])
   │  ├─ @graphql-tools/batch-delegate@npm:8.2.2 [bfa3d] (via npm:8.2.2 [bfa3d])
   │  │  └─ @graphql-tools/delegate@npm:8.4.2 [55f8a] (via npm:8.4.2 [55f8a])
   │  ├─ @graphql-tools/delegate@npm:8.4.2 [55f8a] (via npm:8.4.2 [55f8a])
   │  └─ @graphql-tools/wrap@npm:8.5.1 [bfa3d] (via npm:^8.3.1 [bfa3d])
   │     └─ @graphql-tools/delegate@npm:8.8.1 [ccd30] (via npm:8.8.1 [ccd30])

Expected behavior

Environment:

  • OS: linux
  • @graphql-tools/...:
  • NodeJS: 16.10.0

Additional context

neumark avatar Mar 27 '23 13:03 neumark