No way to have optional data in GraphQL queries.
See original GitHub issueDescription
I’m not sure this is a bug or a feature-request. It seems that while a specific <page-query> can have nullable GraphQL fields, if you want to query a source that you’ve personally defined it does not allow nullable entries.
Steps to reproduce
Using the gridsome/gridsome-starter-blog
try and create a post without a cover image. The only way to do so is by rewriting the Page component (and Index etc) to not rely on the cover_image
.
Expected result
It should be possible to mark fields as optional or nullable, or just natively support it.
Actual result
Module build failed (from ./node_modules/gridsome/lib/plugins/vue-components/lib/loaders/page-query.js):
Error: Cannot query field "cover_image" on type "Post".
GraphQL request (124:5)
123: content
124: cover_image (width: 860, blur: 10)
^
125: meta_image (width: 860, blur: 10)
Environment
Libs:
- gridsome version: 0.6.2
- @gridsome/cli version: 0.1.1
Browser:
- [X] Chrome (desktop) version 74.0.3729.169
For Tooling issues:
- Node version: 12.0
- Platform: Mac
Issue Analytics
- State:
- Created 4 years ago
- Reactions:10
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Using nullability in GraphQL
By default, every field in GraphQL is nullable, and you can opt in to mark it non-null. In this article, we'll go over...
Read more >GraphQL optional Query Arguments - Stack Overflow
Arguments in GraphQL are nullable (i.e. optional) by default. So if your type definition looks like this: companies(limit: Int): [Company].
Read more >Querying with GraphQL optional arguments in Elm - Thoughtbot
We update the GraphQL schema to have a nullable notes field. The notes argument is optional. We can tell because it doesn't have...
Read more >Nulls in GraphQL: Cheatsheet - Hasura
A GraphQL query can have fields and inputs, with or without variables. Fields are always optional, whether nullable or not.
Read more >Queries and Mutations - GraphQL
Most discussions of GraphQL focus on data fetching, but any complete data platform needs a way to modify server-side data as well. In...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not sure if it’s fixed in v0.7? I am still experiencing the same issue.
Gridsome can only generate the schema based on the data you have. We are working on APIs for letting you defined the schema yourself to make sure the
cover_image
always exists. It will be available in v0.7 😃