Skip to content

Rename & Encapsulate Transforms On GraphQL Handler Break Query #1600

Open
@ddcollins

Description

@ddcollins

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:

  • Encapsulate or rename a top level field in GraphQL handler.
 - name: Academy
   transforms:
     - filterSchema:
        - Query.!server
     - encapsulate:
         name: Academy
         applyTo:
           query: true
           mutation: false
           subscription: false
 - name: Academy
   transforms:
     - filterSchema:
         - Query.!server
     - rename:
         - from:
             type: Query
             field: items
           to:
             type: Query
             field: academy
  • Fire off a query.

Expected behavior
Query executes successfully.

Environment:

  • OS: MacOS 10.15.7
   "@graphql-mesh/cli": "^0.15.*",
   "@graphql-mesh/graphql": "^0.13.13",
   "@graphql-mesh/json-schema": "^0.10.2",
   "@graphql-mesh/transform-encapsulate": "^0.1.23",
   "@graphql-mesh/transform-filter-schema": "^0.8.27",
   "@graphql-mesh/transform-naming-convention": "^0.6.26",
   "@graphql-mesh/transform-rename": "^0.7.21",
   "@graphql-mesh/transform-resolvers-composition": "^0.7.26"
  • NodeJS: 14.15

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions