-
Notifications
You must be signed in to change notification settings - Fork 468
Querying non-existent single page by URI returns error instead of null #1639
Copy link
Copy link
Closed
Labels
impact: medMinor performance improvements, fix broad user base issuesMinor performance improvements, fix broad user base issuesobject type: postRelating to the Post Object TypesRelating to the Post Object Typesstale?May need to be revalidated due to prolonged inactivityMay need to be revalidated due to prolonged inactivitytype: bugIssue that causes incorrect or unexpected behaviorIssue that causes incorrect or unexpected behavior
Milestone
Description
Expected behavior
When querying a single page by URI and the provided URI does not exist, no error is thrown, and the returned data is null.
Actual behavior
The following query works fine when either a) the idType is set to URI and the id provided exists, or b) the idType is set to DATABASE_ID (whether or not the id exists).
query GET_PAGE_BY_ID($id: ID!, $idType: PageIdType = URI, $imageSize: MediaItemSizeEnum = LARGE) {
page(id: $id, idType: $idType) {
databaseId
date
slug
uri
title
author {
node {
slug
nickname
}
}
featuredImage {
node {
altText
sourceUrl(size: $imageSize)
}
}
}
}
However, if the idType is set to URI and the id does not exist, the following error is returned:
{
"errors": [
{
"debugMessage": "Cannot return null for non-nullable field \"Page.databaseId\".",
"message": "Internal server error",
"extensions": {
"category": "internal"
},
"locations": [
{
"line": 3,
"column": 5
}
],
"path": [
"page",
"databaseId"
],
...
}
],
"data": {
"page": null
},
"extensions": {
"debug": []
}
}
A similar query for a single post, passing SLUG for idType and a non-existent id does not throw an error, instead returning null for data.
Tested both via headless frontend and directly in GraphiQL IDE (same error both places).
Using WP GraphQL v1.0.3 (also tested w/ v102 and v1.0.4 – which is not available via WP plugin repository, btw)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
impact: medMinor performance improvements, fix broad user base issuesMinor performance improvements, fix broad user base issuesobject type: postRelating to the Post Object TypesRelating to the Post Object Typesstale?May need to be revalidated due to prolonged inactivityMay need to be revalidated due to prolonged inactivitytype: bugIssue that causes incorrect or unexpected behaviorIssue that causes incorrect or unexpected behavior
Type
Projects
Status
✅ Done