-
Notifications
You must be signed in to change notification settings - Fork 1.2k
refactor(codegen): use graphql.Config type #4017
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
refactor(codegen): use graphql.Config type #4017
Conversation
d636ef0 to
24df78f
Compare
| eq, msg := eqgo.PackagesEquivalent( | ||
| singlefilePkg, | ||
| singlefileFSet, | ||
| followschemaPkg, | ||
| followschemaFSet, | ||
| nil, | ||
| ) | ||
| if !eq { | ||
| // When msg is too long, require.True(...) omits it entirely. | ||
| // Therefore use fmt.Fprintln to print it manually instead. | ||
| fmt.Fprintln(os.Stderr, msg) | ||
| require.Fail(t, "Packages not equivalent") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
eq-go does not support Go 1.18 generics (ast.IndexListExpr) and panics when it encounters them.
Since the library is no longer maintained, this PR replaces it with comparison using the standard library's go/printer.
type Config[R any, D any, C any] struct {
Schema *ast.Schema
Resolvers R
Directives D
Complexity C
}| if gd, ok := decl.(*ast.GenDecl); ok && gd.Tok == token.IMPORT { | ||
| continue | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This skips import comparison. Since matching declarations will inherently produce matching imports, there's little value in comparing them separately. It also avoids some awkward edge cases around import handling. I don't think this causes any real problems in practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me!
Description
Some of the code currently living in the templates doesn't need to be part of the generated output. Moving these pieces into static .go files helps keep generated.go simpler and easier to maintain.
There are several places where this applies, so I'll be sending a series of smaller PRs rather than one large change. As a first step, this PR extracts the Config struct into the graphql package.
I have: