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

Cryptic runtime error when running hive-gateway supergraph #8267

Closed
4 tasks
ejkg opened this issue Jan 14, 2025 · 4 comments · Fixed by graphql-hive/gateway#462
Closed
4 tasks

Cryptic runtime error when running hive-gateway supergraph #8267

ejkg opened this issue Jan 14, 2025 · 4 comments · Fixed by graphql-hive/gateway#462
Assignees

Comments

@ejkg
Copy link

ejkg commented Jan 14, 2025

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 having trouble replicating this bug in a smaller context. I've got a very cryptic error from sucrase being thrown when I run hive-gateway supergraph. This command produces a runtime error which doesn't seem to be caught by typescript - yet the errors suggest this is a typescript issue.

[2025-01-13T21:54:27.638Z] ERROR  SyntaxError [Error]: Unexpected token (10891:37)
    at unexpected (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/traverser/util.js:99:15)
    at tsParseNonArrayType (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:542:20)
    at tsParseArrayTypeOrHigher (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:546:3)
    at tsParseTypeOperatorOrHigher (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:587:5)
    at tsParseIntersectionTypeOrHigher (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:594:3)
    at tsParseUnionTypeOrHigher (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:604:3)
    at tsParseNonConditionalType (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:793:3)
    at tsParseType (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:756:3)
    at tsParseTypeArguments (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:1160:5)
    at tsParseTypeReference (/Users/ekjg/project/node_modules/.pnpm/[email protected]/node_modules/sucrase/dist/parser/plugins/typescript.js:162:5) {
  pos: 593782,
  loc: { line: 10891, column: 37 }
} 

I can "fix" the issue by omitting a particular resolver file from the gateway config. However something strange. If I comment all of the code from the file it still doesn't resolve the issue, only if I remove the reference from my additionalResolvers in gateway.config does it work

// customer-resolvers.ts
export const customResolvers: Resolvers<GraphQLContext> = {
    // ...Resolvers
}
// gateway.config.ts

import { customResolvers } from "./src/custom-resolvers.ts";

export const gatewayConfig = defineConfig({
  supergraph: "./src/supergraph/schema.graphql",
  additionalResolvers: [ 
        customResolvers,
        // ... other custom resolvers
    ],
  plugins: (gatewayContext) => {
        // ... plugins
    }
});

When I comment out custom resolvers like this:

// gateway.config.ts

import { customResolvers } from "./src/custom-resolvers.ts";

export const gatewayConfig = defineConfig({
  supergraph: "./src/supergraph/schema.graphql",
  additionalResolvers: [ 
        // customResolvers,
        // ... other custom resolvers
    ],
  plugins: (gatewayContext) => {
        // ... plugins
    }
});

The gateway builds and executes the supergraph as expected.

Just to summarize. I believe the issue has to do with custom resolvers in the hive gateway because that appears to be the trigger for causing the cryptic error.

To Reproduce Steps to reproduce the behavior:

Still working on isolating the actual issue.

Expected behavior

Mesh composes the supergraph properly, but the gateway is unable to run our custom resolvers.

Environment:

  • OS: macos 15.2
  • "@graphql-hive/gateway": "^1.7.8":
  • NodeJS: v22.9.0

Additional context

Other relevant packages and their versions:

// dependencies
    "@graphql-hive/core": "^0.8.3",
    "@graphql-hive/envelop": "^0.33.11",
    "@graphql-hive/gateway": "^1.7.8",
    "@graphql-hive/gateway-runtime": "^1.4.7",
    "@graphql-tools/utils": "^10.6.2",

// dev dependencies
    "@graphql-codegen/add": "^5.0.3",
    "@graphql-codegen/cli": "^5.0.3",
    "@graphql-codegen/typescript": "^4.1.2",
    "@graphql-codegen/typescript-resolvers": "^4.4.1",
    "@graphql-mesh/compose-cli": "^1.3.5",
    "@graphql-mesh/types": "^0.103.11",
@ardatan
Copy link
Owner

ardatan commented Jan 14, 2025

It looks like a TypeScript parse error. @enisdenjo Do you think we can improve this error message to show which file is the issue?

@enisdenjo enisdenjo self-assigned this Jan 14, 2025
@enisdenjo
Copy link
Collaborator

enisdenjo commented Jan 15, 2025

@ejkg I tried replicating the issue following your description but couldn't get it to fail. It could be something with the Resolvers and GraphQLContext from customer-resolvers.ts.

Can you please share also the imports you do in customer-resolvers.ts?

BTW, for future reference, the Hive Gateway has been moved to: https://github.com/graphql-hive/gateway.

@enisdenjo
Copy link
Collaborator

graphql-hive/gateway#462 now exposes file paths of syntax errors - can you please try the alpha release to find the error?

@ejkg
Copy link
Author

ejkg commented Jan 15, 2025

Hey Dennis, thanks for the update using the new package version @graphql-hive/[email protected] I was able to get a better error that helped me locate the issue in no time.

basically I had to make this change in my composed supergraph.

// supergraph/resolver.types.ts

- SizeMetadata: ResolverTypeWrapper<@mesh@EnrichedProductAttributes>;
+ SizeMetadata: ResolverTypeWrapper<@mesh#EnrichedProductAttributes>;

This was caused by a typo in a codegen mapper that would have been really hard trace without the improved error reporting.

import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  schema: "./src/supergraph/schema.graphql",
  generates: {
    "./src/supergraph/resolvers.types.ts": {
      config: {
        mappers: {
-          SizeMetadata: "@mesh@EnrichedProductAttributes",
+          SizeMetadata: "@mesh#EnrichedProductAttributes",
        },
      },
    },
  },
};
export default config;

Much appreciated.

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

Successfully merging a pull request may close this issue.

3 participants