Queries

Queries are responsible for generating the initial resolved values that will be picked apart to form the result map.

Other than that, queries are just the same as any other field. Queries have a type, and accept arguments.

Queries are defined as the fields of a special object, Query object.

{:objects
 {:Query
  {:fields
   {:hero
    {:type (non-null :Character)
     :args {:episode {:type :episode}}}

    :human
    {:type (non-null :Human)
     :args {:id {:type String
                 :default-value "1001"}}}}}}}

The field resolver for a query is passed nil as the the value (the third parameter). Outside of this, the query field resolver is the same as any field resolver anywhere else in the schema.

In the GraphQL specification, it is noted that queries are idempotent; if the query document includes multiple queries, they are allowed to execute in parallel.

:queries key

The above is the “modern” way to define queries; an older approach is still supported. Queries may instead be defined using the :queries key of the schema.

{:queries
 {:hero
  {:type (non-null :Character)
   :args {:episode {:type :episode}}}

  :human
  {:type (non-null Hhuman)
   :args {:id {:type String
               :default-value "1001"}}}}}