Skip to content

Commit

Permalink
Merge pull request #339 from walmartlabs/20201012-directive-scalar
Browse files Browse the repository at this point in the history
Allow directive arguments to be enums or input objects as well as scalara
  • Loading branch information
hlship committed Oct 12, 2020
2 parents a0587dc + 509b6eb commit 93dbae9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/com/walmartlabs/lacinia/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1515,8 +1515,8 @@
{:arg-name arg-name
:arg-type-name arg-type-name
:schema-types (type-map schema)})))
(when-not (= :scalar (:category arg-type))
(throw (ex-info "Directive argument is not a scalar type."
(when-not (#{:enum :scalar :input-object} (:category arg-type))
(throw (ex-info "Directive argument is not a scalar, enum, or input object type."
{:arg-name arg-name
:arg-type-name arg-type-name
:schema-types (type-map schema)})))
Expand Down
16 changes: 15 additions & 1 deletion test/com/walmartlabs/lacinia/directives_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,20 @@
[expected-msg expected-ex-data schema]
`(expect-exception ~expected-msg ~expected-ex-data (schema/compile ~schema)))

(deftest scalars-allowed-for-directive-args
(schema/compile
'{: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}]}}}))

(deftest unknown-argument-type-for-directive
(directive-test
"Unknown argument type."
Expand All @@ -242,7 +256,7 @@

(deftest incorrect-argument-type-for-directive
(directive-test
"Directive argument is not a scalar type."
"Directive argument is not a scalar, enum, or input object type."
{:arg-name :user
:arg-type-name :User
:schema-types {:object [:Mutation
Expand Down

0 comments on commit 93dbae9

Please sign in to comment.