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

Naming Convention Transform Breaks Union Type Query #1592

Open
ddcollins opened this issue Feb 11, 2021 · 3 comments
Open

Naming Convention Transform Breaks Union Type Query #1592

ddcollins opened this issue Feb 11, 2021 · 3 comments

Comments

@ddcollins
Copy link

ddcollins commented Feb 11, 2021

Adding the naming convention transform:

transforms:
  # Global
  - namingConvention:
      typeNames: pascalCase
      enumValues: upperCase
      fieldNames: camelCase

Results in the following error:

"originalError": {
    "name": "TypeError",
    "message": "Cannot read property 'getFields' of undefined",
    "stack": [
        "TypeError: Cannot read property 'getFields' of undefined",
        "    at visitObjectValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4078:27)",
        "    at visitFieldValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4148:16)",
        "    at /app/node_modules/@graphql-tools/utils/index.cjs.js:4102:26",
        "    at Array.forEach (<anonymous>)",
        "    at visitObjectValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4089:31)",
        "    at visitFieldValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4152:16)",
        "    at /app/node_modules/@graphql-tools/utils/index.cjs.js:4135:35",
        "    at Array.map (<anonymous>)",
        "    at visitListValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4135:17)",
        "    at visitFieldValue (/app/node_modules/@graphql-tools/utils/index.cjs.js:4143:16)"
    ]
},

When trying to run the following query:

{
    items {
        course(limit:10) {
            id
            title
            description
            lessons {
                title
                subTitle
                canPreview
                description
                steps {
                    stepTitle
                    canPreview
                    item {
                        ... on LessonSlide {
                            content
                            status
                            imageUrl
                        }
                        ... on LessonVideo {
                            videoUrl
                        }
                    }
                }
            }
        }
    }

}

This query works fine when the naming convention transform is removed.
The query also works fine if I remove:

item {
    ... on LessonSlide {
        content
        status
        imageUrl
    }
    ... on LessonVideo {
        videoUrl
    }
}

The query is through my graphql handler.

Dependencies:

"@graphql-mesh/cli": "^0.15.*",
    "@graphql-mesh/graphql": "^0.13.*",
    "@graphql-mesh/json-schema": "^0.10.*",
    "@graphql-mesh/transform-encapsulate": "^0.1.20",
    "@graphql-mesh/transform-naming-convention": "^0.6.23",
    "@graphql-mesh/transform-resolvers-composition": "^0.7.*",
@ddcollins
Copy link
Author

It's specifically this transform:

typeNames: pascalCase

@ardatan
Copy link
Owner

ardatan commented Feb 11, 2021

Could you share more details and a reproduction if possible?

@ddcollins
Copy link
Author

ddcollins commented Feb 11, 2021

Could you share more details and a reproduction if possible?

This is my mesh config

sources:
  - name: DirectusAcademy
    handler:
      graphql:
        endpoint: ${DIRECTUS_HOST}
        schemaHeaders:
          Authorization: Bearer ${DIRECTUS_API_TOKEN}
        operationHeaders:
          Authorization: Bearer ${DIRECTUS_API_TOKEN}
        batch: false

transforms:
  # Global
  - resolversComposition:
      - resolver: 'Query.*'
        composer: ./src/middleware/api-token-guard.js
      - resolver: 'Mutation.*'
        composer: ./src/middleware/api-token-guard.js
  - namingConvention:
      typeNames: pascalCase
      enumValues: upperCase
      fieldNames: camelCase

serve:
  port: 5000

We are hooking into Directus which has "many to any" relational support

e.g.

Lesson has "steps", and that step could be a "Lesson Slide", "Lesson Video", etc object.

Previous to the transforms the query was:

{
    items {
        course(limit:10) {
            id
            title
            description
            lessons {
                title
                sub_title
                can_preview
                description
                steps {
                    step_title
                    can_preview
                    item {
                        ... on lesson_slide {
                            content
                            status
                            image_url
                        }
                        ... on lesson_video {
                            video_url
                        }
                    }
                }
            }
        }
    }
    
}

My theory is that it's still looking for the snake case type name for lesson_slide and lesson_video and not the transformed pascal case

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

@theguild-bot theguild-bot mentioned this issue Aug 11, 2022
@theguild-bot theguild-bot mentioned this issue Sep 28, 2023
This was referenced Apr 30, 2024
This was referenced May 7, 2024
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

2 participants