Fork me on GitHub
#graphql
<
2020-07-21
>
Rick Bradley00:07:54

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 Bradley00:07:28

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 Bradley00:07:58

Sample query:

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

Rick Bradley00:07:35

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 Bradley00:07:08

Which turns up like this in the lacinia schema:

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

Rick Bradley00:07:36

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

Rick Bradley00:07:09

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 Bradley00:07:37

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 Bradley00:07:57

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

Rick Bradley00:07:37

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

Rick Bradley00:07:04

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

jduhamel13:07:09

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

gklijs17:07:44

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.

đź‘Ť 3
steveb8n00:07:35

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

gklijs05:07:44

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

gklijs05:07:08

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.

hlship16:07:34

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.

vlaaad17:07:55

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 Bradley19:07:50

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

Rick Bradley19:07:27

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

vlaaad06:07:07

haha, sorry, didn’t notice it asked for DMs

hlship16:07:29

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