Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createNamingConventionTransform can cause issues with common OpenAPI types #8214

Open
1 of 4 tasks
fauna5 opened this issue Dec 31, 2024 · 0 comments
Open
1 of 4 tasks

Comments

@fauna5
Copy link

fauna5 commented Dec 31, 2024

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.

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

Describe the bug

When using loadOpenAPISubgraph from @omnigraph/openapi the common types e.g. void_container.Void are subject to the same transformations as all the other types. This causes issues when loading two subgraphs, they need to have the exact same transforms otherwise mesh-compose throws an error

To Reproduce Steps to reproduce the behavior:

mesh.config

import {
  camelCase,
  createEncapsulateTransform,
  createNamingConventionTransform,
  defineConfig,
} from "@graphql-mesh/compose-cli";
import { loadOpenAPISubgraph } from "@omnigraph/openapi";

export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadOpenAPISubgraph("APIOne", {
        source: "schema1.json",
        endpoint: "http://localhost:8080",
      }),
      transforms: [
        // UNCOMMENT TO FIX THE ISSUE
        // createNamingConventionTransform({
        //   fieldNames: camelCase,
        // }),
      ],
    },
    {
      sourceHandler: loadOpenAPISubgraph("APITwo", {
        source: "schema2.json",
        endpoint: "http://localhost:8081",
      }),
      transforms: [
        createNamingConventionTransform({
          fieldNames: camelCase,
        }),
      ],
    },
  ],
});

schema1

{
  "paths": {
    "/example": {
      "get": {
        "summary": "Example GET endpoint",
        "responses": {
          "200": {
            "description": "Successful response with payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "204": {
            "description": "No content"
          }
        }
      }
    }
  }
}

schema2

{
  "paths": {
    "/different_endpoint": {
      "get": {
        "summary": "Example GET endpoint",
        "responses": {
          "200": {
            "description": "Successful response with payload",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "204": {
            "description": "No content"
          }
        }
      }
    }
  }
}

Expected behavior

A successful compose

> mesh-compose -o supergraph.graphql

[2024-12-31T17:37:36.982Z] INFO  Mesh Compose  Found default config file /Users/richardchamberlain/dev/graphql-mesh-conflict/mesh.config.ts 
[2024-12-31T17:37:37.106Z] INFO  Mesh Compose  Loaded config 
[2024-12-31T17:37:37.106Z] INFO  Mesh Compose  Composing 
[2024-12-31T17:37:37.181Z] INFO  Mesh Compose  Writing schema to supergraph.graphql 
[2024-12-31T17:37:37.184Z] INFO  Mesh Compose  Done! 

Actual behaviour

> mesh-compose -o supergraph.graphql

[2024-12-31T17:39:29.941Z] INFO  Mesh Compose  Found default config file /Users/richardchamberlain/dev/graphql-mesh-conflict/mesh.config.ts 
[2024-12-31T17:39:30.062Z] INFO  Mesh Compose  Loaded config 
[2024-12-31T17:39:30.062Z] INFO  Mesh Compose  Composing 
[2024-12-31T17:39:30.135Z] ERROR Mesh Compose  Failed to compose subgraphs 
[2024-12-31T17:39:30.135Z] ERROR Mesh Compose  The following supergraph API query:
{
  differentEndpoint {
    ... on Void_container {
      Void
    }
  }
}
cannot be satisfied by the subgraphs because:
- from subgraph "APITwo":
  - cannot find field "Void_container.Void".
  - cannot move to subgraph "APIOne", which has field "Void_container.Void", because type "Void_container" has no @key defined in subgraph "APIOne". 
[2024-12-31T17:39:30.135Z] ERROR Mesh Compose  The following supergraph API query:
{
  example {
    ... on Void_container {
      void
    }
  }
}
cannot be satisfied by the subgraphs because:
- from subgraph "APIOne":
  - cannot find field "Void_container.void".
  - cannot move to subgraph "APITwo", which has field "Void_container.void", because type "Void_container" has no @key defined in subgraph "APITwo". 

Environment:

  • OS: OSX
  • @graphql-mesh/compose-cli": "^1.3.4:
  • NodeJS: 22

Additional context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant