Skip to content

nodeByUri return unexpected response on REST API uris (e.g: uri: /wp-json/...) #3513

@yaronuliel

Description

@yaronuliel

Description

When calling the nodeByUri method and passing a uri that serves as WP Rest API endpoint - the GraphQL response is a JSON provided by the REST API, and not the expected GraphQL response structure

For example:

An existing REST API Endpoint:

# Request:
{
  nodeByUri(uri:"/wp-json/wp/v2/users") {
     id,
     __typename
  }
}
# Actual Response
{
  "code": "rest_missing_callback_param",
  "message": "Missing parameter(s): username, email, password",
  "data": {
    "status": 400,
    "params": [
      "username",
      "email",
      "password"
    ]
  }
}
# Expected Result
{
  "data": {
    "nodeByUri": null
  }
}

A missing API Endpoint

# Request:
{
  nodeByUri(uri:"/wp-json/something-something") {
     id,
     __typename
  }
}
# Actual Response
{
  "code": "rest_no_route",
  "message": "No route was found matching the URL and request method.",
  "data": {
    "status": 404
  }
}
# Expected Result
{
  "data": {
    "nodeByUri": null
  }
}

Expected Behaviour

IMO, since REST API endpoints are not nodes by any means, I think that all requests with relevant uris should act as if an unknown uri was passed to the function, regardless of the validity of the endpoint
i.e., returning:

{
  "data": {
    "nodeByUri": null
  }
}

Steps to reproduce

Open GraphQL IDE

Write this query:

{
  nodeByUri(uri:"/wp-json/wp/v2/users") {
     id,
     __typename
  }
}

Additional context

It's important to note the the /wp-json is the default prefix, and it can be modified using the rest_url_prefix filter,
so when testing for the prefix - rest_get_url_prefix() should be used.

WPGraphQL Version

2.7.0

WordPress Version

6.8.1

PHP Version

8.3

Additional environment details

No response

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have disabled ALL plugins except for WPGraphQL.

  • Yes
  • My issue is with compatibility with a specific WordPress plugin, and I have listed all my installed plugins (and version info) above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    🆕 New

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions