Fork me on GitHub
#graphql
<
2019-08-08
>
subsaharancoder22:08:26

I need some help with lacinia, i'm trying to return a list of objects using a query that has no params:

:drivers
 [{:id "1"
   :name "Tom Smith"
   :email ""}
  {:id "2"
   :name "Billy Blanks"
   :email ""}
  {:id "3"
   :name "Peter Pan"
   :email ""}
  {:id "4"
   :name "Greg Abott"
   :email ""}
  {:id "5"
   :name "Jill Tray"
   :email ""}
  {:id "6"
   :name "Mary Miles"
   :email ""}]
`

subsaharancoder22:08:54

My query:

:all_drivers
  {:type        (list :Driver)
   :description "Get all the drivers"
   :resolve     :query/all-drivers}
  }
and the resolver:
(defn resolver-map
  [component]
  (let [trips-data (-> (io/resource "trips-data.edn")
                       slurp
                       edn/read-string)
        trips-map (entity-map trips-data :trips)
        cars-map (entity-map trips-data :cars)
        drivers-map (entity-map trips-data :drivers)]
    {:query/trip-by-id (partial resolve-trip-by-id trips-map)
     :query/drivers-by-id (partial resolve-drivers-by-id drivers-map)
     :query/all-drivers resolve-all-drivers drivers-map
     :Trip/cars (partial resolve-trip-cars cars-map)
     :Car/trips (partial resolve-car-trips trips-map)}))

(defn resolve-all-drivers
  [drivers-map context args value]
  drivers-map)

subsaharancoder22:08:43

Calling all_drivers gives me this error:

{
  "data": {
    "all_drivers": null
  },
  "errors": [
    {
      "message": "Field resolver returned a single value, expected a collection of values.",
      "locations": [
        {
          "line": 31,
          "column": 3
        }
      ],
      "path": [
        "all_drivers"
      ]
    }
  ]
}
any idea what's going on?

subsaharancoder23:08:11

figured this out ' drivers-map (get trips-data :drivers)`

subsaharancoder23:08:16

drivers-map (get trips-data :drivers)