Fork me on GitHub
#graphql
<
2018-06-25
>
blance04:06:11

how do you guys generally test your graphql server?

blance04:06:14

I have a graphql server which only has Query, and right now all it does is essentially translate graphql query string to sql query string, and run the query with very minimal transformation/computation in between.

blance04:06:37

i can only think of to populate the test db with some sample data, than run 1~2 query through api and verify it works as expected, but i feel like that's not testing much here.

blance04:06:20

my resolver function is pretty generic as well, one looks like:

(defn query-entities
  [{:keys [x-user-id db] :as context}
   {:keys [filter orderBy first skip] :as args}
   {:keys [uuid] :as value}]
  (let [constraints (merge filter
                           {:user-id x-user-id}
                           (when uuid
                             {:import-uuid uuid}))
        query-configs (select-keys args [:orderBy :first :skip])]
   (db/query-all-from-table db :entities query-configs)))

blance04:06:08

I don't think I can manually write all possible query and verify them, but I couldn't come up with a generative test for it either 😞

hlship16:06:09

Finally, please look into using io.aviso/pretty, as sometimes the details are hidden inside the ex-data, and pretty ensures that gets printed out.