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.

DataLoader used by `suspend` function fails to complete

See original GitHub issue

Library Version

1.4.2

Describe the bug

When I use a BatchLoader to resolve a property defined as a suspended function the request will complete maybe once or twice, and then subsequently fail to complete. The Dataloader body

If I define the property as a function that returns a CompletableFuture it returns successfully every time.

This may be expected behavior. If so I’d like to update the example code.

To Reproduce

  1. Check out the following branch https://github.com/rharriso/graphql-kotlin/tree/demostrate-batch-issue
  2. Run the spark example
  3. Request the suspended property multiple times:
query {
  searchCourses(params: { ids: [1,2,3] }) {
    university {
      id
      name
    }
  }
}
  1. See complete once or twice and fail afterwards.
  2. Query the property supplied by CompletableFuture
query {
  searchCourses(params: { ids: [1,2,3] }) {
    universityFuture {
      id
      name
    }
  }
}
  1. This query should always succeed.

Expected behavior

Not sure. If this is a bad usage of a batch loader I’d like to know.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

9reactions
DrMetalliuscommented, Jul 28, 2020

I don’t see the benefit of declaring using suspend functions with DataLoader as this just caches the response to be used at a later time.

The example provided by the original poster is contrived indeed, but the benefit here is simple: I get some result from another service through a loader, then I use it differently in different resolvers. Obviously, I don’t want to call said external server multiple times in the same query, that’s why I need some mechanism for batching and caching.

I can’t just move the logic from the resolvers into a data loader. I have one external service, but the result is used differently by different resolvers, so that would result in different data loaders thus defeating the purpose. The only way of making this work that I can see is by abandoning coroutines altogether and transforming the CompletableFuture from the data loader via thenApplyAsync or something similar. Obviously, this doesn’t exactly thrill me as it’s neither consistent, nor convenient.

1reaction
rharrisocommented, Apr 22, 2020

if DataLoader expects a CompletableFuture, you will have to return that. I don’t think there is a way for them to support co-routines since the library is implemented with Java/

My use-case makes a network request to another service over gRPC.

I’ll update the spark example to include asynchronous example.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common error messages in Data Loader - Salesforce Help
Here's a list of common Data Loader errors you'll receive as you use Data Loader to update or insert records. Resolution. Error: Row...
Read more >
DataLoaders Explained: Building a Multi-Process Data Loader ...
We now basically have a fully functional data loader; The only issue is that get() is loading in one element of dataset at...
Read more >
kotlin - Suspend function reference as parameter of let gets error
You can only call suspend functions from a coroutine or another suspend function. And let does not take a suspend function as a...
Read more >
How to Stop Users from Exporting Data from Salesforce
This post talks about how to customize Salesforce to either restrict or add friction to users exporting data from Salesforce.
Read more >
Salesforce data loader | Terms and Conditions | dataloader.io
Subject to the terms below, this Agreement permits Customer to use Dataloader.io ... product or copy any features, functions or graphics of Dataloader.io....
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