drupal-graphql / graphql

GraphQL integration for Drupal 9/10
287 stars 202 forks source link

When queries entity field reference without value multiple errors are display #1029

Open Eduardo-Morales-Alberti opened 4 years ago

Eduardo-Morales-Alberti commented 4 years ago

I created a query based on the example module, but with a custom entity content with field references. I query all fields, and if the references exists there are no problem, but when try to query an entity that does not have references the following errors are showed.

{
  getProjects(uuid: "28077916-0cd4-4754-b8c2-7f10dcfccd7e", offset: 0, limit: 1) {
    items {
        id
            uuid
            title
            author
            list {
                uuid
                title
                manipulation {
                    id
                    uuid
                    title
                    author
                    targetCssSelector
                }
            }
    }
  }
}
{
    "data": {
        "getProjects": {
            "items": [
                {
                    "id": 20,
                    "uuid": "28077916-0cd4-4754-b8c2-7f10dcfccd7e",
                    "title": "HELLO GRAPHQL 5",
                    "author": "Graphql",
                    "list": [
                        {
                            "uuid": "362d2002-e6a3-4f58-a5a5-8a390d23ba40",
                            "title": "HELLO URL GRAPHQL",
                            "manipulation": {
                                "id": null,
                                "uuid": "",
                                "title": null,
                                "author": null,
                                "targetCssSelector": ""
                            }
                        }
                    ]
                }
            ]
        }
    },
    "extensions": [
        {
            "message": "Call to a member function id() on boolean",
            "locations": [
                {
                    "line": 12,
                    "column": 6
                }
            ],
            "path": [
                "getProjects",
                "items",
                0,
                "list",
                0,
                "manipulation",
                "id"
            ]
        },
        {
            "message": "Argument 1 passed to Drupal\\graphql\\Plugin\\GraphQL\\DataProducer\\Entity\\EntityLabel::resolve() must implement interface Drupal\\Core\\Entity\\EntityInterface, boolean given",
            "locations": [
                {
                    "line": 14,
                    "column": 6
                }
            ],
            "path": [
                "getProjects",
                "items",
                0,
                "list",
                0,
                "manipulation",
                "title"
            ]
        },
        {
            "message": "Argument 1 passed to Drupal\\graphql\\Plugin\\GraphQL\\DataProducer\\Entity\\EntityOwner::resolve() must implement interface Drupal\\Core\\Entity\\EntityInterface, boolean given",
            "locations": [
                {
                    "line": 15,
                    "column": 6
                }
            ],
            "path": [
                "getProjects",
                "items",
                0,
                "list",
                0,
                "manipulation",
                "author"
            ]
        }
    ]
}

Documentation: Example based on https://github.com/drupal-graphql/graphql/blob/8.x-4.x/examples/src/Plugin/GraphQL/DataProducer/QueryArticles.php

Kingdutch commented 2 years ago

Hey @Eduardo-Morales-Alberti,

I hope you have solved this problem in the meantime but if not: it sounds like your custom data producers are returning values from a Drupal loader of some sort directly. The loader is returning FALSE which causes the GraphQL module to call field resolvers on the values. Ensuring that FALSE is correctly translated to NULL will ensure that the later field resolvers are not called and don't throw an error.