Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sequence of type ChunkedSeq leads to invalid query from graphql-query #46

Open
transducer opened this issue Mar 23, 2022 · 1 comment · May be fixed by #47
Open

Sequence of type ChunkedSeq leads to invalid query from graphql-query #46

transducer opened this issue Mar 23, 2022 · 1 comment · May be fixed by #47

Comments

@transducer
Copy link

When passing a sequence to the graphql-query function this leads to different behaviour whether the sequence is a ChunkedSeq or an IndexedSeq.

Example

(require '[venia.core :refer [graphql-query]])

(def indexed-seq
  (seq (mapv (comp keyword str) (take 10 (range)))))
;; => (:0 :1 :2 :3 :4 :5 :6 :7 :8 :9)

(type indexed-seq)
;; => cljs.core/IndexedSeq

(graphql-query
 {:queries [[:foo {:bar indexed-seq}]]})
;; => "{foo(bar:[0,1,2,3,4,5,6,7,8,9])}"

(def chunked-seq
  (seq (mapv (comp keyword str) (take 40 (range)))))
;; => (:0 :1 :2 :3 :4 :5 :6 :7 :8 :9 :10 ... :39)

(type chunked-seq)
;; => cljs.core/ChunkedSeq

(graphql-query
 {:queries [[:foo {:bar chunked-seq}]]})
;; => "{foo(bar:(:0 :1 :2 :3 :4 :5 :6 :7 :8 :9 :10 ... :39))}"

So when the sequence is longer and thus Clojure internally handles it as a ChunkedSeq instead of an IndexedSeq, the collection in the arguments is processed to become a list with keywords, instead of a vector with symbols. In the ChunkedSeq case the query generated is invalid GraphQL.

Workaround

Ensure the sequence passed to graphql-query is not of type ChunkedSeq, for example by marshalling the sequence into a vector.

Note: this is a crosspost of district0x/graphql-query#9.

@transducer
Copy link
Author

Reason is that the protocol is extended to an IndexedSeq at https://github.com/Vincit/venia/blob/master/src/venia/core.cljc#L53, but not to a ChunkedSeq.

transducer added a commit to mediquest-nl/venia that referenced this issue Mar 23, 2022
@transducer transducer linked a pull request Mar 23, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant