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

Transform federation generates incorrect schema

Open georgeberar opened this issue 5 months ago • 0 comments

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

I'm trying to build the subgraph based on a gRPC source but the generated GraphQL schema seems to be invalid and contains 'unknown directives'.

To Reproduce Steps to reproduce the behavior:

I have a simple gRPC message defined as:

message Transaction {
  string id = 1;
  string accountId = 2;
  string amount = 3;
  string createdAt = 4;

}

other proto files (e.g. service) are omitted for brevity

My .meshrc.yml looks like this:

sources:
  - name: transaction-service
    handler:
      grpc:
        endpoint: ${BACKEND_SERVICE_HOST}
        useHTTPS: ${USE_HTTPS}
        source:
          file: ./proto/transaction_service.proto
          load:
            defaults: true
            includeDirs:
              - ./proto
    transforms:
      - federation:
          types:
            - name: Transaction
              config:
                key:
                  - fields: id

When running mesh build it generates:

schema @link(url: "https://specs.apollo.dev/federation/v2.0", import: []) {
  query: Query
  mutation: Mutation
}

// omitted for brevity

type Transaction @key(fields: "id") {
  id: String
  type: TransactionTypeGrpc
  accountId: String
  amount: String
  createdAt: String
}

but the @link and @key directives are marked as unknown. They are missing from the import as well. Pushing this schema to Hive results in an error due to unknown directive @link.

I found another issue similar to this here but I'm using the default 2.0 federation version.

Expected behavior

The generated schema is valid.

Environment:

  • OS: Mac & Linux
  •   "@graphql-mesh/cli": "0.88.5",
      "@graphql-mesh/grpc": "0.97.3",
      "@graphql-mesh/transform-federation": "^0.96.3"
    
  • NodeJS: v18.19.0

Additional context

georgeberar avatar Jan 24 '24 12:01 georgeberar