Skip to content

Commit

Permalink
Merge pull request #338 from walmartlabs/20201009-directive-arg-defaults
Browse files Browse the repository at this point in the history
Fix bug with true/false/null literal values in SDL
  • Loading branch information
hlship committed Oct 12, 2020
2 parents 17b200a + 54b1d77 commit 4f38697
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 16 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ per [the GraphQL specification](http://spec.graphql.org/June2018/#sec-Root-Opera
Added function `com.walmartlabs.lacinia.executor/selection` which provides access to
the details about the selection, including directives and nested selections.

Fixed problems with the literal values `true`, `false`, and `null` when parsing Schema Definition Language files.
## 0.37.0 -- 30 Jun 2020

Added new function `com.walmartlabs.lacinia.util/inject-streamers`, used to
Expand Down
4 changes: 2 additions & 2 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject com.walmartlabs/lacinia "0.38.0-alpha-2"
(defproject com.walmartlabs/lacinia "0.38.0-alpha-3"
:description "A GraphQL server implementation in Clojure"
:url "https://github.com/walmartlabs/lacinia"
:license {:name "Apache, Version 2.0"
Expand All @@ -11,7 +11,7 @@
[org.clojure/data.json "1.0.0"]]
:source-paths ["src"]
:profiles {:dev {:dependencies [[criterium "0.4.6"]
[expound "0.8.5"]
[expound "0.8.6"]
[joda-time "2.10.6"]
[com.walmartlabs/test-reporting "1.0.0"]
[io.aviso/logging "0.3.2"]
Expand Down
8 changes: 4 additions & 4 deletions resources/com/walmartlabs/lacinia/schema.g4
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ K_TRUE : 'true' ;
K_FALSE : 'false' ;
K_NULL : 'null' ;

BooleanValue
booleanValue
: K_TRUE
| K_FALSE
;
Expand All @@ -238,8 +238,8 @@ value
| FloatValue
| StringValue
| BlockStringValue
| BooleanValue
| NullValue
| booleanValue
| nullValue
| enumValue
| arrayValue
| objectValue
Expand All @@ -261,7 +261,7 @@ objectField
: anyName ':' value
;

NullValue
nullValue
: K_NULL
;

Expand Down
8 changes: 6 additions & 2 deletions src/com/walmartlabs/lacinia/parser/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -352,9 +352,13 @@
[prod]
(xform-second prod))

(defmethod xform :booleanvalue
(defmethod xform :booleanValue
[prod]
(Boolean/valueOf ^String (second prod)))
(Boolean/valueOf ^String (-> prod second second)))

(defmethod xform :nullValue
[_]
nil)

(defmethod xform :intvalue
[prod]
Expand Down
45 changes: 37 additions & 8 deletions test/com/walmartlabs/lacinia/parser/schema_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@
{:Ebb
{:fields
{:flow
{:args {:input {:type 'Boolean}}
{:args {:input {:type 'Boolean
:default-value false}}
:type 'String}}}}}
(parse-string "type Ebb { flow (input: Boolean) : String }"))))
(parse-string "type Ebb { flow (input: Boolean = false) : String }"))))

(deftest schema-directives
(is (= '{:directive-defs
Expand All @@ -222,6 +223,27 @@
:line 1}]}
(parse-string "directive @Dupe (a : String, b : String, a : String) on ENUM")))

(deftest directive-arg-literals
(is (= '{:directive-defs {:auth {:args {:logFailure {:type Boolean
:default-value true}
:operationName {:default-value nil
:type String}
:roles {:default-value [:ADMIN :MANAGER]
:type (list :Role)}}
:locations #{:field-definition}}}
:enums {:Role {:values [{:enum-value :ADMIN}
{:enum-value :MANAGER}
{:enum-value :WORKER}
{:enum-value :GUEST}]}}}
(parse-string
"directive @auth (
roles: [Role] = [ADMIN, MANAGER]
logFailure: Boolean = true
operationName: String = null
) on FIELD_DEFINITION
enum Role { ADMIN, MANAGER, WORKER, GUEST }"))))

(deftest field-directive
(is (= '{:directive-defs
{:Trace
Expand Down Expand Up @@ -322,11 +344,17 @@
{:Animal
{:fields
{:name {:type (non-null String)}
:keyword {:type String
:default-value nil}
:weight {:type (non-null Int)}
:imperial {:type Boolean
:default-value false}
:category {:type String :default-value "feline"}}}}}
(parse-string "input Animal {
name: String!
keyword: String = null
weight: Int!
imperial: Boolean = false
category: String = \"feline\"
}"))))

Expand Down Expand Up @@ -387,12 +415,12 @@
:episodes {:type '(list :episode)}}
:implements [:Human]}
:MyQuery {:fields {:in_episode {:args {:episode {:type :episode
:default-value :NEWHOPE
:description "Episode for which to find characters"}}
:directives [{:directive-type :Trace}]
:resolve in-episode
:description "Find all characters for a given episode"
:type '(list :CharacterOutput)}}}
:default-value :NEWHOPE
:description "Episode for which to find characters"}}
:directives [{:directive-type :Trace}]
:resolve in-episode
:description "Find all characters for a given episode"
:type '(list :CharacterOutput)}}}
:OtherQuery {:fields {:find_by_names {:args {:names {:type '(non-null (list (non-null String)))}}
:resolve find-by-names
:type '(list :CharacterOutput)}}}
Expand Down Expand Up @@ -570,3 +598,4 @@
:members [:File
:Directory]}}}
schema))))

0 comments on commit 4f38697

Please sign in to comment.