Skip to content

Commit

Permalink
Support leading Pipes in Union Synatx
Browse files Browse the repository at this point in the history
This change adds support for leading pipe values in union
definitions. This was added to GraphQL in 2017.

This should address issue #465.

Co-authored-by: Toby Crawley <[email protected]>
  • Loading branch information
iwillig and tobias committed Feb 7, 2025
1 parent 99d71e1 commit 90105be
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion resources/com/walmartlabs/lacinia/schema.g4
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ unionExtDef
;

unionTypes
: (anyName '|')* anyName
: '|'? ( anyName '|')* anyName
;

enumDef
Expand Down
26 changes: 17 additions & 9 deletions test/com/walmartlabs/lacinia/parser/schema_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -181,17 +181,25 @@
(parse-string "interface Flow { ebb : String }"))))

(deftest schema-union
(is (= {:unions
{:Matter
{:members [:Solid :Liquid :Gas :Plasma :INPUT_OBJECT]}}}
(parse-string "union Matter = Solid | Liquid | Gas | Plasma | INPUT_OBJECT")))

(testing "basic union type"
(is (= {:unions
{:Matter
{:members [:Solid :Liquid :Gas :Plasma :INPUT_OBJECT]}}}
(parse-string "union Matter = Solid | Liquid | Gas | Plasma | INPUT_OBJECT"))))

(testing "leading pipe chars in union"
(is (= {:unions
{:Matter
{:members [:Solid :Liquid :Gas :Plasma :INPUT_OBJECT]}}}
(parse-string "union Matter = | Solid | Liquid | Gas | Plasma | INPUT_OBJECT"))))

(testing "extensions"
(is (= {:unions
{:Matter
{:members [:Solid :Liquid :Gas :Plasma :INPUT_OBJECT]}}}
(parse-string (str "union Matter = Solid\n"
"extend union Matter = Liquid | Gas | Plasma | INPUT_OBJECT"))))))
(is (= {:unions
{:Matter
{:members [:Solid :Liquid :Gas :Plasma :INPUT_OBJECT]}}}
(parse-string (str "union Matter = Solid\n"
"extend union Matter = Liquid | Gas | Plasma | INPUT_OBJECT"))))))

(deftest schema-field-args
(is (= {:objects
Expand Down

0 comments on commit 90105be

Please sign in to comment.