graphql

Rick Bradley 2020-07-21T00:30:54.238200Z

I'm ("we're") using lacinia, hodur, and pedestal hosting a graphql API, and we've been having a lot of success. Today I got stuck trying to get a search endpoint, using a union schema definition to work properly. I'm using tag-with-type on the individual returned results. If I just return one type of result, and set the schema to say (rather than the union) the return value is that one type, everything is fine. But, using the union, I get the "Field resolver returned an instance not tagged with a schema type." error back.

Rick Bradley 2020-07-21T00:32:28.240Z

I've dumped the hodur schema to lacinia format and it looks fine (to me) and I can provide snippets; and, while I've been test-driving this, I've also been hitting it with a graphql client just to make sure nothing in my local query generation would be the problem. I have debugging output which shows me that the tag-with-type tagging is actually showing up as metadata on the individual results. Kind of at a loss as to why, even with tagging, I'm getting the error.

Rick Bradley 2020-07-21T00:32:58.240400Z

Sample query:

query {
  searchAll(query: "search") {
    ... on Interaction {
      gid
    }
}

Rick Bradley 2020-07-21T00:33:35.240800Z

hodur schema bits:

^{:union true}
      SearchResults
      [Interaction Person Handle Group Stack PersonComment]      

QueryRoot
      [
       ^{:type SearchResults
         :cardinality [0 n]
         :lacinia/resolve :query/search-all}
       search-all [^String query]]

Rick Bradley 2020-07-21T00:35:08.241500Z

Which turns up like this in the lacinia schema:

:unions
 {:SearchResults
  {:members
   [:Group :Handle :Interaction :Person :PersonComment :Stack]}}

Rick Bradley 2020-07-21T00:35:36.241800Z

...
  :searchAll
  {:type (non-null (list (non-null :SearchResults))),
   :resolve :query/search-all,
   :args {:query {:type (non-null String)}}},

Rick Bradley 2020-07-21T00:37:09.242100Z

The tagging (debug output):

clojure.lang.PersistentVector
[^#:com.walmartlabs.lacinia.schema{:type-name :person} {:id 9, :name "Bobby Search User", :created_at #inst "2020-07-21T00:36:52.791467000-00:00", :updated_at #inst "2020-07-21T00:36:52.791467000-00:00", :user_id 5, :type "people"} ^#:com.walmartlabs.lacinia.schema{:type-name :group} {:description "Search Results Group", :name "test group", :type "groups", :updated_at #inst "2020-07-21T00:36:52.791467000-00:00", :parent_id nil, :id 3, :user_id 5, :position nil, :created_at #inst "2020-07-21T00:36:52.791467000-00:00"} ^#:com.walmartlabs.lacinia.schema{:type-name :group} {:description "Search Results Group 2", :name "test group 2", :type "groups", :updated_at #inst "2020-07-21T00:36:52.791467000-00:00", :parent_id nil, :id 4, :user_id 5, :position nil, :created_at #inst "2020-07-21T00:36:52.791467000-00:00"}]
{:data {:searchAll [nil nil nil]}, :errors [{:message "Field resolver returned an instance not tagged with a schema type.", :locations [{:line 1, :column 2}], :path [:searchAll], :extensions {:arguments {:query "search"}}}]}

Rick Bradley 2020-07-21T00:37:37.242600Z

Generated by this code:

(def-resolve ^:query/search-all
  search-all [{:keys [user]} args _]
  (let [results (db/search-all (:id user) (:query args))
        tagged (into [] (map (fn [record]
                               (schema/tag-with-type record (tag-for-record (:type record))))
                             results))
        _ (prn (type tagged))
        _ (binding [*print-meta* true]
            (prn tagged))]
    tagged))

Rick Bradley 2020-07-21T00:37:57.243Z

where tag-for-record just returns a key for a record type string

Rick Bradley 2020-07-21T00:42:37.243400Z

anyway, I'm cross-eyed from looking at this, just wondering if it rings any bells for anyone

Rick Bradley 2020-07-21T00:45:04.243900Z

(I also started with types like :Person in my tagging, with similar results)

jduhamel 2020-07-21T13:49:09.244900Z

Is there a good graphql client to use. I started with re-graph but got stumped quickly.

steveb8n 2020-07-27T00:58:35.256300Z

I dropped re-graph as well. too much magic. now I just use xhr/http client and use grafeo to generate the graphql

steveb8n 2020-07-27T00:59:27.256500Z

https://github.com/r0man/grafeo

gklijs 2020-07-27T05:50:44.256800Z

Thanks, grafeo looks neat. Currently in Clojurescript I just use strings and variables.

gklijs 2020-07-30T05:26:08.257700Z

Turns out ver 3 of GraphQL Kotlin has a client. Haven't looked at it, also don't know how easily it would be to wrap Kotlin in Clojure.

hlship 2020-07-21T16:41:34.246800Z

Are you using Lacinia at your company? If you are and can share that information, please DM me. I'm compiling a list of companies, and this may help give our team some leverage to devote a bit more time to developing Lacinia further.

hlship 2020-07-22T16:52:29.248400Z

Non-DM is fine too; it's common for developers to not be allowed to discuss specific technology choices publically.

gklijs 2020-07-21T17:22:44.247Z

Re-graph should work, but it's a bit low level maybe. There aren't any good clients on the JVM that I know of. There is the Appolo Android/Kotlin client. But that might do to much. For my current work we actually have about the some problem, and I know for Micronaut there is also a which. I might create a thin pure Java library at some point that could be used by others. It's not much that it needs to do.

đź‘Ť 1
vlaaad 2020-07-21T17:22:55.247200Z

no longer work there, but JobTech (aka Arbetsförmedlingen, Swedish Government's Employment Agency) uses Lacinia to provide GraphQL endpoint for it's taxonomy of terms related to job market (I implemented it — it was a nice experience, and it's open source: https://gitlab.com/team-batfish/jobtech-taxonomy-api/-/blob/develop/src/clj/jobtech_taxonomy_api/db/graphql.clj)

Rick Bradley 2020-07-21T19:12:50.247600Z

Yes, we're using lacinia at https://clickety.app/ it's been quite nice

Rick Bradley 2020-07-21T19:15:27.247900Z

(not exactly a DM I guess, but a thread is fine with me)