Make worker_limit configurable at runtime (startup and per-request) - #4270
Open
grzn wants to merge 1 commit into
Open
Make worker_limit configurable at runtime (startup and per-request)#4270grzn wants to merge 1 commit into
grzn wants to merge 1 commit into
Conversation
grzn
force-pushed
the
runtime-configurable-worker-limit
branch
from
July 15, 2026 10:30
31e3876 to
0fc79c2
Compare
…est) exec.worker_limit was baked into generated code as a compile-time literal, so the slice-marshalling concurrency limit could only be changed by editing gqlgen.yml and regenerating. This adds runtime configuration. Precedence: per-request override > server-wide default > codegen worker_limit. - graphql.OperationContext gains a WorkerLimit *int64 field plus EffectiveWorkerLimit(codegenDefault) and SetWorkerLimit(limit) helpers. - Executor/Server gain SetWorkerLimit(int64) for a server-wide default, copied into each OperationContext in CreateOperationContext. - Per-request overrides can be set from an extension/middleware via graphql.GetOperationContext(ctx).SetWorkerLimit(n). - codegen emits ec.EffectiveWorkerLimit(<worker_limit>) instead of the raw literal, keeping the YAML value as the fallback default. Fully backward compatible: with nothing set EffectiveWorkerLimit returns the codegen default, so behaviour is unchanged. MarshalSliceConcurrently's signature is untouched.
grzn
force-pushed
the
runtime-configurable-worker-limit
branch
from
July 15, 2026 12:06
0fc79c2 to
31e0145
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4269
Problem
exec.worker_limitis only configurable at codegen time. gqlgen bakes it into every generatedgraphql.MarshalSliceConcurrently(...)call as a compile-time literal, so the slice-marshalling concurrency limit is frozen at generation time — changing it means editinggqlgen.ymland regenerating.graphql.MarshalSliceConcurrentlyalready takesworkerLimit int64at runtime (0= unlimited), so only the hard-coded literal prevented runtime configuration.Change
Make the worker limit resolvable at runtime, with precedence:
per-request override > server-wide default > codegen
worker_limit(fallback).graphql.OperationContextgains aWorkerLimit *int64field plusEffectiveWorkerLimit(codegenDefault int64) int64andSetWorkerLimit(limit int64)helpers.*int64keeps "unset" distinct from an explicit0(= unlimited).executor.Executorandhandler.ServergainSetWorkerLimit(int64)for a server-wide default, copied into eachOperationContextinCreateOperationContext.graphql.GetOperationContext(ctx).SetWorkerLimit(n).codegen/type.gotpl) now emitsec.EffectiveWorkerLimit({{ .Config.Exec.WorkerLimit }})instead of the raw literal, keeping the YAML value as the default.ecis in scope in both execution-context syntax modes (receiver and function-syntax), so no extra plumbing is needed.Generated files were regenerated with
go generate ./....Backward compatibility
Fully backward compatible. With nothing set at runtime,
EffectiveWorkerLimitreturns the codegen default, so behaviour is identical to before.MarshalSliceConcurrently's signature is unchanged, so example/testdata code that still passes the literal (nested modules not covered bygo generate ./...) keeps compiling.Usage
I have:
graphql.TestEffectiveWorkerLimit)docs/content/config.md)