aPureBase / KGraphQL

Pure Kotlin GraphQL implementation
https://kgraphql.io
MIT License
298 stars 58 forks source link

Add extensions-Field to GraphQLError.kt #166

Closed MaaxGr closed 2 years ago

MaaxGr commented 2 years ago

Fixes #165

MaaxGr commented 2 years ago

Tested it. Everything works:

throw GraphQLError(message = "test", extensions = mapOf("code" to "BAD_USER_INPUT"))

Returns:

{
  "errors": [
    {
      "message": "test",
      "locations": [],
      "path": [],
      "extensions": {
        "code": "BAD_USER_INPUT"
      }
    }
  ]
}
jeggy commented 2 years ago

Hi @MaaxGr

This looks great! Could you write a unit test that validates that your implementation also works?

Sorry for this late response.

MaaxGr commented 2 years ago

Haha. Yeah of course. Hopefully that also doesn't have to wait for some months :D Let's see, when I have time for that

jeggy commented 2 years ago

Sure :) And I'm gonna make sure that this repository won't stand stale again.

We have opened GitHub discussions and I'm looking for people to help out #187 Looking for maintainers

MaaxGr commented 2 years ago

Hey. I have added a unit test to verify the serialize()-Method with extensions-Object included.

But to be honest i now realize that the implementation doesn't exactly matches the spec.

GraphQL services may provide an additional entry to errors with key extensions. This entry, if set, must have a map as its value. This entry is reserved for implementors to add additional information to errors however they see fit, and there are no additional restrictions on its contents. https://spec.graphql.org/June2018/#example-90475

This example shows that there can also be substructures in one extension, which is currently not supported in my implementation. https://www.apollographql.com/docs/apollo-server/data/errors/

How sould we deal with this?

MaaxGr commented 2 years ago

Closing this, as we probably should go with MR #171.