higherkindness / mu-haskell

Mu (μ) is a purely functional framework for building micro services.
http://higherkindness.io/mu-haskell/
Apache License 2.0
334 stars 19 forks source link

GraphQL Inline Fragments Are Not Yet Supported #291

Closed kutyel closed 3 years ago

kutyel commented 3 years ago

When doing elm-graphql the way to resolve unions is the following:

type FunctionOrType
    = FunctionDetails String
    | TypeDetails String

commitSelection : SelectionSet CommitSet Commit
commitSelection =
    SelectionSet.succeed CommitSet
        |> with Koral.Api.Object.Commit.hash
        |> with (Koral.Api.Object.Commit.element { name = "absZero" } elementSelection)

elementSelection : SelectionSet FunctionOrType Element
elementSelection =
    Koral.Api.Union.Element.fragments
        { onFunction = SelectionSet.map FunctionDetails Koral.Api.Object.Function.name
        , onType = SelectionSet.map TypeDetails Koral.Api.Object.Type.name
        }

Which returns this ugly message from our GraphQL server: 😭

Something went wrong: inline fragments are not (yet) supported

I guess it is time to fill the holes in https://github.com/higherkindness/mu-haskell/blob/master/graphql/src/Mu/GraphQL/Query/Parse.hs#L819 !! 💪🏻

kutyel commented 3 years ago

I was able to print the query generated by elm-graphql and here it is:

query {
  project1267710958: project(id: "example") {
    module1182648713: module(name: "example") {
      commit3038732989: commit(hash: "34567") {
        element3002909790: element(name: "absZero") {
          __typename
          ... on Function {
            name3832528868: name
          }
          ... on Type {
            name3832528868: name
          }
        }
        hash3832528868: hash
      }
      name3832528868: name
    }
    id3832528868: id
  }
}