question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Schema-relations. GraphQLDocumentError - Cannot query field

See original GitHub issue

Hi. I was trying to take a look how RedwoodJS scaffold UI for items with relations.

I was referencing to Documentation https://redwoodjs.com/docs/schema-relations

Following that guide I couldn’t achieve expected result.

  1. I have imitated project with yarn create redwood-app ./redwoodblog
  2. Copied and Pasted from section ‘You can get this working by creating an explicit relationship—defining the table structure yourself:’ code.
model Product { ... }
model Tag { ... }
model ProductsOnTag { ... }

https://github.com/artemhp/redwood-relations/blob/master/api/db/schema.prisma#L13 3. Migrate DB: yarn rw prisma migrate dev 4. Scaffold product yarn rw g scaffold product All files has been successfully created but in output there some errors:

Error: Could not generate GraphQL type definitions (web)
AggregateError: GraphQL Document Validation failed with 9 errors;
  Error 0: GraphQLDocumentError: Unknown type "Int".
    at /Users/adeikun/Projects/temp/temp2/redwoodblog/web/src/components/Product/EditProductCell/EditProductCell.js:1:28

Error 1: GraphQLDocumentError: Cannot query field "product" on type "Query".
    at /Users/adeikun/Projects/temp/temp2/redwoodblog/web/src/components/Product/EditProductCell/EditProductCell.js:2:3

Error 2: GraphQLDocumentError: Unknown type "Int".
    at /Users/adeikun/Projects/temp/temp2/redwoodblog/web/src/components/Product/EditProductCell/EditProductCell.js:1:37

Error 3: GraphQLDocumentError: Unknown type "UpdateProductInput".
    at /Users/adeikun/Projects/temp/temp2/redwoodblog/web/src/components/Product/EditProductCell/EditProductCell.js:1:51

Error 4: GraphQLDocumentError: Unknown type "CreateProductInput".
    at /Users/adeikun/Projects/temp/temp2/redwoodblog/web/src/components/Product/NewProduct/NewProduct.js:1:40
  1. Run project yarn redwood dev
  2. Navigate to http://localhost:8910/products In console output have errors:
api | Starting API Server...
api | Loading server config from /Users/adeikun/Projects/temp/temp2/redwoodblog/api/server.config.js 
api | 
api | Importing Server Functions... 
api | 12:32:16 💀 
api |  ⚠️ GraphQL server crashed 
api |  
api | Error: Unknown type "ProductsOnTag". Did you mean "Product"?
api |     at assertValidSDL (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/graphql/validation/validate.js:135:11)
api |     at Object.buildASTSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/graphql/utilities/buildASTSchema.js:44:34)
api |     at makeExecutableSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/node_modules/@graphql-tools/schema/index.js:495:26)
api |     at makeMergedSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/dist/makeMergedSchema/makeMergedSchema.js:176:51)
api |     at createGraphQLHandler (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/dist/functions/graphql.js:128:53)
api |     at Object.<anonymous> (/Users/adeikun/Projects/temp/temp2/redwoodblog/api/src/functions/graphql.js:10:24)
api |     at Module._compile (node:internal/modules/cjs/loader:1101:14)
api |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
api |     at Module.load (node:internal/modules/cjs/loader:981:32)
api |     at Function.Module._load (node:internal/modules/cjs/loader:822:12) 
api | {
api |   "err": {
api |     "type": "Error",
api |     "message": "Unknown type \"ProductsOnTag\". Did you mean \"Product\"?",
api |     "stack": "Error: Unknown type \"ProductsOnTag\". Did you mean \"Product\"?\n    at assertValidSDL (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/graphql/validation/validate.js:135:11)\n    at Object.buildASTSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/graphql/utilities/buildASTSchema.js:44:34)\n    at makeExecutableSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/node_modules/@graphql-tools/schema/index.js:495:26)\n    at makeMergedSchema (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/dist/makeMergedSchema/makeMergedSchema.js:176:51)\n    at createGraphQLHandler (/Users/adeikun/Projects/temp/temp2/redwoodblog/node_modules/@redwoodjs/graphql-server/dist/functions/graphql.js:128:53)\n    at Object.<anonymous> (/Users/adeikun/Projects/temp/temp2/redwoodblog/api/src/functions/graphql.js:10:24)\n    at Module._compile (node:internal/modules/cjs/loader:1101:14)\n    at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)\n    at Module.load (node:internal/modules/cjs/loader:981:32)\n    at Function.Module._load (node:internal/modules/cjs/loader:822:12)"
api |   }
api | }
web | <e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8910/graphql to http://[::1]:8911/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
web | <e> [webpack-dev-server] [HPM] Error occurred while proxying request localhost:8910/graphql to http://[::1]:8911/ [ECONNREFUSED] (https://nodejs.org/api/errors.html#errors_common_system_errors)
  1. On UI page I see an error “The RedwoodJS API server is not available or is currently reloading. Please refresh.”

Repository with use case: https://github.com/artemhp/redwood-relations

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:10 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
jtoarcommented, Apr 18, 2022

@artemhp There’s a PR that aims to fix this doc that I’ve been super behind on reviewing: https://github.com/redwoodjs/redwood/pull/4849.

The TL;DR is you have to generate SDLs for the other models in the relation. Here’s a PR on your repo that shows what I mean: https://github.com/artemhp/redwood-relations/pull/1

1reaction
jtoarcommented, May 19, 2022

I’m going to close this one for now; if you’d like to open a feature request we’re happy to talk about it.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Why I got error: Cannot query field xx on type "Query"?
The fault with my query was that I didn't download the new schema. You can download the schema by using: apollo schema:download ...
Read more >
Cannot query field "..." on type "Query".GraphQL: Validation
I have a v simple set-up: a new redwood typescript project with a single sdl file and corresponding service file…
Read more >
GraphQL error: Cannot query field "name" on type "Query
I'm doing a simple hello world application that uses ApolloStack and react-meteor but it seems not working fine.
Read more >
How I Fixed: Gatsby GraphQL Cannot query field "query" on ...
I set up a Gatsby site, along with Postgres and Postgraphile to expose GraphQL over my database. This is frankly amazing, and achieves...
Read more >
Troubleshoot Common Errors - StepZen
Cannot Query Field on Type ... Adding the field to the capsules type resolves the problem. In general, an error indicating that you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found