GraphQL. DRAFT references cause errors on nullable fields
See original GitHub issueExpected Behavior
DRAFT
as Reference
should be ignored by graphQL on nullable fields.
Actual Behavior
Adding a DRAFT
as Reference
causes an error and prevents loading data.
Using: useQuery
via @apollo/client
or graphiql via https://graphql.contentful.com/content/v1/spaces/{SPACE}
"errors": [
{
"message": "Query execution error. Link to entry '{ENTRY_ID}' on field '{FIELD_NAME}' within type '{CONTENT_TYPE}' cannot be resolved",
"extensions": {
"contentful": {
"code": "UNRESOLVABLE_LINK",
"requestId": "{REQUEST_ID}",
"details": {
"type": "{CONTENT_TYPE}",
"field": "{FIELD_NAME}",
"linkType": "Entry",
"linkId": "{ENTRY_ID}"
}
}
},
"locations": [
{
"line": 156,
"column": 9
}
],
"path": [
"{COLLECTION_NAME}",
"items",
0,
"{FIELD_NAME}"
]
}
]
Partial data exists on graphiql via https://graphql.contentful.com/content/v1/spaces/{SPACE}
but it won’t be returned by @apollo/client
.
![contentful_error_graphql](https://user-images.githubusercontent.com/1148334/87536272-2453f780-c699-11ea-8f3a-3e90cf6e780a.png)
Possible Solution
Removing the DRAFT
works but is (probably) not the intended behavior
Steps to Reproduce
- Add a
DRAFT
asReference
- Query the contentType via
https://graphql.contentful.com/content/v1/spaces/{SPACE}
- See error
Context
When changing a published entry to DRAFT
the page cannot be loaded. This can cause unexpected behavior and should be considered a showstopper.
Partial data exists on graphiql via https://graphql.contentful.com/content/v1/spaces/{SPACE}
but it won’t be returned by @apollo/client
.
If this is considered an @apollo/client
issue please mention it in a comment so I can create an issue and link it.
Maybe @apollo/client
does not return data when an error is present. The error is unnecessary and IMHO a bug.
Environment
- Language Version: v12.15.0
- Package Manager Version: 6.13.4
- Operating System: 19.5.0 Darwin Kernel Version 19.5.0: Tue May 26 20:41:44 PDT 2020; root:xnu-6153.121.2~2/RELEASE_X86_64 x86_64
- Package Version: n.a.
- Which API are you using?: GraphQL
Issue Analytics
- State:
- Created 3 years ago
- Reactions:6
- Comments:13
Hey, this issue is causing us some troubles, using GraphQL Api. I know we can filter or ignore the errors, but what about the
null
entries? For example when we have an entry with linked entries, and some of then are still in draft mode, we get something like this:Which is very annoying and error-prone when we use indexing of the items to track order, for example. And as far as I understood, the option
removeUnresolved
is not available in the GraphQL Api. Any other way of fixing this?I am having the same issue - it’s strange - why the graphql api returns NULL fields in draft items instead of just not returning them? Since we have preview tokens for that purposes it would not make sense to always hide draft items? @pixelass
As @hugomn mentioned a lot of my queries are also returning this data structure:
So I am having to do a lot of
data.filter(x=>x)
as a workaround for this issue.@hugomn did you find any solution for that?
Thanks.