Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide a ::pc/mutation-data in mutation context #148

Open
souenzzo opened this issue Mar 24, 2020 · 1 comment
Open

Provide a ::pc/mutation-data in mutation context #148

souenzzo opened this issue Mar 24, 2020 · 1 comment

Comments

@souenzzo
Copy link
Contributor

In resolver context, pathom provide a pc/resolver-data that contains all "metadata" from resolver

This feature isn't present in mutation.

(let [register [(pc/mutation `mutation
                             {::pc/output [::mutation]}
                             (fn [env params]
                               {::mutation (-> env ::pc/mutation-data)}))
                (pc/resolver `resolver
                             {::pc/output [::resolver]}
                             (fn [env params]
                               {::resolver (-> env ::pc/resolver-data)}))]
      parser (p/parser {::p/plugins [(pc/connect-plugin {::pc/register register})]
                        ::p/mutate  pc/mutate})
      env {::p/reader [p/map-reader
                       pc/reader2
                       pc/open-ident-reader]}]
  (parser env
          `[{(mutation {})
             [::resolver
              ::mutation]}]))
=>
{user/mutation {:user/resolver {:com.wsscode.pathom.connect/sym user/resolver,
                                :com.wsscode.pathom.connect/input #{},
                                :com.wsscode.pathom.connect/resolve #object[user$eval21712$fn__21715
                                                                            0x700e1383
                                                                            "user$eval21712$fn__21715@700e1383"],
                                :com.wsscode.pathom.connect/output [:user/resolver]},
               ;; expected: {::pc/sym user/mutation ....}
               ;; actual:
                :user/mutation nil}}
@souenzzo
Copy link
Contributor Author

souenzzo commented Mar 24, 2020

in here
https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/connect.cljc#L1508
and
https://github.com/wilkerlucio/pathom/blob/master/src/com/wsscode/pathom/connect.cljc#L1530

  (if-let [{::keys [sym] :as mutation-data} (get-in indexes [::index-mutations sym'])]
    (let [env (-> env 
                 (assoc-in [:ast :key] sym)
                 (assoc ::pc/mutation-data mutation-data))]

Consider mutation-data helper function (line 124 ATM)

test

(is (every? number? (for [[mutate parser-gen] [[pc/mutate p/parser]
                                               [pc/mutate-async p/parallel-parser]]]
                      (let [register [(pc/mutation `mutation
                                                   {::my-var 42}
                                                   (fn [env params]
                                                     {::mutation (-> env ::pc/mutation-data))}))]
                            parser (parser-gen {::p/plugins [(pc/connect-plugin {::pc/register register})]
                                                ::p/mutate  mutate})]
                        (-> (parser {} `[(mutation)])
                            (wasync/<!!maybe)
                            (get-in [`mutation ::mutation ::my-var]))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant