retro / graphql-builder

GraphQL client library for Clojure and ClojureScript
MIT License
184 stars 15 forks source link

Query Boolean variables, default false value is dropped. #29

Closed tommi-martin closed 1 year ago

tommi-martin commented 1 year ago

Required default false values are dropped from graphql queries. Breaking directives in graphql.

Steps to repeat:

  1. Create a file getPostCollection.graphql
  2. add the following content to the query
    query postCollectionQuery(
    $list: Boolean = false
    ) {
    postCollection {
    items {
      content @skip(if: $list) {
        json
      }
      shortDescription @include(if: $list) {
        json
      } 
    }
    }
    }
  3. Evaluate the following expressions:
    
    (ns sample
    (:require
    [graphql-builder.parser :refer [defgraphql]]
    [graphql-builder.core :as graphql-core]))

(defgraphql graphql-query "getPostCollection.graphql") (def single-query (graphql-core/query-map graphql-query)) (:query (:graphql ((get-in single-query [:query :post-collection-query]))))


**Expected result:**

query postCollectionQuery( $list: Boolean = false ) { postCollection { items { content @skip(if: $list) { json } shortDescription @include(if: $list) { json } } } }


**Actual result**

query postCollectionQuery(

NOTE the missing default value breaking the directives below.

$list: Boolean ) { postCollection { items { content @skip(if: $list) { json } shortDescription @include(if: $list) { json } } } }


When this query is pushed to contentful for example the result is a 503 as the query validator does not explicitly report this problem back to the graphql client.
retro commented 1 year ago

@tommi-martin 0.1.15 is released with the fix