Skip to content

Commit

Permalink
Prevent fragment spread + selection set
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilmo Raunio committed Jun 7, 2024
1 parent 77ed180 commit fd14cea
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/oksa/parse.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@
[::children [:? [:schema [:ref ::SelectionSet]]]]]
[:catn
[::node [:schema [:ref ::WrappedField]]]]
[:catn
[::node [:schema [:ref ::FragmentSpreadSelection]]]]
;; Special case where subsequent selection set is allowed
[:catn
[::node [:schema [:ref ::BareField]]]
[::children [:? [:schema [:ref ::SelectionSet]]]]]]]]]
::WrappedField [:orn [::WrappedField [:schema [:ref ::Field]]]]
::FragmentSpreadSelection [:orn [::FragmentSpread [:schema [:ref ::FragmentSpread]]]]
::Selection [:orn
[::FragmentSpread [:schema [:ref ::FragmentSpread]]]
[::InlineFragment [:schema [:ref ::InlineFragment]]]
[::NakedField [:schema [:ref ::NakedField]]]]
::Field [:orn [::Field [:cat
Expand Down
8 changes: 7 additions & 1 deletion test/oksa/alpha/api_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,13 @@
(api/select
(api/field :foo
(api/select :qux :baz))
(api/select :basho))))))))
(api/select :basho))))))
(t/testing "fragment spread + selection set should throw an exception"
(t/is (thrown? #?(:clj Exception :cljs js/Error)
(api/gql
(api/select
(api/fragment-spread {:name :foo})
(api/select :bar))))))))

(t/deftest transformers-test
(t/testing "names are transformed when transformer fn is provided"
Expand Down
6 changes: 5 additions & 1 deletion test/oksa/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,11 @@
(unparse-and-validate [[:foo {}] [:bar]])) "field w/o selection-set + sequential selection-set parses correctly")
(t/testing "sequential selection sets should throw an exception"
(t/is (thrown? #?(:clj Exception :cljs js/Error)
(unparse-and-validate [[:foo {} [:qux :baz]] [:basho]]))))))
(unparse-and-validate [[:foo {} [:qux :baz]] [:basho]]))))
(t/testing "fragment spread + selection set should throw an exception"
(t/is (thrown? #?(:clj Exception :cljs js/Error)
(oksa.core/gql [[:... {:name :foo}]
[:bar]]))))))

(t/deftest transformers-test
(t/testing "names are transformed when transformer fn is provided"
Expand Down

0 comments on commit fd14cea

Please sign in to comment.