pgutkowski / KGraphQL

Pure Kotlin GraphQL implementation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fragments not resolving correctly on same data node

puug opened this issue · comments

Having an issue where fragments that operate on the same data node are not being merged, rather only the last fragment is being resolved.

Setup

data class Contact(val name: Name = Name())
data class Name(val firstName: String = "Bob", val lastName: String = "Jones")
 KGraphQL.schema {
        query("contact") {
            resolver { -> Contact() }
        }

        type<Contact> { }
}

A simple query resolves correctly

{
  contact {
    name {
      firstName
      lastName
    }
  }
}

Result

{
  "data": {
    "contact": {
      "name": {
        "firstName": "Bob",
        "lastName": "Jones"
      }
    }
  }
}

But when multiple fragments are used that operate on name only the last is resolved

fragment firstName on Contact {
  name {
    firstName
  }
}

fragment lastName on Contact {
  name {
    lastName
  }
}

{
  contact {
     ...firstName
     ...lastName
  }
}

Result

{
  "data": {
    "contact": {
      "name": {
        "lastName": "Jones"
      }
    }
  }
}

The fragments work as expected when used independently, and if they operate on different nodes of data they both resolve.

Expected
Both fragment should be resolved and firstName and lastName returned. That's my understanding of the spec, and I ran a similar experiment against express-graphql and it merges correctly. This leads me to believe it's a bug within KGraphQL.