Fork me on GitHub
#graphql
<
2021-10-28
>
Ryan14:10:35

Does anyone have advice for graphql queries in a reframe frontend app? Just suffer through strings? graphql-builder? Definitely using parameterized queries so no need to really stringbash, just missing nice formatting and syntax highlighting. Has anyone gotten Cursive working with IntelliJ language injections?

mafcocinco16:10:52

We have been using that for some time and has worked pretty well.

mattly15:10:06

it’s been a while since I’ve done this, but I had had a “read-file” macro and loaded the query into a def via it

1
thom15:10:50

I wrote a hacky and pretty minimal Hiccup-ish syntax. It covers this functionality and basically no more, happy to bung it up on GitHub if it might be useful:

(deftest query-test
  (are [input output] (equals-ignore-whitespace output (query input))
    [:foo [:bar :baz]]
    "{ foo { bar baz } }"
    
    [:bar [:baz :foo]]
    "{ bar { baz foo } }"

    [:foo [:bar :graphql/alias :baz
           :baz :graphql/alias :bar
           :blah]]
    "{ foo { bar: baz baz: bar blah } }"
    
    [:foo {:id 1} [:bar :baz]]
    "{ foo(id: 1) { bar baz } }"

    [:fop :graphql/alias :foo {:id 1} [:bar :baz]]
    "{ fop: foo(id: 1) { bar baz } }"

    [:foo {:id 1 :name "foo"} [:bar :baz]]
    "{ foo(id: 1, name: \"foo\") { bar baz } }"
    
    [:foo {:id 2} [:bar {:id 4} :baz {:fizzle "wobble" :fuzzle [:wibble]}]]
    "{ foo(id: 2) { bar(id: 4) baz(fizzle: \"wobble\", fuzzle: [wibble]) } }"

    [:foo {:id 1} [:bar {:id 2} [:baz {:order :asc} :bling] :boggle] :bargle]
    "{ foo(id: 1) { bar(id: 2) { baz(order: asc) bling } boggle } bargle }"))

(deftest multiple-query-test
  (is (equals-ignore-whitespace "query { foo { bar baz } bar { baz foo } }"
                                (query [:foo [:bar :baz]] [:bar [:baz :foo]]))))

👍 1
Ryan15:10:23

That would be awesome

mafcocinco17:10:29

I posted this in a reply but probably useful for general consumption: https://github.com/Vincit/venia

🙏 1
mafcocinco17:10:45

We have been using that lib for about 2 years and it has served us well.

thom17:10:51

oh nice, spectacularly failed to find this when googling for something previously.