question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

running "afterware"

See original GitHub issue

With combine we can add handlers to run before the main resolver. Useful for authentication checks and such.

I think it would be nice if we could also run some handlers after the main resolver. Think about credit transactions.

combineResolvers(reserveFunds, performAction, chargeFunds)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
smeijercommented, Jun 4, 2019

@lucasconstantino, I’m aware of batching, but it’s not the holy grail either. It doesn’t combine requests from multiple child resolvers

query {
  blog(id: "x") {
    author {
      name
    }
    publisher {
      name
    }
  }
}

When authorId and publisherId are not equal, this will still hit the database three times. While we could optimize it, by fetching in the blog resolver:

  Query: {
    blog: async (_, { id }, { db }) => {
      const blog = await db.blogs.findOne({ _id: id });

      const users = await db.users.find(
        { _id: { $in: [blog.authorId, blog.publisherId] }}
      ).toArray();

      blog.author = users.find(x => x._id === blog.authorId);
      blog.publisher = users.find(x => x._id === blog.publisherId);

      return blog;
    }
  }

This is an oversimplified example of course, and in this specific case, I even might recommend against it. But taking the blog’s code from before:

query {
  blogs(first: 100) {
    author {
      name
    }
  }
}

If the first 100 blogs are made by 100 different authors. This would still result in 101 queries hitting the database. Even when using dataloader with it’s batching implementation. Unless I missed something huge in dataloader, it only protects you from requesting duplicate id’s. So when there are 25 different authors in this first 100 blogs, the database will only be hit 26 times. While we could reduce the count to 2 hits when we would iterate over the blogs our selves.

0reactions
lucasconstantinocommented, Jun 2, 2019

@smeijer I honestly forgot to answer you back then. Facebook’s data-loader not only facilitates caching, but batching. You should have a deeper look at that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Batched network interface runs middleware and afterware ...
'Afterware' is very similar to a middleware, except that a afterware runs after a request has been made, that is when a response...
Read more >
Running a Marathon? Think Hot Tub, Not Ice Bath, Afterward
Muscles recover better after exhausting exercise if they are warmed than if they are chilled, a new study finds.
Read more >
How To Warm Up For A Run And Cool Down Afterwards | Coach
Avoid injury and get the most out of your runs with these brief pre and post-run routines.
Read more >
Why I run: 'It's painful and boring. Afterwards, you're fully alive'
Running is chafingly painful, repetitive, booorrring. It is also the best source of natural serotonin. Afterwards, once you've recovered ...
Read more >
Aftercare - Pentz Run Family Servicess - DuBois, PA
Aftercare... Mobile Case Management Program. Aftercare services are available to residents and their families, upon the resident's discharge from Pentz Run.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found