walmartlabs / lacinia

GraphQL implementation in pure Clojure
http://lacinia.readthedocs.io/en/latest/
Other
1.82k stars 160 forks source link

Fixes a runtime error that occurs when deep-merging fragments #463

Open namenu opened 3 months ago

namenu commented 3 months ago

Depending on the position of the fragment, you'll get inconsistent values.

I fixed a similar issue in #453, but in that case the fragment was nested, whereas this case is not.

This fails:

query MyQuery {
  node(id: "1000") {
    ... on Post {
      id
      ...PostFragment
    }
  }
}

fragment PostFragment on Post {
  author {
    alwaysFail
  }
  ...PostFragment2   # <--
}

fragment PostFragment2 on Post {
  author {
    name
  }
}

While this is not:

query MyQuery {
  node(id: "1000") {
    ... on Post {
      id
      ...PostFragment
    }
  }
}

fragment PostFragment on Post {
  ...PostFragment2   # <--
  author {
    alwaysFail
  }
}

fragment PostFragment2 on Post {
  author {
    name
  }
}

The reason seems to be that deep-merge is not commutative. Given one of arguments isnil or ::null, exception is thrown.