ribelo / doxa

The Unlicense
232 stars 8 forks source link

pull expressions using :__typename don't work #7

Closed stevebuik closed 3 years ago

stevebuik commented 3 years ago

because Doxa considers :_ to be a reverse ref read, it stops graphql results from working out of the box.

All graphql entities have a :__typename field so this is pervasive.

My workaround is simple enough:

  1. transform the pull or query before execution
  2. transform the results after execution
(defn read-enter
  [read-or-query]
  (walk/prewalk (fn [v]
                  (if (= :__typename v)
                    :gql-type
                    v))
                read-or-query))

(defn read-leave
  [result]
  (walk/prewalk (fn [v]
                  (if (= :gql-type v)
                    :__typename
                    v))
                result))

This is like an interceptor.

Is there a way to provide support for :_foo attributes?

If not, I wonder if adding interceptors to this lib with some included examples like a graphql transform might be a solution?

Or other solutions?

ribelo commented 3 years ago

Could you check that it really works? I've never used graphql and don't know if this is what it was about

stevebuik commented 3 years ago

I have tested and confirmed the fix. If you want to add a test for this, you can use this:

(let [entity-id "6037b7a5-5a77-48a3-a294-8dba786d8e9d"
        gql-entity {:__typename "release"
                    :id         entity-id
                    :created    "2021-05-10T09:39:28"
                    :release/id entity-id} 
        db (dx/commit (dx/create-dx) [[:dx/put gql-entity]])]
    (dx/pull db [:__typename :created] [:release/id entity-id]))