ohler55 / agoo

A High Performance HTTP Server for Ruby
MIT License
912 stars 39 forks source link

__typename is not working properly #87

Closed JonasBorchelt closed 4 years ago

JonasBorchelt commented 4 years ago

Hey again,

if you do the following request in the song example:

{
  artist(name:"Fazerdaze") {
    name
    songs{
      name
      duration
      __typename
    }
    __typename
  }
  __typename
}

You get:

{
  "errors": [
    {
      "message": "Internal error, failed to determine the __typename.",
      "code": "eval error",
      "timestamp": "2020-05-05T09:32:12.193248000Z"
    }
  ]
}

It's working on the query root with no problem. But as soon it's on a type, it's not working.

ohler55 commented 4 years ago

I'll look into it tonight. Is the schema the same as in the songs example?

ohler55 commented 4 years ago

Agoo uses directives to associate a GraphQL type with a Ruby class. During evaluation fields resolve into Ruby objects Agoo must then determine the type for a given Ruby class. It could be smarter and look at the schema types except when a Union or Interface is used and then there is no choice but to have a map for Ruby class to GraphQL type. Right now Agoo uses that map for all calls to __typename.

To fix your immediate issue, make sure each type has an @ruby() directive. An example if this is the test directory but here is what the Artist type would start with:

type Artist @ruby(class:"Artist") {

Leave this issue open though and I'll try to get __typename to fallback to the schema if it can.

JonasBorchelt commented 4 years ago

Perfect! Much thanks for your answer. This helps a lot. Yeah, I was debugging through the code and found the part where it checks if "ruby" is there.

Thank you for your effort.