Skip to content

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
1e16miin committed Aug 22, 2024
1 parent a25afd8 commit 98b0c93
Showing 1 changed file with 58 additions and 5 deletions.
63 changes: 58 additions & 5 deletions test/com/walmartlabs/lacinia/complexity_analysis_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

(ns com.walmartlabs.lacinia.complexity-analysis-test
(:require
[clojure.test :refer [deftest is run-test]]
[clojure.test :refer [deftest is run-test testing]]
[com.walmartlabs.lacinia :refer [execute]]
[com.walmartlabs.test-utils :as utils]))

Expand Down Expand Up @@ -56,8 +56,10 @@
(utils/simplify (execute schema query variables nil {:max-complexity 10})))

(deftest over-complexity-analysis
(is (= {:errors {:message "Over max complexity! Current number of resources to be queried: 22"}}
(q "query ProductDetail($productId: ID){
(testing "It is possible to calculate the complexity of a query in the Relay connection spec
by taking into account both named fragments and inline fragments."
(is (= {:errors {:message "Over max complexity! Current number of resources to be queried: 27"}}
(q "query ProductDetail($productId: ID){
node(id: $productId) {
... on Product {
...ProductLikersFragment
Expand All @@ -75,6 +77,9 @@
edges{
node{
id
author{
id
}
}
}
}
Expand All @@ -85,11 +90,59 @@
likers(first: 10){
edges{
node{
id
... on Seller{
id
}
... on Buyer{
id
}
}
}
}
}" {:productId "1"}))))
}" {:productId "id"}))))
(testing "If no arguments are passed in the query, the calculation uses the default value defined in the schema."
(is (= {:errors {:message "Over max complexity! Current number of resources to be queried: 22"}}
(q "query ProductDetail($productId: ID){
node(id: $productId) {
... on Product {
...ProductLikersFragment
seller{
id
products(first: 5){
edges{
node{
id
}
}
}
}
reviews(first: 5){
edges{
node{
id
author{
id
}
}
}
}
}
}
}
fragment ProductLikersFragment on Product {
likers{
edges{
node{
... on Seller{
id
}
... on Buyer{
id
}
}
}
}
}" {:productId "id"})))))

(comment
(run-test over-complexity-analysis))

0 comments on commit 98b0c93

Please sign in to comment.