Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@oneOf 시범 구현 #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions dev-resources/input-object-one-of-schema.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{:Query
{:fields
{:user {:type :User,
:args {:by {:type (non-null :UserByInput)}}
:resolve :queries/user}}},

:input-objects
{:UserByInput
{:fields {:id {:type ID},
:email {:type String}},
:directives [{:directive-type :oneOf}]}}}
45 changes: 44 additions & 1 deletion test/com/walmartlabs/lacinia/input_types_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
; limitations under the License.

(ns com.walmartlabs.lacinia.input-types-test
(:require [clojure.test :refer [deftest is]]
(:require [clojure.test :refer [deftest is testing]]
[com.walmartlabs.test-utils :refer [execute compile-schema-injected]]))

(deftest mix-of-literals-and-dynamics
Expand All @@ -38,4 +38,47 @@
{:nodes [{:color "blue"}]}}}
(execute schema query args nil)))))

(deftest one-of-input-object
(let [resolver (fn [_ args _]
;; TODO: arguments validation
{})
schema (compile-schema-injected "input-object-one-of-schema.edn"
{:queries/user resolver})]
(testing "provide exactly one of the fields"
(let [query "{
tom: user(by: {
id: 1
}) {
name
}

jerry: user(by: {
email: \"[email protected]\"
}) {
name
}
}"
args {}]
(is (= {:data
{:tom {:name "Tom"}
:jerry {:name "Jerry"}}}
(execute schema query args nil)))))
(testing "provide two values"
(let [query "{
user(by: {
id: 1
email: \"[email protected]\"
}) {
name
}
}"
args {}]
(is (= {:data
{:cars
{:nodes [{:color "blue"}]}}}
(execute schema query args nil)))))))


(comment
(require 'com.walmartlabs.lacinia.parser.schema)
)
Loading