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 342 forks source link

Rename & Encapsulate Transforms On GraphQL Handler Break Query #1600

Open ddcollins opened 3 years ago

ddcollins commented 3 years ago

Describe the bug I've attempted to use the encapsulate and rename transform on my GraphQL source, and each result in an error at query time.

sources:
  - name: Academy
    transforms:
      - filterSchema:
          - Query.!server
      - encapsulate:
          applyTo:
            query: true
            mutation: false
            subscription: false
    handler:
      graphql:
        endpoint: ${DIRECTUS_HOST}
        schemaHeaders:
          Authorization: Bearer ${DIRECTUS_API_TOKEN}
        operationHeaders:
          Authorization: Bearer ${DIRECTUS_API_TOKEN}
        batch: false
additionalTypeDefs:
  - ./src/additional-type-definitions.graphql
additionalResolvers:
  - ./src/additional-resolvers.js

transforms:
  # Global
  - resolversComposition:
      - resolver: 'Query.*'
        composer: ./src/middleware/api-token-guard.js
      - resolver: 'Mutation.*'
        composer: ./src/middleware/api-token-guard.js
  - namingConvention:
      # Causes issue with union types
      # typeNames: pascalCase
      enumValues: upperCase
      fieldNames: camelCase
{
    academy {
        items {
            course(limit:10) {
                id
                title
                description
            }
        }
    }
}
{
            "message": "Cannot read property 'columns' of undefined",
            "name": "GraphQLError",
            "originalError": {},
            "path": [
                "academy",
                "course"
            ],
            "source": {
                "locationOffset": {}
            },
            "stack": [
                "GraphQLError: Cannot read property 'columns' of undefined",
                "    at Object.relocatedError (/app/node_modules/@graphql-tools/utils/index.cjs.js:3894:12)",
                "    at mergeDataAndErrors (/app/node_modules/@graphql-tools/delegate/index.cjs.js:1397:34)",
                "    at /app/node_modules/@graphql-tools/delegate/index.cjs.js:1425:66",
                "    at Array.forEach (<anonymous>)",
                "    at mergeDataAndErrors (/app/node_modules/@graphql-tools/delegate/index.cjs.js:1423:27)",
                "    at checkResultAndHandleErrors (/app/node_modules/@graphql-tools/delegate/index.cjs.js:1386:38)",
                "    at CheckResultAndHandleErrors.transformResult (/app/node_modules/@graphql-tools/delegate/index.cjs.js:1382:16)",
                "    at /app/node_modules/@graphql-tools/delegate/index.cjs.js:1569:40",
                "    at Array.reduceRight (<anonymous>)",
                "    at Transformer.transformResult (/app/node_modules/@graphql-tools/delegate/index.cjs.js:1568:37)"
            ]
        }

To Reproduce Steps to reproduce the behavior:

Expected behavior Query executes successfully.

Environment:

Additional context

ddcollins commented 3 years ago

@ardatan Here's a repo I set up with instructions on how to replicate this! https://github.com/ddcollins/mesh-directus-replication.