Vincit / venia

Clojure(Script) graphql query generation
Eclipse Public License 1.0
197 stars 20 forks source link

Add support for selecting types (inline fragments) #34

Open positron opened 6 years ago

positron commented 6 years ago

I don't think it is possible to render the ... on Droid part of this query using what exists today.

query HeroForEpisode($ep: Episode!) {
  hero(episode: $ep) {
    name
    ... on Droid {
      primaryFunction
    }
  }
}

If I can, tell me how and I'll update the documentation if needed :-)

madstap commented 6 years ago

As far as I can tell, this feature is not implemented. You can use this ugly hack though

(defn inline-fragment
  [type fields]
  [(keyword (str "... on " (name type))) fields])

(comment

  (require '[venia.core :as venia])

  (venia/graphql-query {:venia/queries [[:hero {:episode :A_NEW_HOPE}
                                         [:name
                                          (inline-fragment :Droid [:primaryFunction])]]]})

  ;=> "{hero(episode:A_NEW_HOPE){name,... on Droid{primaryFunction}}}"

  )
err commented 4 years ago

desired helper made available via https://github.com/Vincit/venia/pull/42/commits/fc786c911c9bb11920d83a40617816cb3867654f on #42