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

Encapsulated transformation not applied to GraphQL source #4931

Closed
1 of 4 tasks
lassebn opened this issue Dec 12, 2022 · 1 comment
Closed
1 of 4 tasks

Encapsulated transformation not applied to GraphQL source #4931

lassebn opened this issue Dec 12, 2022 · 1 comment

Comments

@lassebn
Copy link

lassebn commented Dec 12, 2022

Issue workflow progress

Progress of the issue based on the Contributor Workflow


Describe the bug
I'm trying to proxy two GraphQL services, and I would like to "namespace" one of them, by encapsulating all of that graph within backoffice { ... }. My configuration is a follows

sources:
  - name: frontoffice
    handler:
      graphql:
        endpoint: https://url-1/graphql
        operationHeaders:
          Authorization: "{context.headers.authorization}"
  - name: backoffice
    handler:
      graphql:
        endpoint: https://url-2/graphql
        operationHeaders:
          Authorization: "{context.headers.authorization}"
    transforms:
      - encapsulate:
          name: backoffice
          applyTo:
            query: true
            mutation: true
            subscription: true

When I run DEBUG=1 mesh dev I get no errors, and everything runs fine with the GraphQL playground opening up in my browser. The backoffice source is not encapsulated as expected though

Running DEBUG=1 yarn run mesh build --throwOnInvalidConfig=true gives

💡 🕸️  Mesh Cleaning existing artifacts
💡 🕸️  Mesh Reading the configuration
💡 🕸️  Mesh Generating the unified schema
🐛 🕸️  Mesh - GetMesh Getting subschemas from source handlers
🐛 🕸️  Mesh - frontoffice Generating the schema
🐛 🕸️  Mesh - backoffice Generating the schema
🐛 🕸️  Mesh - backoffice The schema has been generated successfully
🐛 🕸️  Mesh - backoffice Analyzing transforms
🐛 🕸️  Mesh - frontoffice The schema has been generated successfully
🐛 🕸️  Mesh - frontoffice Analyzing transforms
🐛 🕸️  Mesh - GetMesh Schemas have been generated by the source handlers
🐛 🕸️  Mesh - GetMesh Merging schemas using the defined merging strategy.
🐛 🕸️  Mesh - stitchingMerger Stitching directives are being generated
🐛 🕸️  Mesh - stitchingMerger Checking if any of sources has federation metadata
🐛 🕸️  Mesh - stitchingMerger Stitching the source schemas
🐛 🕸️  Mesh - stitchingMerger sourceMap is being generated and attached to the unified schema
Transformed schema is not set yet. Returning a dummy one.
💡 🕸️  Mesh Generating artifacts
💡 🕸️  Mesh Generating index file in TypeScript
💡 🕸️  Mesh Writing index.ts for ESM to the disk.
💡 🕸️  Mesh Writing index.ts for CJS to the disk.
💡 🕸️  Mesh Cleanup
💡 🕸️  Mesh Done! => /Users/lassenorregaard/Source/mesh-gateway-poc/.mesh
✨  Done in 2.36s.

and running DEBUG=1 yarn run mesh validate gives

💡 🕸️  Mesh Reading the configuration
💡 🕸️  Mesh Generating the unified schema
🐛 🕸️  Mesh - GetMesh Getting subschemas from source handlers
🐛 🕸️  Mesh - frontoffice Generating the schema
🐛 🕸️  Mesh - backoffice Generating the schema
💥 🕸️  Mesh - backoffice Failed to generate the schema Error: Failed to fetch introspection from https://url-2/graphql: ValidationError: Validation failed for "introspectionSchema" under ".mesh/sources/backoffice": undefined
    at doValidation (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:155:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.set (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:182:21)
    at async Object.getWithSet (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:168:25)
    at GraphQLHandler.getMeshSource (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/graphql/cjs/index.js:302:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:132:28
💥 🕸️  Mesh - frontoffice Failed to generate the schema Error: Failed to fetch introspection from https://url-1/graphql: ValidationError: Validation failed for "introspectionSchema" under ".mesh/sources/frontoffice":
    at doValidation (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:155:27)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.set (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:182:21)
    at async Object.getWithSet (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/store/cjs/index.js:168:25)
    at GraphQLHandler.getMeshSource (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/graphql/cjs/index.js:302:23)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:132:28
💥 🕸️  Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh.
    at getMesh (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:166:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Object.handler (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/cli/cjs/index.js:233:26)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

To Reproduce
Steps to reproduce the behavior:

I tried to create a reproduction here but that just works. I can see the publicly available GraphQL API I've chosen for the reproduction supports federation.

The actual APIs I'm trying to proxy do not support federation.

Expected behavior
The backoffice source would be nested under backoffice { ... } in the graph.

Environment:

  • OS: MacOS 13.0.1
  • @graphql-mesh/cli: 0.82.3
  • @graphql-mesh/graphql: 0.33.3
  • @graphql-mesh/transform-encapsulate: 0.4.3
  • NodeJS: v16.15.1

Additional context

If I add the SDL from each of the services as a file using the source configuration of the graphql sources, like this

sources:
  - name: frontoffice
    handler:
      graphql:
        endpoint: https://url-1/graphql
        source: schema.graphql
        operationHeaders:
          Authorization: "{context.headers.authorization}"
  - name: backoffice
    handler:
      graphql:
        endpoint: https://url-2/graphql
        source: schema-backoffice.graphql
        operationHeaders:
          Authorization: "{context.headers.authorization}"
    transforms:
      - encapsulate:
          name: backoffice
          applyTo:
            query: true
            mutation: true
            subscription: true

then mesh build gives

💡 🕸️  Mesh Cleaning existing artifacts
💡 🕸️  Mesh Reading the configuration
💡 🕸️  Mesh Generating the unified schema
🐛 🕸️  Mesh - GetMesh Getting subschemas from source handlers
🐛 🕸️  Mesh - frontoffice Generating the schema
🐛 🕸️  Mesh - frontoffice Reading schema.graphql from the file system
🐛 🕸️  Mesh - backoffice Generating the schema
🐛 🕸️  Mesh - backoffice Reading schema-backoffice.graphql from the file system
🐛 🕸️  Mesh - backoffice The schema has been generated successfully
🐛 🕸️  Mesh - backoffice Analyzing transforms
💥 🕸️  Mesh - frontoffice Failed to generate the schema Error: Failed to fetch introspection from https://url-1/graphql: Error: Unknown type "Long". Did you mean "Link"?

Unknown type "Long". Did you mean "Link"?

Unknown type "Long". Did you mean "Link"?
    at assertValidSDL (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/graphql/validation/validate.js:135:11)
    at buildASTSchema (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/graphql/utilities/buildASTSchema.js:44:34)
    at buildSchema (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/graphql/utilities/buildASTSchema.js:109:10)
    at GraphQLHandler.getNonExecutableSchemaForHTTPSource (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/graphql/cjs/index.js:87:50)
    at GraphQLHandler.getMeshSource (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/graphql/cjs/index.js:302:23)
    at async /Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:132:28
💥 🕸️  Mesh Error: Schemas couldn't be generated successfully. Check for the logs by running Mesh.
    at getMesh (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/runtime/cjs/get-mesh.js:166:15)
    at async Object.handler (/Users/lassenorregaard/Source/mesh-gateway-poc/node_modules/@graphql-mesh/cli/cjs/index.js:304:53)
error Command failed with exit code 1.

We do have Long in our SDL which is not defined as a scalar. Is it possible to run the gateway in a less strict mode? I mean the GraphQL playground is running fine, and all of our clients (using Apollo) are not blocked by this 🤔

@ardatan
Copy link
Owner

ardatan commented Apr 3, 2023

I'm not able to run the sandbox you sent. Could you update it if the issue persists?
I'm closing the issue for now. We can reopen it if the issue persists and you update the sandbox. Thanks!

We do have Long in our SDL which is not defined as a scalar. Is it possible to run the gateway in a less strict mode? I mean the GraphQL playground is running fine, and all of our clients (using Apollo) are not blocked by this
I don't think we can do that because this will cause an inconsistent behavior.

@ardatan ardatan closed this as completed Apr 3, 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