0

is the any way that throw an error by GraphQL\Error\Error with no additional data except message. the current return data is

{
  "errors": [
    {
      "message": "Some Errors",
      "extensions": {
        "reason": "",
        "category": "custom"
      },
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "to the path"
      ],
      "trace": [{},{},{},{}]
    }
  ],
  "data": {
    "testQuery": null
  }
}

it contains unnecessary data

but I want something like:

{
  "errors": [
    {
      "message": "Some Errors",
      "extensions": {
        "reason": "",
        "category": "custom"
      },
      
  ],
  "data": {
    "testQuery": null
  }
}
MrM
  • 11
  • 1
  • 3

2 Answers2

0

You can throw your own exceptions, that will allow you to do that. Check https://lighthouse-php.com/5/digging-deeper/error-handling.html#registering-error-handlers.

Enzo Notario
  • 639
  • 4
  • 9
  • I've tried that also, it just let me add some data to exception, not removing! – MrM Aug 18 '21 at 07:10
  • mm you may do it.. but it would break graphql specs.. so, firstly, try to attach you to graphql specs.. if you still want to do that, you will have to touch some lighthouse/webonyx-graphql-php code.. – Enzo Notario Aug 18 '21 at 16:45
  • actually I thought it wouldn't be good show to user the directories on the server and `trace` field exactly does that. I want to remove it for this purpose . is there any other way to achieve this goal – MrM Aug 18 '21 at 18:53
  • Ok, if we are talking about the `trace`, you see it because you have `APP_DEBUG=true` in your `.env`, or `APP_ENV=local`. Hopefully in your production server you will not see it. – Enzo Notario Aug 19 '21 at 21:20
0

for a simple error you can use this code, in case you don't want to create an error handler class

use GraphQL\Error\Error;

...

return Error::createLocatedError('Some Errors');

Mohamed SLimani
  • 351
  • 2
  • 9