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.

Cosmos IQueryable throws "LINQ query please set allowSynchronousQueryExecution true or use GetItemQueryIterator to execute asynchronously"

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Product

Hot Chocolate

Describe the bug

When returning a Cosmos Linq Queryable, HotChocolate throws because it appears to be attempting to access the IQueryable synchronously (rather than async)

[UseFiltering]
public IQueryable<MyModel> GetPartner() =>
    MyContainer.GetItemLinqQueryable<MyModel>();

Steps to reproduce

  1. Connect your program to a cosmos database
  2. Return a queryable ala MyContainer.GetItemLinqQueryable<MyModel>()
  3. Exception happens when accessing that node

Relevant log output

GraphQL service exception for 'POST /graphql/UnknownOperation - 662a00b5500da5b6c5c6a01ee7142acd': To execute LINQ query please set allowSynchronousQueryExecution true or use GetItemQueryIterator to execute asynchronously
      System.NotSupportedException: To execute LINQ query please set allowSynchronousQueryExecution true or use GetItemQueryIterator to execute asynchronously
         at Microsoft.Azure.Cosmos.Linq.CosmosLinqQuery`1.GetEnumerator()+MoveNext()
         at HotChocolate.Execution.Processing.Tasks.ResolverTask.<>c__DisplayClass50_0.<ExecuteResolverPipelineAsync>b__0()
         at System.Threading.Tasks.Task`1.InnerInvoke()
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
      --- End of stack trace from previous location ---
         at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
      --- End of stack trace from previous location ---
         at HotChocolate.Execution.Processing.Tasks.ResolverTask.ExecuteResolverPipelineAsync(CancellationToken cancellationToken)
         at HotChocolate.Execution.Processing.Tasks.ResolverTask.TryExecuteAsync(CancellationToken cancellationToken)

Additional Context?

HC should try to load data from the IQuerayble asynchronously rather than synchronously

Version

13.0.5

Blockers to having a nice repository for searching/paging/filtering for Cosmos and HotChocolate

Issue Analytics

  • State:open
  • Created 6 months ago
  • Comments:16 (14 by maintainers)

github_iconTop GitHub Comments

1reaction
Arcalise08commented, Jul 14, 2023

I’m new to this library and also very much invested in CosmosDB. Can anyone tell me if this is a bad approach to fixing the OPs error

    [UseFiltering]
    public async Task<IEnumerable<Users>?> GetUsers([FromServices] Container<Users> users, IResolverContext resolverContext)
    {
        var query = container
            .GetItemLinqQueryable<Users>()
            .Filter(resolverContext)
            .ToFeedIterator();
        var list = new List<Users>();
        while (query.HasMoreResults)
        { 
            var response = await query.ReadNextAsync();
            foreach (var item in response)
            {
                list.Add(item);
            }
        }
        return list;
    }

It does work without the allowSynchronousQueryExecution set to true.

1reaction
michaelstaibcommented, Mar 20, 2023

We have a standard template for this. I can post you later a pr that shows how such a driver is implemented.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to do run LINQ Count on a Cosmos-db query ...
I have an existing Cosmos-db SDK V3 query in my C# code and I can run the Count method on it if "...
Read more >
Container.GetItemLinqQueryable<T> Method
This method creates a LINQ query for items under a container in an Azure Cosmos DB service. IQueryable extension method ToFeedIterator() should be...
Read more >
LINQ to NoSQL translation - Azure Cosmos DB
Learn the LINQ operators supported and how the LINQ queries are mapped to ... shows LINQ query generation and asynchronous execution with a...
Read more >
Query Document using LINQ on Azure Cosmos DB
Either you query XML or File or Object you always write a same program. You can create an IQueryable object that directly queries...
Read more >
Using LINQ to Query Dynamic Schema-less Cosmos DB ...
On July 9, 2019, a new set of libraries for working with Azure services was announced. These SDKs target multiple languages including Python, ......
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