ardatan / graphql-mesh

🕸️ GraphQL Federation Framework for any API services such as REST, OpenAPI, Swagger, SOAP, gRPC and more...
https://the-guild.dev/graphql/mesh
MIT License
3.29k stars 344 forks source link

Combining transformations and response cache plugin causes mangled responses #6272

Closed bobjana closed 7 months ago

bobjana commented 1 year ago

Issue workflow progress

Progress of the issue based on the Contributor Workflow

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

Please make sure Mesh package versions under package.json matches yours.


Describe the bug The combinations of applying transformations and using Response cache plugin, causes mangled responses. Commenting out either transformations or caching gives the correct response. This used to work up to the following versions contained in (yarn.lock.txt)

To Reproduce Steps to reproduce the behavior: Unfortunately it's not possible to submit a reproducible sandbox as we're integrating with a 3rd party subgraph ContentStack which is not publicly accessible.

mesh-config.txt

Query:

query AllSizeGuides {
  cms{    
      all_size_guide(limit: 1, skip: 0, locale: "fr-nl") {
                total,
                items {
                    chunk_id,
                }
        }
    }
}

Expected response:

{
  "data": {
    "__typename": "Query",
    "cms": {
      "__typename": "Query",
      "all_size_guide": {
        "__typename": "CS_AllSizeGuide",
        "total": 121,
        "items": [
          {
            "__typename": "CS_SizeGuide",
            "chunk_id": [
              80007203
            ]
          }
        ]
      }
    }
  }
}

Mangled Response:

{
  "data": {
    "__gqtld0__": "Query",
    "__gqtld1__": {
      "total": 121,
      "items": [
        {
          "chunk_id": [
            80007203
          ]
        }
      ]
    }
  }
}

Expected behaviour

Environment:

Additional context

While configuring snapshot plugin, noticed additional file being snapshoted while performing the same query: mangled_snapshots.zip as opposed to the snapshots when a valid response is returned: correct_snapshots.zip

bitrvmpd commented 1 year ago

I'm facing this issue too, was able to reproduce by using the response-cache plugin and the encapsulate transform with a single source. If there are 2 or more sources the issue is no longer present:

ardatan commented 11 months ago

Sorry for the late response! It doesn't happen on the single source because we don't apply stitching and forward requests directly to the single source's executor, and when cache hits, response cache plugin stops execution with result without applying the transforms after. So this causes you get the raw result. This would be solved after this PR gets merged; https://github.com/n1ru4l/envelop/pull/2093

bobjana commented 8 months ago

@ardatan, I just upgraded all libraries to the latest releases and the bug still exists. My current dependencies are:

  "dependencies": {
    "@graphql-mesh/cache-redis": "^0.96.0",
    "@graphql-mesh/cli": "^0.88.5",
    "@graphql-mesh/graphql": "^0.96.0",
    "@graphql-mesh/plugin-prometheus": "^0.96.0",
    "@graphql-mesh/transform-encapsulate": "^0.96.0",
    "@graphql-mesh/transform-federation": "^0.96.0",
    "@graphql-mesh/transform-prefix": "^0.96.0",
    "@graphql-mesh/transform-rename": "^0.96.0",
    "graphql": "^16.8.1",
    "prom-client": "^15.0.0"
  }