Skip to content

Commit

Permalink
Add support for @deprecated directives on input fields
Browse files Browse the repository at this point in the history
While the @deprecated annotation is suported for enum values and type
fields, it was not supported for input field definitions, where a
@deprecated annotation may also be applied.
  • Loading branch information
sundbry committed Apr 19, 2023
1 parent 4f44b07 commit afa9c04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/com/walmartlabs/lacinia/schema.clj
Original file line number Diff line number Diff line change
Expand Up @@ -1878,7 +1878,7 @@
(map-kvs compile-directive-args
(assoc directive-defs
:deprecated {:args {:reason {:type 'String}}
:locations #{:field-definition :enum-value}})))))
:locations #{:enum-value :field-definition :input-field-definition}})))))

(defn ^:private validate-directives-by-category
[schema category]
Expand Down
18 changes: 16 additions & 2 deletions test/com/walmartlabs/lacinia/directives_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@
(directive-test
"Directive @deprecated on union `Ebb' is not applicable."
{:allowed-locations #{:enum-value
:field-definition}
:field-definition
:input-field-definition}
:directive-type :deprecated
:union :Ebb}
{:objects
Expand All @@ -375,7 +376,8 @@
(directive-test
"Directive @deprecated on scalar `Ebb' is not applicable."
{:allowed-locations #{:enum-value
:field-definition}
:field-definition
:input-field-definition}
:directive-type :deprecated
:scalar :Ebb}
{:scalars
Expand Down Expand Up @@ -493,6 +495,18 @@
(is (= true
(get-in schema [:Account :fields :id :deprecated])))))

(deftest can-deprecate-input-fields
(let [schema (schema/compile
{:input-objects
{:Character
{:description "A character"
:fields {:name {:type '(non-null String)
:description "Character name"}
:weapon {:type '(non-null String)
:directives [{:directive-type :deprecated}]
:description "Weapon of choice"}}}}})]
;; Exception is not thrown
(is (any? schema))))

(deftest can-deprecate-enum-values
(let [schema (schema/compile
Expand Down

0 comments on commit afa9c04

Please sign in to comment.