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

Allow custom resolver filenames using filename_template option #1085

Closed
wants to merge 3 commits into from

Conversation

tobias-kuendig
Copy link
Contributor

This PR adds a new filename_template option to the resolver section.

This allows us to get more control over the generated filenames when using the follow-schema layout.

The new option is a string that is passed to fmt.Sprintf and receives the resolver's name as a parameter.

If the option is empty, the format %s.resolvers.go is used.

Before updating the relevant documentation I wanted to get feedback about the implementation and possible other solutions.

@tobias-kuendig
Copy link
Contributor Author

Regarding the failed test:

It looks like removing the original testdata/followschema/out/schema.resolvers.go re-generates the file now with new data, so the assertions won't match anymore.

This also happens on the master branch if the file gets removed before running the tests.

This feels like a test that should have been updated?

@vektah
Copy link
Collaborator

vektah commented Apr 22, 2020

Placeholders are a little more future proof and self describing, eg

filename_template: "{name}.custom.go"

that said, whats the use case here? It would be very easy to break gqlgens output using this by not including the name part, or colliding it with another file in the dir by leaving the suffix off. Without a use case its hard judge the tradeoff.

@tobias-kuendig
Copy link
Contributor Author

Thank you for your feedback.

The current naming convention of %s.resolvers.go is very opinionated. Working on a bigger app, the gqlgen files are the only filenames that contain a suffix. This makes them feel out of place. In my case, I wanted to remove the suffix completely, so the files are just called {name}.go.

Let me know if I should work on a second iteration of this PR. Otherwise feel free to close it!

@vektah
Copy link
Collaborator

vektah commented Apr 24, 2020

Ok, lets switch to a placeholder rather than %s and lets :shipit:

@tobias-kuendig
Copy link
Contributor Author

Great! I did replace the fmt.Sprintf call with a call to strings.ReplaceAll to get simple placeholder support.

@raphaelvigee
Copy link

Any update on getting this merged ?

vektah pushed a commit that referenced this pull request Jul 26, 2020
This is a squash commit of #1085, required to fix the broken tests and
resolve merge conflicts.
@vektah
Copy link
Collaborator

vektah commented Jul 26, 2020

I've squash rebase merged this manually in ad675f0 to fix the broken tests

@vektah vektah closed this Jul 26, 2020
@tobias-kuendig tobias-kuendig deleted the config-suffix branch July 26, 2020 09:40
cgxxv pushed a commit to cgxxv/gqlgen that referenced this pull request Mar 25, 2022
This is a squash commit of 99designs#1085, required to fix the broken tests and
resolve merge conflicts.
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.

3 participants