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

Hive client fails with TypeError: Cannot read properties of undefined (reading 'name') when using JSON scalar #4574

Open
sam-lewis opened this issue Apr 23, 2024 · 0 comments

Comments

@sam-lewis
Copy link

I get an error from Hive Usage collection with Yoga when a JSON scalar type is used within a GraphQL query / mutation.

With this query:

query MyAwesomeQuery {
  test(
    json: {hello: "world"}
  ) {
    id
  }
}

I see error:

Failed to collect operation (name: "MyAwesomeQuery") TypeError: Cannot read properties of undefined (reading 'name')
    at resolveTypeName (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/usage.js:421:46)
    at collectNode (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/usage.js:257:35)
    at Object.ObjectField (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/usage.js:391:17)
    at Object.enter (node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/utilities/TypeInfo.js:391:27)
    at visit (node_modules/.pnpm/graphql@16.8.1/node_modules/graphql/language/visitor.js:197:21)
    at collect (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/usage.js:324:23)
    at <anonymous> (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/utils.js:31:23)
    at Object.complete (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/internal/usage.js:153:54)
    at onResultProcess (node_modules/.pnpm/@graphql-hive+client@0.32.0_graphql@16.8.1/node_modules/@graphql-hive/client/cjs/yoga.js:98:24)
    at processResult (node_modules/.pnpm/graphql-yoga@5.3.0_graphql@16.8.1/node_modules/graphql-yoga/cjs/process-request.js:10:15)

The error doesn't occur when the JSON scalar is passed as a variable e.g.

query MyAwesomeQueryWithVariable($json: JSON) {
  test(
    json: $json
  ) {
    id
  }
}

Variables
=======
{
  "json": {"hello": "world"}
}

Versions

@graphql-hive/client: 0.32.0
graphql-yoga: 5.3.0

Possible Fix
I dont know the full implications of doing this but the error can be fixed by adding a check to the collectNode() function in usage.ts:

if (!inputType) {
  return
}

Thanks for the amazing project 🙏

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

1 participant