graphql

subsaharancoder 2019-08-08T22:40:26.017200Z

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 "<mailto:tom@google.com|tom@google.com>"}
  {:id "2"
   :name "Billy Blanks"
   :email "<mailto:bill@email.com|bill@email.com>"}
  {:id "3"
   :name "Peter Pan"
   :email "<mailto:peterpan@yahoo.com|peterpan@yahoo.com>"}
  {:id "4"
   :name "Greg Abott"
   :email "<mailto:gregabott@gmail.com|gregabott@gmail.com>"}
  {:id "5"
   :name "Jill Tray"
   :email "<mailto:jilltray@gmail.com|jilltray@gmail.com>"}
  {:id "6"
   :name "Mary Miles"
   :email "<mailto:mmiles@uber.com|mmiles@uber.com>"}]
`

subsaharancoder 2019-08-08T22:41:54.018Z

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 (-&gt; (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)

subsaharancoder 2019-08-08T22:48:43.018700Z

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?

subsaharancoder 2019-08-08T23:33:11.019Z

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

subsaharancoder 2019-08-08T23:33:16.019200Z

drivers-map (get trips-data :drivers)