From 90105be71c8fc71322ebae47a5d26407c99d8fdf Mon Sep 17 00:00:00 2001 From: Ivan Willig Date: Fri, 7 Feb 2025 11:47:24 -0500 Subject: [PATCH] Support leading Pipes in Union Synatx 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 --- resources/com/walmartlabs/lacinia/schema.g4 | 2 +- .../lacinia/parser/schema_test.clj | 26 ++++++++++++------- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/resources/com/walmartlabs/lacinia/schema.g4 b/resources/com/walmartlabs/lacinia/schema.g4 index ce9d110b..9818e146 100644 --- a/resources/com/walmartlabs/lacinia/schema.g4 +++ b/resources/com/walmartlabs/lacinia/schema.g4 @@ -118,7 +118,7 @@ unionExtDef ; unionTypes - : (anyName '|')* anyName + : '|'? ( anyName '|')* anyName ; enumDef diff --git a/test/com/walmartlabs/lacinia/parser/schema_test.clj b/test/com/walmartlabs/lacinia/parser/schema_test.clj index 2a3ddd12..729e1e95 100644 --- a/test/com/walmartlabs/lacinia/parser/schema_test.clj +++ b/test/com/walmartlabs/lacinia/parser/schema_test.clj @@ -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