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

Improve ResolverImplementer.Implment #2850

Merged

Conversation

roneli
Copy link
Contributor

@roneli roneli commented Dec 2, 2023

Changes the ResolverImplementor to be a function that is called in render time, rather then before, keeping compatibility with previous versions.

@StevenACoffman ,I will add tests if this change makes sense.

The reason I changed it is sometimes the render requires some logic, such as calling the template.Render's ReserveImport , which impossible to call if we are doing it before that call as it will be nil (templates.CurrentImports)

Moreover the original implementation had a flaw, that once an implementation existed, it was never called again, which doesn't make sense. I wanted to pass the PrevDecl of the function to the interface, but didn't want to break compatibility, so now it just re-renders each time.

Describe your PR and link to any relevant issues.

I have:

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

@roneli roneli changed the title improve resolver implement render Improve ResolverImplementer.Implment Dec 2, 2023
@coveralls
Copy link

coveralls commented Dec 2, 2023

Coverage Status

coverage: 75.933% (+0.08%) from 75.856%
when pulling 1bb2ce7 on roneli:improve-resolver-implement-render
into cb3c1c8 on 99designs:master.

@StevenACoffman
Copy link
Collaborator

@roneli I would like you to add some test coverage for this, as I expect others to build upon your work here.

@roneli
Copy link
Contributor Author

roneli commented Dec 2, 2023

Awesome, thanks for the quick reply.

I wanted to also upgrade this code a little more, as currently it only allows a single implementer, but I would like implementers to have more control perhaps (running based on field / logic) and also get previous implementation. Maybe for future improvements. (Unless you prefer we break the interface now? rather than later?)

Will add tests soon so we can merge this.

@roneli
Copy link
Contributor Author

roneli commented Dec 2, 2023

Added a test, as I saw on all, I would maybe go with deeper tests, need to play with more cases like a render with imports.

Just tell me if we want to upgrade the interface a little more now to give it more control or in a later PR?

// ResolverImplementer is used to generate code inside resolvers
type ResolverImplementer interface {
	ShouldImplement(object *codegen.Object, field *codegen.Field) bool
	Implement(previousDecl string, field *codegen.Field) string
}

Like this perhaps? Allowing for implementors based on what we see maybe a directive etc'.

We can also just pass the object into implement and let all the logic reside there.

@StevenACoffman StevenACoffman merged commit bd9657f into 99designs:master Dec 3, 2023
18 checks passed
@StevenACoffman
Copy link
Collaborator

This PR is already a useful improvement, so I merged it! I would love further improvements or demonstrations of how to take advantage of this.

I am open to changing the interface in the future if we can demonstrate an immediate need to do so, and we have a good sense of how much it might break people's existing code.

@mojtabacazi
Copy link

This breaks our entire project, replaces are existing resolver implementation with panic(....

@StevenACoffman
Copy link
Collaborator

@mojtabacazi Did you look at #2886 ? WDYT?

@roneli roneli deleted the improve-resolver-implement-render branch February 2, 2024 20:29
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.

None yet

4 participants