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.
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.
Sample query:
query {
searchAll(query: "search") {
... on Interaction {
gid
}
}
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]]
Which turns up like this in the lacinia schema:
:unions
{:SearchResults
{:members
[:Group :Handle :Interaction :Person :PersonComment :Stack]}}
...
:searchAll
{:type (non-null (list (non-null :SearchResults))),
:resolve :query/search-all,
:args {:query {:type (non-null String)}}},
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"}}}]}
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))
where tag-for-record
just returns a key for a record type string
anyway, I'm cross-eyed from looking at this, just wondering if it rings any bells for anyone
(I also started with types like :Person
in my tagging, with similar results)
Is there a good graphql client to use. I started with re-graph but got stumped quickly.
I dropped re-graph as well. too much magic. now I just use xhr/http client and use grafeo to generate the graphql
Thanks, grafeo looks neat. Currently in Clojurescript I just use strings and variables.
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.
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.
Non-DM is fine too; it's common for developers to not be allowed to discuss specific technology choices publically.
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.
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)
Yes, we're using lacinia at https://clickety.app/ it's been quite nice
(not exactly a DM I guess, but a thread is fine with me)