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

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

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 17 (15 by maintainers)

Most upvoted comments

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.

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