Skip to content
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

asPreview started to return null when ID Type is URI. Works for ID Type DABASE_ID #3225

Open
2 of 3 tasks
JorgeSivil opened this issue Nov 7, 2024 · 4 comments
Open
2 of 3 tasks
Labels
needs: author response Additional Pending information from the author has been requested from the author type: bug Issue that causes incorrect or unexpected behavior

Comments

@JorgeSivil
Copy link

JorgeSivil commented Nov 7, 2024

Description

I implemented this Preview feature in the site I'm working on some months ago, on 8/8/2024. It was working.
I don't know what happened but now it doesn't work anymore.
I found the same issue in another different site that I was tasked on implementing preview (I copied some things from the original work since it was working, and on this site I found out this issue and this workaround). Now the same is happening

Steps to reproduce

Create a draft.
Run the following query

query ($uri: ID!, $isPreview: Boolean = false) {
  contentNode(id: $uri, idType: DATABASE_ID, asPreview: $isPreview) {
    isPreview
  }
}

Change id type for URI and $uri param accordingly.

Screencast.from.07-11-24.19.03.08.webm

Additional context

No response

WPGraphQL Version

Version 1.28.0

WordPress Version

6.6.1

PHP Version

8.2.24 (Supports 64bit values)

Additional environment details

Server architecture Linux 6.1.85+ x86_64
Web server nginx
PHP version 8.2.24 (Supports 64bit values)
PHP SAPI fpm-fcgi
PHP max input variables 10000
PHP time limit 43300
PHP memory limit 512M
Max input time -1
Upload max filesize 50M
PHP post max size 100M
cURL version 7.81.0 OpenSSL/3.0.2
Is SUHOSIN installed? No
Is the Imagick library available? Yes
Are pretty permalinks supported? Yes
.htaccess rules Your .htaccess file contains only core WordPress features.
Current time 2024-11-07T22:11:50+00:00
Current UTC time Thursday, 07-Nov-24 22:11:50 UTC
Current Server time 2024-11-07T22:11:39+00:00

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.
@JorgeSivil
Copy link
Author

Secondary issue:

Error is returned when requesting "uri" from a Draft

image

@justlevine
Copy link
Collaborator

Hey @JorgeSivil

That video you share isn't loading for me (tried laptop and desktop) just 20 second of black. Do you mind resharing?

Regarding your second issue, an Internal Server Error points to an error in PHP. Not sure why this would happen on a nodeByUri query with all plugins disabled, but if you turn on both GraphQL Debugging and WP_DEBUG_LOG and rerun the query, you should get a trace in either the GraphQL response or wp-content/debug.log with the trace to the fatal error.

Once you've shared that, we should be able to see the culprit and provide you with next steps.

@justlevine justlevine added type: bug Issue that causes incorrect or unexpected behavior needs: author response Additional Pending information from the author has been requested from the author labels Nov 8, 2024
@JorgeSivil
Copy link
Author

This is the result for the URI ID type

{
  "data": {
    "contentNode": null
  },
  "extensions": {
    "debug": [],
    "tracing": {
      "version": 1,
      "startTime": 1731381867.881628,
      "endTime": 1731381868.018566,
      "duration": 136937,
      "execution": {
        "resolvers": [
          {
            "path": [
              "contentNode"
            ],
            "parentType": "RootQuery",
            "fieldName": "contentNode",
            "returnType": "ContentNode",
            "startOffset": 133283,
            "duration": 3443
          }
        ]
      }
    },
    "queryLog": {
      "queryCount": 1,
      "totalTime": 0.00041103363037109375,
      "queries": [
        {
          "sql": "SELECT   wp_posts.ID\n\t\t\t\t\t FROM wp_posts \n\t\t\t\t\t WHERE 1=1  AND wp_posts.post_name = 'new-neighborhood-test' AND wp_posts.post_type = 'neighborhoods'\n\t\t\t\t\t \n\t\t\t\t\t ORDER BY wp_posts.post_date DESC\n\t\t\t\t\t  /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/NodeResolver.php:191] */",
          "time": 0.00041103363037109375,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Data\\NodeResolver->resolve_uri, WP_Query->__construct, WP_Query->query, WP_Query->get_posts"
        }
      ]
    },
    "queryAnalyzer": {
      "keys": "8f7e49bc620ffe4b49cc8a88ae799071ba442cb45d688f2025e8fddc1f47dd71 graphql:Query operation:neighborhoodQuery",
      "keysLength": 106,
      "keysCount": 3,
      "skippedKeys": "",
      "skippedKeysSize": 0,
      "skippedKeysCount": 0,
      "skippedTypes": []
    }
  }
}

This is for the other, DATABASE_ID

{
  "data": {
    "contentNode": {
      "isPreview": false
    }
  },
  "extensions": {
    "debug": [],
    "tracing": {
      "version": 1,
      "startTime": 1731382012.091562,
      "endTime": 1731382012.26379,
      "duration": 172227,
      "execution": {
        "resolvers": [
          {
            "path": [
              "contentNode"
            ],
            "parentType": "RootQuery",
            "fieldName": "contentNode",
            "returnType": "ContentNode",
            "startOffset": 154211,
            "duration": 2470
          },
          {
            "path": [
              "contentNode",
              "isPreview"
            ],
            "parentType": "CptNeighborhood",
            "fieldName": "isPreview",
            "returnType": "Boolean",
            "startOffset": 171875,
            "duration": 154
          }
        ]
      }
    },
    "queryLog": {
      "queryCount": 7,
      "totalTime": 0.007837057113647461,
      "queries": [
        {
          "sql": "SELECT * FROM wp_posts WHERE ID = 21350 LIMIT 1 /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Utils/Utils.php:377] */",
          "time": 0.0005431175231933594,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Utils\\Utils::get_post_preview_id, wp_get_post_revisions, get_post, WP_Post::get_instance"
        },
        {
          "sql": "SELECT   wp_posts.ID\n\t\t\t\t\t FROM wp_posts \n\t\t\t\t\t WHERE 1=1  AND wp_posts.post_parent = 21350  AND wp_posts.post_type = 'revision' AND ((wp_posts.post_status = 'inherit'))\n\t\t\t\t\t \n\t\t\t\t\t ORDER BY wp_posts.post_date DESC, wp_posts.ID DESC\n\t\t\t\t\t LIMIT 0, 1 /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Utils/Utils.php:377] */",
          "time": 0.0004379749298095703,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Server\\Helper->promiseToExecuteOperation, GraphQL\\GraphQL::promiseToExecute, GraphQL\\Executor\\Executor::promiseToExecute, GraphQL\\Executor\\ReferenceExecutor->doExecute, GraphQL\\Executor\\ReferenceExecutor->executeOperation, GraphQL\\Executor\\ReferenceExecutor->executeFields, GraphQL\\Executor\\ReferenceExecutor->resolveField, GraphQL\\Executor\\ReferenceExecutor->resolveFieldValueOrError, WPGraphQL\\Utils\\InstrumentSchema::WPGraphQL\\Utils\\{closure}, WPGraphQL\\Type\\ObjectType\\RootQuery::WPGraphQL\\Type\\ObjectType\\{closure}, WPGraphQL\\Utils\\Utils::get_post_preview_id, wp_get_post_revisions, get_children, get_posts, WP_Query->query, WP_Query->get_posts"
        },
        {
          "sql": "SELECT   wp_posts.*\n\t\t\t\t\t FROM wp_posts \n\t\t\t\t\t WHERE 1=1  AND wp_posts.ID IN (21350) AND wp_posts.post_type IN ('attachment', 'concierges', 'homesites', 'masterplans', 'nav_menu_item', 'neighborhoods', 'page', 'plans', 'post', 'revision', 'sales-rep') AND ((wp_posts.post_status <> 'trash' AND wp_posts.post_status <> 'auto-draft'))\n\t\t\t\t\t \n\t\t\t\t\t ORDER BY FIELD(wp_posts.ID,21350)\n\t\t\t\t\t LIMIT 0, 1 /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/Loader/PostObjectLoader.php:103] */",
          "time": 0.0004229545593261719,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter->wait, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise::runQueue, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise->GraphQL\\Executor\\Promise\\Adapter\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->WPGraphQL\\Data\\Loader\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load_buffered, WPGraphQL\\Data\\Loader\\PostObjectLoader->loadKeys, WP_Query->__construct, WP_Query->query, WP_Query->get_posts"
        },
        {
          "sql": "SELECT DISTINCT t.term_id, tr.object_id\n\t\t\t FROM wp_terms AS t  INNER JOIN wp_term_taxonomy AS tt ON t.term_id = tt.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id\n\t\t\t WHERE tt.taxonomy IN ('category', 'post_tag', 'nav_menu', 'post_format', 'home-types', 'amenities', 'school-districts', 'masterplan-status', 'neighborhood-status', 'floorplan-status', 'homesite-status', 'region') AND tr.object_id IN (21350)\n\t\t\t ORDER BY t.name ASC\n\t\t\t  /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/Loader/PostObjectLoader.php:103] */",
          "time": 0.0006160736083984375,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter->wait, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise::runQueue, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise->GraphQL\\Executor\\Promise\\Adapter\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->WPGraphQL\\Data\\Loader\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load_buffered, WPGraphQL\\Data\\Loader\\PostObjectLoader->loadKeys, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, update_post_caches, update_object_term_cache, wp_get_object_terms, get_terms, WP_Term_Query->query, WP_Term_Query->get_terms"
        },
        {
          "sql": "SELECT post_id, meta_key, meta_value FROM wp_postmeta WHERE post_id IN (21350) ORDER BY meta_id ASC /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/Loader/PostObjectLoader.php:103] */",
          "time": 0.0028879642486572266,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter->wait, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise::runQueue, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise->GraphQL\\Executor\\Promise\\Adapter\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->WPGraphQL\\Data\\Loader\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load_buffered, WPGraphQL\\Data\\Loader\\PostObjectLoader->loadKeys, WP_Query->__construct, WP_Query->query, WP_Query->get_posts, update_post_caches, update_postmeta_cache, update_meta_cache"
        },
        {
          "sql": "SELECT wp_users.ID\n\t\t\t\t FROM wp_users\n\t\t\t\t WHERE 1=1 AND wp_users.ID IN (3)\n\t\t\t\t ORDER BY user_login ASC\n\t\t\t\t LIMIT 0, 1 /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/Loader/UserLoader.php:135] */",
          "time": 0.00030493736267089844,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter->wait, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise::runQueue, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise->GraphQL\\Executor\\Promise\\Adapter\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->WPGraphQL\\Data\\Loader\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load_buffered, WPGraphQL\\Data\\Loader\\UserLoader->loadKeys, WP_User_Query->__construct, WP_User_Query->query"
        },
        {
          "sql": "SELECT DISTINCT wp_users.ID FROM wp_posts INNER JOIN wp_users ON post_author = wp_users.ID WHERE ( ( post_type = 'post' AND ( post_status = 'publish' ) ) OR ( post_type = 'page' AND ( post_status = 'publish' ) ) OR ( post_type = 'masterplans' AND ( post_status = 'publish' ) ) OR ( post_type = 'neighborhoods' AND ( post_status = 'publish' ) ) OR ( post_type = 'plans' AND ( post_status = 'publish' ) ) OR ( post_type = 'homesites' AND ( post_status = 'publish' ) ) ) AND post_author IN ( 3 ) ORDER BY FIELD( wp_users.ID, 3) /* From [xxxcodev.wpenginepowered.com/index.php?graphql] in [/nas/content/live/xxxcodev/wp-content/plugins/wp-graphql/src/Data/Loader/UserLoader.php:79] */",
          "time": 0.002624034881591797,
          "stack": "require('wp-blog-header.php'), wp, WP->main, WP->parse_request, do_action_ref_array('parse_request'), WP_Hook->do_action, WP_Hook->apply_filters, WPGraphQL\\Router::resolve_http_request, WPGraphQL\\Router::process_http_request, WPGraphQL\\Request->execute_http, GraphQL\\Server\\StandardServer->executeRequest, GraphQL\\Server\\Helper->executeOperation, GraphQL\\Executor\\Promise\\Adapter\\SyncPromiseAdapter->wait, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise::runQueue, GraphQL\\Executor\\Promise\\Adapter\\SyncPromise->GraphQL\\Executor\\Promise\\Adapter\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->WPGraphQL\\Data\\Loader\\{closure}, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load, WPGraphQL\\Data\\Loader\\AbstractDataLoader->load_buffered, WPGraphQL\\Data\\Loader\\UserLoader->loadKeys, WPGraphQL\\Data\\Loader\\UserLoader->get_public_users"
        }
      ]
    },
    "queryAnalyzer": {
      "keys": "b2a2f1ba23cc0462de87335246094cad42dfdf0ffed88e0cf4d813bffd8deebc graphql:Query operation:neighborhoodQuery cG9zdDoyMTM1MA==",
      "keysLength": 123,
      "keysCount": 4,
      "skippedKeys": "",
      "skippedKeysSize": 0,
      "skippedKeysCount": 0,
      "skippedTypes": []
    }
  }
}

Re-attaching the video

Screencast.from.07-11-24.19.03.08.webm

@JorgeSivil
Copy link
Author

JorgeSivil commented Nov 12, 2024

@justlevine uri property does work when all plugins are disabled, I guess we can leave that out
I enabled all plugins back one by one and it was still working, unless there's some caching mechanism, I guess it's not happening anymore 🤔

"uri": "/?post_type=neighborhoods&p=21350"

This is a new never-published post. It has a URL in theory. I'm wondering if the URI is a missmatch (provided the value returned above) because it was never published.

image

Once I publish it, the URI ID starts working. After I move it back to draft. It keeps working

image

One extra thing to note:

I edit the title, click "Preview" (not Save Draft)

Re-run the query, and it still says "isPreview": false, while showing the 33 that I just added

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: author response Additional Pending information from the author has been requested from the author type: bug Issue that causes incorrect or unexpected behavior
Projects
Status: 🆕 New
Development

No branches or pull requests

2 participants