Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Add omit_complexity config flag to skip generation of the body of ComplexityRoot struct and Complexity function #2502

Closed
mariuscraciunescu opened this issue Jan 9, 2023 · 0 comments

Comments

@mariuscraciunescu
Copy link
Contributor

What happened?

When GraphQL schema is really large (~60.000+ lines), the code generated with gqlgen fails to compile with the following error:

<autogenerated>:1: internal compiler error: NewBulk too big: nbit=13244 count=1469951 nword=414 size=608559714
More details about this compiler issue can be found here: golang/go#48375, golang/go#33437

This compilation error is caused by:
type ComplexityRoot struct { ... }
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) { ... }

What did you expect?

Code should compile successfully, regardless of the GraphQL schema size.

versions

  • v0.17.22

Proposed solution

Introduce a new config flag omit_complexity, which when set to true will skip the generation of the body of these constructs.

The resulting generated code will be:

type ComplexityRoot struct {
  // empty struct
}
func (e *executableSchema) Complexity(typeName, field string, childComplexity int, rawArgs map[string]interface{}) (int, bool) {
  ec := executionContext{nil, e}
  _ = ec

  // switch statement is not generated

  return 0, false
}

This proposal is backwards compatible, won't introduce any breaking changes.

StevenACoffman pushed a commit that referenced this issue Jan 13, 2023
* Add omit_complexity config option to skip generation of ComplexityRoot struct content and Complexity function

* fix lint error

Co-authored-by: Marius Craciunescu <marius.craciunescu@crowdstrike.com>
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

No branches or pull requests

2 participants