nautilus/gateway

Composing results fails for single item queries

berend opened this issue · 2 comments

Hi there,

we found a bug it seems.

Given two schemas

A

schema {
    query: Query
}

type Query {
    node(id: ID!): Node
    Thing(id: ID!): Thing
    Things(limit: limit: Int = 10): ThingList
}


interface Node {
    id: ID!
}

ThingList {
	list: [Thing]
}


type Thing implements Node {
    id: ID!
    foo: String!
}

B

schema {
    query: Query
}

type Query {
    node(id: ID!): Node
    Thing(id: ID!): Thing
}


interface Node {
    id: ID!
}

type Thing implements Node {
    id: ID!
    bar: String!
}

and using nautilus to combine them.

This single item query does not work:

{
  Thing(id:"Thing:110915031829") {
    id
    foo
    bar
  }
}

This query does work:

{
  Things(limit: 3) {
    list {
      id
      foo
      bar
    }
  }
}

Reason seems to be that here

obj, err := executorExtractValue(target, resultLock, path)
a list is expected and not a single value. For the error above, a single item is here and the the error returned from executorExtractValue is

did not encounter a list when expected. Point: Thing#Thing:110915031829. Field: Thing. Result map[id:Thing:110915031829 foo:foo]

We are willing to do a PR for this. Would that be welcome?
(Since it is somehow deep into your tool and we are only using this for a day, we might need a bit of guidance.)

It looks like the reason for this is that our node-id contains a :. Then this line

if strings.Contains(point, ":") {

assumes, that we a looking at a list

We have a fix and will add a test.