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

Fix templates and book to recommend Pathom setting for always returning :tempids #484

Closed
holyjak opened this issue Sep 2, 2021 · 11 comments · Fixed by fulcrologic/fulcro-rad#64

Comments

@holyjak
Copy link
Collaborator

holyjak commented Sep 2, 2021

Add :tempids to mutation join queries by default so that all users do not need to do that themselves (and '* if there was no query before to preserve Pathom's behavior of everything the whole mutation output if the user did not ask for anything in particular).

Add ::p/errors to all queries and mutations - most users of Fulcro use Pathom and need this and an extra keyword will not harm those who don't (and they can always remove it via a custom global transform).

Also expand the default elision list to RAD's (for the sake of simplicity, include also the *.rad.* ones, they are just keywords so do not create any dependency on RAD and will make its life easier).

Consequences

  • Many users likely do some of this in their global eql transforms. If they combine their with Fulcro, they might end up with these props twice in the query, but that should not harm anything, since we get back just a map, so no duplication there
  • Users will far less run into problems where tempid remapping does not work, b/c they used a mutation join and forgot to add :tempids
  • Users will get pathom errors back by default, which will make it easier to discover what went wrong with their query/mutation
@awkay
Copy link
Member

awkay commented Sep 2, 2021

This is close to what we want (if we expand the default exclusion list):

(defn global-eql-transform
  "Returns an EQL transform that removes `(pred k)` keywords from network requests."
  [pred]
  (fn [ast]
    (let [mutation?     (symbol? (:dispatch-key ast))
          has-children? (seq (:children ast))]
      (cond-> (-> ast
                (rad-app/elide-ast-nodes pred)
                (update :children conj (eql/expr->ast :com.wsscode.pathom.core/errors)))
        (and mutation? (not has-children?)) (update :children conj (eql/expr->ast '*))
        mutation? (update :children conj (eql/expr->ast :tempids))))))

holyjak added a commit to holyjak/fulcro that referenced this issue Sep 4, 2021
holyjak added a commit to holyjak/fulcro that referenced this issue Sep 4, 2021
holyjak added a commit to holyjak/fulcro that referenced this issue Sep 9, 2021
@holyjak
Copy link
Collaborator Author

holyjak commented Sep 10, 2021

Some questions, @awkay, to determine whether adding ::p/errors anywhere to transactions with mutations is meaningful or not - because it seems that errors of a mutation itself is returned as {<mutation-symbol> {::p/reader-error "some text"}}.

  1. Is it so that a "query" and a mutation is never combined in a single transaction / request to pathom, i.e. if the transaction contains a mutation, there are never any non-mutation top-level joins or properties - something like [:x {:y [:z]} (mutation)] will never happen and thus adding ::p/errors to the top level is pointless?
    (though in RAD there is perhaps <mutation symbol> :com.fulcrologic.rad.pathom/errors?)
  2. Since mutation errors are returned as reader errors and are returned by default, we do not need to add anything to the transaction to get them in Fulcro

(For mutations, we could perhaps offer a function you can hook into the app's :remote-error? that would mark mutation reader-errors as errors so that they would appear in the component's ::m/mutation-error, as produced by the default result action?)

@awkay
Copy link
Member

awkay commented Sep 10, 2021

Honestly I do not remember/know.

In terms of what needs to be in the query: remember that if there is a mutation join that Fulcro uses that for merge as well, so if the key is not in the outgoing query Fulcro itself will filter it.

To be honest I'm torn on how much pathom-specific stuff to include, since that is an external lib that is in the process of changing how it works. I'd probably tend to leave the pathom-specific keys out altogether and document that you might want to customize that part for your app.

@holyjak
Copy link
Collaborator Author

holyjak commented Sep 11, 2021

No need for :tempids in mutation queries?!

According to my experiment, we do not need to add :tempids to mutations:

  1. If the mutation has no query then Pathom simply returns everything by default, thus including :tempids
  2. Even If I add a query via m/returning - and the server-seen query becomes [{(com.example.mutations/create-random-thing {:tmpid #fulcro/tempid["1b59713c-305c-4b8d-802d-7b39b8a4e696"]}) [:fake :com.wsscode.pathom.core/errors]}] - still tempids are returned to Fulcro

(Pathom 2.3.1, Fulcro 3.5.2)

@awkay
Copy link
Member

awkay commented Sep 11, 2021

Hm. I have seen this mess up in RAD, so I know it doesn't work through the stack. It could be that Fulcro's the one filtering the tempids? Does the remap work in case (2)?

@holyjak
Copy link
Collaborator Author

holyjak commented Sep 12, 2021 via email

@holyjak
Copy link
Collaborator Author

holyjak commented Sep 12, 2021

Confirmed that in RAD Demo I need to add :tempids to mutation joins otherwise tempids are not returned by Pathom. Need to explore.

@holyjak
Copy link
Collaborator Author

holyjak commented Sep 12, 2021

Oh, I see why getting back tempids worked in my first test. I had this in my parser config:

{::p/env {::pc/mutation-join-globals [:tempids], ...}}

@awkay wouldn't adding the Pathom config ☝️ be a simpler solution than modifying the global-eql-transform in Fulcro? It would require more work from the user, namely to copy a "recommended" Pathom setup - but I expect that most users do that anyway? But it seems that neither fulcro-template nor fulcro-rad-demo do this for some reason?

Above you wrote

if there is a mutation join that Fulcro uses that for merge as well, so if the key is not in the outgoing query Fulcro itself will filter it

Does that mean that is :tempids is not in the outgoing Fulcro query then Fulcro will ignore it, even if it is in the incoming data? But that is not congruent with my experiements so maybe tempids is special, compared to any other query property?

You also wrote

I'd probably tend to leave the pathom-specific keys out altogether and document that you might want to customize that part for your app.

I guess it means you would after all prever not including ::p/errors in the query, is that correct? If that is the case - what about using a general, Fulcro specific key, such as com.fulcrologic.fulcro.networking.[http-?]remote/errors, and expecting that the Fulcro server-side glue (or the remote implementation) remaps that to whatever the particular kind of remote uses? So in the case of Pathom, it would be some fulcro-integration-plugin that would move ::p/errors from the result into this key on the way out?

@awkay
Copy link
Member

awkay commented Sep 12, 2021

Yes, I was not aware of this option in Pathom. It would be better to just recommend that and fix the templates.

In terms of the errors: Fulcro does not require Pathom, and how you deal with errors on Pathom is also pretty configurable. I'm fine with setting up the templates to glue together error handling in some "useful" manner but given that Pathom 3 might even change this key I really don't want to chase Pathom on this in Fulcro's code.

@holyjak
Copy link
Collaborator Author

holyjak commented Sep 13, 2021

Then I guess we should close this issue as "won't fix"?

@awkay awkay changed the title Automatically add :tempids to mutation queries and ::p/errors to all Fix templates and book to recommend Pathom setting for always returning :tempids Sep 13, 2021
@awkay
Copy link
Member

awkay commented Sep 13, 2021

Yeah, let's open up the templates and fix them, and also document it in the tempids section of the book. Let's just track it with this issue, since all the history is here.

holyjak added a commit to holyjak/fulcro-template that referenced this issue Sep 15, 2021
Fix fulcrologic/fulcro#484 for fulcro-template

Now even if mutation has a mut. join that does not specify `:tempids`,
these will be returned anyway.
holyjak added a commit to holyjak/fulcro-rad that referenced this issue Sep 15, 2021
Instead of manually adding :tempids to mutations on the client side,
we can leverage Pathom's config to do it automatically on the server
side.

Fixes fulcrologic/fulcro#484 for RAD.
holyjak added a commit to holyjak/fulcro-developer-guide that referenced this issue Sep 15, 2021
awkay pushed a commit to fulcrologic/fulcro-rad that referenced this issue Sep 15, 2021
Instead of manually adding :tempids to mutations on the client side,
we can leverage Pathom's config to do it automatically on the server
side.

Fixes fulcrologic/fulcro#484 for RAD.
holyjak added a commit to holyjak/fulcro-template that referenced this issue Sep 17, 2021
...in the same way as fulcro-rad does, so that it is easier
to get hold of these e.g. inside `remote-error?`

Related to fulcrologic/fulcro#484
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants