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

Graphql replication async modifier function #2367

Closed
zefman opened this issue Jul 20, 2020 · 2 comments
Closed

Graphql replication async modifier function #2367

zefman opened this issue Jul 20, 2020 · 2 comments

Comments

@zefman
Copy link
Contributor

zefman commented Jul 20, 2020

Case

REQUEST FOR A NEW FEATURE

Issue

I would like to be able to use an async function when modifying the document before or after the graphql replication happens. RXDB already provides a modifier function as part of the push and pull config, but I am not able to perform asynchronous code within it.

In my app I have two related models, a Submission and Submission Globals, these are both reflected as collections in RxDB. I want the push replication I have set up for Submissions to also create it's related Submission globals at the same time. I want my modifier function to look something like this:

push: {
        queryBuilder: pushQueryBuilder,
        modifier: async (doc: Submission) => {
         const submissionGlobals = await db.submissionGlobals.find()
                .where('submissionId')
                .eq(doc.id)
                .exec()
                .then((items) => items.map(item => item.toJSON()));

          return {
            ...doc,
           submissionGlobals
          };
        },
     },

I have created the modifications required but thought its best to discuss here first before making a PR. https://github.com/zefman/rxdb/tree/feat/graphql-replication-async-modifier

Is there any reason this is a bad idea? If you think this is a suitable request I will open a PR. Thanks

Info

  • Environment: All
  • Adapter: All
  • Stack: All
@pubkey
Copy link
Owner

pubkey commented Jul 20, 2020

I do not see any reason why this is a bad idea. The http-request in the end is async anyway so having an async modifier should work too.
Yes please make a PR.

@pubkey
Copy link
Owner

pubkey commented Jul 22, 2020

Solved with #2369

@pubkey pubkey closed this as completed Jul 22, 2020
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

2 participants