Skip to content

Conversation

@lukemurray
Copy link
Collaborator

Still some testing to do but the idea is

  • let async things happen (don't force GetAwaiter())
  • clean things up at the end of it all

@lukemurray
Copy link
Collaborator Author

New changes

  • Move to a ResolveAsync<> method

The ResolveAsync method allows you to define fields that execute asynchronously using injected services:

var schema = SchemaBuilder.FromObject<MyContext>();

schema.Type<Person>()
    .AddField("weather", "Current weather for this person's location")
    .ResolveAsync<WeatherService>((person, weatherService) =>
        weatherService.GetWeatherAsync(person.Location));
  • Introduce a way to control the concurrency within the query

EntityGraphQL provides three levels of concurrency control to help you manage resource usage and prevent overwhelming external services.

All concurrency limits apply only to the currently executing query.

Field-Level Concurrency

Limit concurrency for individual fields:

schema.Type<Person>()
    .AddField("expensiveOperation", "Resource-intensive operation")
    .ResolveAsync<ExpensiveService>((person, service) =>
        service.DoExpensiveWorkAsync(person.Id),
        maxConcurrency: 5); // Only 5 concurrent operations for this field

Service-Level Concurrency

Configure concurrency limits for entire services across all fields that use them:

var executionOptions = new ExecutionOptions
{
    ServiceConcurrencyLimits = new Dictionary<Type, int>
    {
        [typeof(WeatherService)] = 10,  // Max 10 concurrent weather calls
        [typeof(DatabaseService)] = 3,  // Max 3 concurrent database operations
        [typeof(EmailService)] = 2      // Max 2 concurrent email sends
    }
};

var result = await schema.ExecuteRequestAsync(query, context, serviceProvider, executionOptions);

Query-Level Concurrency

Set a global limit for all async operations in a single query:

var executionOptions = new ExecutionOptions
{
    MaxQueryConcurrency = 20  // Maximum 20 concurrent operations across entire query
};

var result = await schema.ExecuteRequestAsync(query, context, serviceProvider, executionOptions);

Hierarchical Concurrency Control

EntityGraphQL applies concurrency limits hierarchically - each level respects the limits above it:

  1. Query Level: Global limit for the entire query
  2. Service Level: Limit per service type
  3. Field Level: Limit per individual field

For example, with these settings:

  • Query limit: 50
  • WeatherService limit: 10
  • Field limit: 3

The field will never exceed 3 concurrent operations, the WeatherService will never exceed 10 concurrent operations, and the entire query will never exceed 50 concurrent operations.

@lukemurray lukemurray merged commit 7d457ef into master Aug 23, 2025
1 check passed
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

Successfully merging this pull request may close these issues.

3 participants