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
Querying Page by URI doest require correct URI field #3042
Comments
@andremendonca03 if you visit |
Per slack it 404s on the frontend. |
ah ok. Often times WordPress will attempt to find the best match and return the page still, or redirect to it. |
@andremendonca03 can you query for more fields? like Do you maybe have something under the When I try and reproduce, I get a |
@jasonbahl Unfortunately I am still getting the page even if I query for more fields. When visiting the URI /test/ it 404s on wordpress' front-end. Btw, when I used a wrong url with 2 slashes it somehow returned a post data (not page) alongside an error. |
Are you able to reproduce with no other plugins other than WPGraphQL? I was not able to reproduce. Curious if there are specific permalink rules at play or something from a plugin possibly at play here. |
@jasonbahl Yes, I just spinned up a brand new wordpress, created the about page and test child page. Installed WPGraphQL and run the queries. Querying by page /test/ it is still returning the page: And this wrong URI is still retrieving the post: |
This seems like maybe a $global post thing. 🤔 What happens if you query for page first then nodeByUri in the same request? |
Attempt to reproduce:
{
nodeByUri(uri: "/test/") {
__typename
id
uri
}
page(id: "/test/", idType: URI) {
__typename
id
uri
}
}
Now I am able to see the "/about/test" node returned for the "page", but not the "nodeByUri", which is indeed interesting. However, the node that is returned also returns a I think at minimum we've identified an inconsistency with If WordPress is able to accept a non-existing uri ( I would think the correct solution here would be to have the |
I think the action here is to identify why Without looking, my hunch is that the |
WP default behavior is to correctly return a 404, so
|
In a vanilla WordPress install, it redirected not returned a 404 though 🤔 |
It doesn't for me 🤔 Let me try again when I'm by my desk |
it did for me in a vanilla install with only WPGraphQL and whatever latest default theme. |
We should tackle this by handling it the same way as core WordPress. if WordPress redirects, WPGraphQL should return the node, and the node should have the accurate uri as a field that can be used to redirect to by the client. If WordPress 404s, WPGraphQL should return a null. |
Description
When querying for pages or posts by URI, it returns any match of the uri even if it's incomplete. It turns out to be a problem when parent/child relationships are in place.
i.e. I've got a test page which URI is /about/test/ but it can still be queried just with a fraction of the URI like bout/test/ or even just /test/
Steps to reproduce
Additional context
No response
WPGraphQL Version
1.21.0
WordPress Version
6.4.3
PHP Version
8.3.0
Additional environment details
No response
Please confirm that you have searched existing issues in the repo.
Please confirm that you have disabled ALL plugins except for WPGraphQL.
The text was updated successfully, but these errors were encountered: