AxeWP / wp-graphql-rank-math

Add GraphQL support for RankMath SEO
GNU General Public License v3.0
50 stars 7 forks source link

breadcrumb produce Internal server error on ContentType #81

Closed MonPetitUd closed 5 months ago

MonPetitUd commented 5 months ago

Description

When "ContentType" is returned by a nodeByUri query (for example on the page for posts e.g. "/blog" or woocommerce shop page e.g. "/shop") including "breadcrumbs" under "NodeWithRankMathSeo" produces an internal server error. The data is still returned with the breadcrumbs being null. I suspect breadcrumbs are not actually available on this type?

Steps to reproduce

Example query:

query rankMathNodeByUri {
    nodeByUri(uri: "/blog") {
        __typename
        ... on NodeWithRankMathSeo {
            seo {
                __typename
                title
                description
                breadcrumbs {
                    text
                    isHidden
                    url
                }
            }
        }
    }
}

Result:

{
    "errors": [
        {
            "message": "Internal server error",
            "extensions": {
                "category": "internal"
            },
            "locations": [
                {
                    "line": 9,
                    "column": 5
                }
            ],
            "path": [
                "nodeByUri",
                "seo",
                "breadcrumbs"
            ]
        }
    ],
    "data": {
        "nodeByUri": {
            "__typename": "ContentType",
            "seo": {
                "__typename": "RankMathPostTypeSeo",
                "title": "Blog - Website Name",
                "description": "Blog page SEO description",
                "breadcrumbs": null
            }
        }
    }
}

Additional context

No response

Plugin Version

0.1.1

WordPress Version

6.4.3

WPGraphQL Version

1.22.1

RankMath SEO Version

1.0.216

Additional enviornmental details

WooGraph 0.19.0 WooCommerce 8.6.1

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

Please confirm that you have disabled ALL plugins except for RankMath SEO, WPGraphQL, and WPGraphQL for Rank Math

justlevine commented 5 months ago

Thanks for taking the time to report this @MonPetitUd !

Would you be able to:

  1. Confirm what PHP version you're running, and
  2. Enable GraphQL Debugging (either via GraphQL Settings or with the GRAPHQL_DEBUG constant), rerun the query, and share the debugMessage that (hopefully) gets generated?

I'm working on a fix now, but that information will help me confirm I'm on the right path 🤞

justlevine commented 5 months ago

(Additional context - the fatal error itself seems to be a PHP error and solvable by setting a default value to SeoModel:$databaseId. The larger underlying issue that ContentType objects don't have a global archive context, due to the lack of an archive interface, so even with the fatal fixed the data itself is bad).

MonPetitUd commented 5 months ago

No worries @justlevine.

PHP 7.4

Below is the response with GraphQL debugging on:

{
    "errors": [
        {
            "debugMessage": "Typed property WPGraphQL\\RankMath\\Model\\Seo::$database_id must not be accessed before initialization",
            "message": "Internal server error",
            "extensions": {
                "category": "internal"
            },
            "locations": [
                {
                    "line": 9,
                    "column": 5
                }
            ],
            "path": [
                "nodeByUri",
                "seo",
                "breadcrumbs"
            ]
        }
    ],
    "data": {
        "nodeByUri": {
            "__typename": "ContentType",
            "seo": {
                "__typename": "RankMathPostTypeSeo",
                "title": "Blog - Website Name",
                "description": "Blog page SEO description",
                "breadcrumbs": null
            }
        }
    },
    "extensions": {
        "debug": [],
        "queryAnalyzer": {
            "keys": "f99ddc3f7fbf19aeff4b9a5da13138928f5f3ea80617099f0537512a628a3a6d graphql:Query operation:rankMathNodeByUri cG9zdF90eXBlOnBvc3Q=",
            "keysLength": 127,
            "keysCount": 4,
            "skippedKeys": "",
            "skippedKeysSize": 0,
            "skippedKeysCount": 0,
            "skippedTypes": []
        }
    }
} 
justlevine commented 5 months ago

Hey @MonPetitUd

90 should fix this issue. Please feel free to test.

(I'm putting it through the final paces myself, at which point I'll merge and start the release process).

justlevine commented 5 months ago

(This is closed automatically on merge, if you're still running into trouble, comment here and I'll repoen)