From 064ae8199051e5cebdc4598441dabd809ec9485b Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Fri, 12 Jul 2024 15:38:49 +0530 Subject: [PATCH] fix a bug in which a closing parenthesis in @graphql directive failed to parse as json --- sql/directives.sql | 2 +- test/expected/comment_directive.out | 29 ++++++++++++++++++++++++++++- test/sql/comment_directive.sql | 17 ++++++++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/sql/directives.sql b/sql/directives.sql index 17a5d3d3..cf0506d8 100644 --- a/sql/directives.sql +++ b/sql/directives.sql @@ -11,7 +11,7 @@ as $$ ( regexp_match( comment_, - '@graphql\((.+?)\)' + '@graphql\((.+)\)' ) )[1]::jsonb, jsonb_build_object() diff --git a/test/expected/comment_directive.out b/test/expected/comment_directive.out index 427f7bb8..d80c609b 100644 --- a/test/expected/comment_directive.out +++ b/test/expected/comment_directive.out @@ -1,9 +1,36 @@ select graphql.comment_directive( comment_ := '@graphql({"name": "myField"})' - ) + ); comment_directive --------------------- {"name": "myField"} (1 row) +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with (parentheses)"})' + ); + comment_directive +---------------------------------------- + {"name": "myField with (parentheses)"} +(1 row) + +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with a (starting parenthesis"})' + ); + comment_directive +-------------------------------------------------- + {"name": "myField with a (starting parenthesis"} +(1 row) + +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with an ending parenthesis)"})' + ); + comment_directive +------------------------------------------------- + {"name": "myField with an ending parenthesis)"} +(1 row) + diff --git a/test/sql/comment_directive.sql b/test/sql/comment_directive.sql index c3f999be..b4ba3794 100644 --- a/test/sql/comment_directive.sql +++ b/test/sql/comment_directive.sql @@ -1,4 +1,19 @@ select graphql.comment_directive( comment_ := '@graphql({"name": "myField"})' - ) + ); + +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with (parentheses)"})' + ); + +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with a (starting parenthesis"})' + ); + +select + graphql.comment_directive( + comment_ := '@graphql({"name": "myField with an ending parenthesis)"})' + );