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

[resolvergen] make rewrite default for single-file mode #3243

Merged

Conversation

hailyngx
Copy link
Contributor

@hailyngx hailyngx commented Sep 4, 2024

BREAKING CHANGE

Resolvers generated using layout: single-file will now have their resolver files overwritten on generate.

Why this change?

Make rewrite the default for single-file mode as no one is relying on the behavior of single file NOT supporting rewrite. Thus, it would be backwards compatible to use the existing rewrite instead of introducing the new enable_rewrite_for_single_file flag.
Relevant Discussion: #3205

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@hailyngx hailyngx force-pushed the enable_rewrite_for_single_file branch from 1f993f2 to d7ffe0c Compare September 4, 2024 22:07
@hailyngx
Copy link
Contributor Author

hailyngx commented Sep 4, 2024

Refactor unit tests -- Sorry I got mixed up some file changes in my last commit that failed 2 tests. Should passed all unit tests now with this new commit!

@coveralls
Copy link

coveralls commented Sep 4, 2024

Coverage Status

coverage: 56.737% (+0.05%) from 56.691%
when pulling 61bcb03 on uber:enable_rewrite_for_single_file
into 1855758 on 99designs:master.

filename: testdata/singlefile_enable_rewrite/out/generated.go
resolver:
filename: testdata/singlefile_enable_rewrite/out/resolver.go
type: CustomResolverType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work without this option?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clayne11 This is the unit test for rewrite features with single-file, which follows exactly the available single-file feature. As I wrote a new function, it's good to have coverage.
On another note, without rewrite, yes, it does work in our system with Bazel. However, it does not support any functional overwriting. The developer will generate the stubs, implement however they like after the stubs. If they happened to make large schema changes and want the new corresponding resolver stubs, they have to delete resolver.go in the directory. The main difference is that single-file only focus on generating the stubs, not keeping the implementation.
Rewrite aims to support large schema changes while retaining the implementation of single-file mode.


type Resolver struct{}

type QueryResolver interface {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these interfaces being generated here? Aren't these normally inside the server executable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@clayne11 You are right! The test are supposed to include only one model.go with necessary interfaces (that are usually in the server.go). They supply it this way only for the purpose of a compact unit test I think.

@StevenACoffman
Copy link
Collaborator

BTW, I very much appreciate you working on this, as it helps to narrow the behavioral gap between single file and multi-file (where rewrite is currently supported).

I don't believe anyone is relying on the behavior of single file NOT supporting rewrite, so I think it would be backwards compatible to use the existing rewrite instead of introducing the new enable_rewrite_for_single_file but I am happy to merge this as is, or to make changes that better fit with the changes that @clayne11 is working on.

@clayne11
Copy link
Contributor

clayne11 commented Sep 5, 2024

Makes sense, let's remove the flag then and just make it default behavior. Thanks for reviewing @StevenACoffman.

@hailyngx
Copy link
Contributor Author

Updated based on your suggestion @StevenACoffman 🙏 Thank you Steve!

@hailyngx hailyngx changed the title [resolvergen] add configuration flag and unit tests for enable_rewrite_single_file [resolvergen] make rewrite default for single-file mode Sep 12, 2024
@hailyngx hailyngx force-pushed the enable_rewrite_for_single_file branch 3 times, most recently from 22d8ef5 to c355813 Compare September 12, 2024 20:07
)

type CustomResolverType struct{}

// Resolver is the resolver for the resolver field.
func (r *queryCustomResolverType) Resolver(ctx context.Context) (*Resolver, error) {
panic("not implemented")
panic(fmt.Errorf("not implemented: Resolver - resolver"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The string change is welcome, but why are you changing from:

panic("a problem")

to:

panic(fmt.Errorf("a problem"))

It seems unhelpful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like I have to go back to change the default stubs of rewrite single-file to panic("not implemented"). panic(fmt.Errorf("not implemented: Resolver - resolver")) is currently the template for the default rewrite follow-schema. That's why the change is necessary for a git diff check, but if I make this change, the lint check does not like it. Also, looks like deleting resolver config is not a solution. Let me know if you have any suggestions!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a big deal. We you would need to backtrack and change the template, but it's not actually important.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@StevenACoffman Made a new commit that works for all tests. Coverage and security should be good to go even though they fail right? Thanks Steve for being so responsive!

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Thanks for sticking with it! Sorry this was such a long journey!

@hailyngx hailyngx force-pushed the enable_rewrite_for_single_file branch from c355813 to 61bcb03 Compare September 12, 2024 22:20
@StevenACoffman StevenACoffman merged commit 6b9e40e into 99designs:master Sep 13, 2024
15 of 17 checks passed
@StevenACoffman
Copy link
Collaborator

Thanks for this work!

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.

4 participants