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

Make the resolver implementation configurable via a new template resolver.gotpl #2720

Merged
merged 5 commits into from
Jul 22, 2023

Conversation

penard-cb
Copy link
Contributor

@penard-cb penard-cb commented Jul 19, 2023

Describe your PR and link to any relevant issues.

I'm adding the ability to pass in a new ResolverTemplate to the ResolverConfig which allows the user to configure a new layout and custom template to generate resolvers.

I made #2724 and this PR should fix it.

What happened?

I need to be able to run gqlgen and pass in a template for generating a resolver.

I need to be able to pass in new imports and make significant code additions (maybe even some convenience methods). This will allow my implementing team to follow my guidlines.

What did you expect?

I thought the config would have an option to just replace the whole gotpl file... it doesn't.

Minimal graphql.schema and models to reproduce

type Query {
    resolver: Resolver!
}

type Resolver {
    name: String!
}
schema:
  - "testdata/schema.graphql"

exec:
  filename: testdata/singlefile/out/ignored.go
model:
  filename: testdata/singlefile/out/generated.go
resolver:
  type: CustomResolverType
  layout: follow-schema
  dir: testdata/resolvertemplate/out
  filename_template: "{name}.resolvers.go"
  resolver_template: "testdata/resolvertemplate/customResolverTemplate.gotpl"

models:
  Resolver:
    model: github.com/99designs/gqlgen/plugin/resolvergen/testdata/singlefile/out.Resolver

I have:

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

@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Jul 19, 2023

Cool! I'm looking forward to seeing where this goes. Thanks for working on it!

@penard-cb penard-cb marked this pull request as ready for review July 20, 2023 19:38
@penard-cb
Copy link
Contributor Author

Cool! I'm looking forward to seeing where this goes. Thanks for working on it!

@StevenACoffman I just pushed an update. I also joined the discord, let me know if you want to chat about it. I think this is ready for review.

@dmaulick
Copy link

+1 looking forward to this change

@StevenACoffman
Copy link
Collaborator

StevenACoffman commented Jul 21, 2023

@penard-cb I noticed there are some test failures. If you could take a look, I would appreciate it.
It's possible you just need to regenerate some files or run the go mod tidy:

go generate ./...; cd _examples; go generate ./...
act --artifact-server-path /tmp/artifacts -j test -W .github/workflows/test.yml

@penard-cb
Copy link
Contributor Author

@StevenACoffman Thanks. I was able to run those commands locally and think I found the issue. I pushed up an update. 🤞

@coveralls
Copy link

Coverage Status

coverage: 75.734% (-0.004%) from 75.738% when pulling cb384d3 on penard-cb:custom-resolver-templates into cccc738 on 99designs:master.

@tsingsun
Copy link

tsingsun commented Aug 7, 2023

may helpless if not support customer function in template.

@penard-cb
Copy link
Contributor Author

@tsingsun What do you mean? You can modify the template as you see fit.

@tsingsun
Copy link

tsingsun commented Aug 9, 2023

i mean that how to pass the custom function to the template, like use template.Func.
user custom templates, most likely not just for formatting.

@penard-cb
Copy link
Contributor Author

Hi @tsingsun . Ah I see. Yes, I have a couple of branches where I'm thinking through how to do that. Requires some interesting and substantial refactor though. I will likely continue working on it within the next month. Happy to collaborate if you have some ideas.

mergify bot referenced this pull request in infratographer/metadata-api Aug 16, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/99designs/gqlgen](https://togithub.com/99designs/gqlgen) |
require | patch | `v0.17.34` -> `v0.17.36` |

---

### Release Notes

<details>
<summary>99designs/gqlgen (github.com/99designs/gqlgen)</summary>

###
[`v0.17.36`](https://togithub.com/99designs/gqlgen/releases/tag/v0.17.36)

[Compare
Source](https://togithub.com/99designs/gqlgen/compare/v0.17.35...v0.17.36)

#### What's Changed

- Update gqlparser to v2.5.8 by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[https://github.com/99designs/gqlgen/pull/2716](https://togithub.com/99designs/gqlgen/pull/2716)
- Added go mod tidy to quick start guide by
[@&#8203;UnAfraid](https://togithub.com/UnAfraid) in
[https://github.com/99designs/gqlgen/pull/2718](https://togithub.com/99designs/gqlgen/pull/2718)
- docs: update dataloader docs by
[@&#8203;zenyui](https://togithub.com/zenyui) in
[https://github.com/99designs/gqlgen/pull/2719](https://togithub.com/99designs/gqlgen/pull/2719)
- Fix docs by [@&#8203;zenyui](https://togithub.com/zenyui) in
[https://github.com/99designs/gqlgen/pull/2722](https://togithub.com/99designs/gqlgen/pull/2722)
- Fixed Data Loader docs by
[@&#8203;UnAfraid](https://togithub.com/UnAfraid) in
[https://github.com/99designs/gqlgen/pull/2723](https://togithub.com/99designs/gqlgen/pull/2723)
- Make the resolver implementation configurable via a new template
resolver.gotpl by [@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2720](https://togithub.com/99designs/gqlgen/pull/2720)
- fix: Don't set the package variable for the new Resolver Template by
[@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2725](https://togithub.com/99designs/gqlgen/pull/2725)
- Make models configurable via template by
[@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2730](https://togithub.com/99designs/gqlgen/pull/2730)
- Fix plugin template resolution by
[@&#8203;douglaswth](https://togithub.com/douglaswth) in
[https://github.com/99designs/gqlgen/pull/2733](https://togithub.com/99designs/gqlgen/pull/2733)

#### New Contributors

- [@&#8203;penard-cb](https://togithub.com/penard-cb) made their first
contribution in
[https://github.com/99designs/gqlgen/pull/2720](https://togithub.com/99designs/gqlgen/pull/2720)
- [@&#8203;douglaswth](https://togithub.com/douglaswth) made their first
contribution in
[https://github.com/99designs/gqlgen/pull/2733](https://togithub.com/99designs/gqlgen/pull/2733)

**Full Changelog**:
99designs/gqlgen@v0.17.35...v0.17.36

###
[`v0.17.35`](https://togithub.com/99designs/gqlgen/blob/HEAD/CHANGELOG.md#v01735---2023-07-15)

[Compare
Source](https://togithub.com/99designs/gqlgen/compare/v0.17.34...v0.17.35)

- <a
href="https://togithub.com/99designs/gqlgen/commit/05006bf1dcb9451b0960d07fd68370145c2697b4"><tt>[`05006bf`](https://togithub.com/99designs/gqlgen/commit/05006bf1)</tt></a>
release v0.17.35

- <a
href="https://togithub.com/99designs/gqlgen/commit/d95d614f8fc2c5983390adf0507027a1efdd778a"><tt>[`d95d614`](https://togithub.com/99designs/gqlgen/commit/d95d614f)</tt></a>
Update gqlparser to v2.5.7 (<a
href="https://togithub.com/99designs/gqlgen/pull/2714">[#&#8203;2714](https://togithub.com/99designs/gqlgen/issues/2714)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/8c378e6bdd1962822216053ae2c01e89ef35034a"><tt>[`8c378e6`](https://togithub.com/99designs/gqlgen/commit/8c378e6b)</tt></a>
Updated GraphiQL playground 2.0.7 -> 3.0.1 and react 17 -> 18 (<a
href="https://togithub.com/99designs/gqlgen/pull/2713">[#&#8203;2713](https://togithub.com/99designs/gqlgen/issues/2713)</a>)

<dl><dd><details><summary><a
href="https://togithub.com/99designs/gqlgen/commit/7880739d48a9aa2d6f4be87129cb361d2c2c0345"><tt>7880739d</tt></a>
Add op ctx safety for apollo tracing (<a
href="https://togithub.com/99designs/gqlgen/pull/2709">#&#8203;2709</a>)</summary>

- Add automated tests for both tracing and tracer to simulate a client
disconnect
- Check for existence of operation context before proceeding to avoid
panic

</details></dd></dl>

- <a
href="https://togithub.com/99designs/gqlgen/commit/6ed9337bce0daf05c1c3bda29fd86368768cdb68"><tt>[`6ed9337`](https://togithub.com/99designs/gqlgen/commit/6ed9337b)</tt></a>
fix function name in comment (<a
href="https://togithub.com/99designs/gqlgen/pull/2707">[#&#8203;2707](https://togithub.com/99designs/gqlgen/issues/2707)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/2cfb9f98c4c2b090a6a65816ed28a67501303768"><tt>[`2cfb9f9`](https://togithub.com/99designs/gqlgen/commit/2cfb9f98)</tt></a>
Fix apollo integrity hash (<a
href="https://togithub.com/99designs/gqlgen/pull/2706">[#&#8203;2706](https://togithub.com/99designs/gqlgen/issues/2706)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/470fca87d3002399fb02e14cf014c3c26755d87b"><tt>[`470fca8`](https://togithub.com/99designs/gqlgen/commit/470fca87)</tt></a>
Update gqlparser again (<a
href="https://togithub.com/99designs/gqlgen/pull/2697">[#&#8203;2697](https://togithub.com/99designs/gqlgen/issues/2697)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/280441b1a0c46652f3b16692839fbdbd024aa06d"><tt>[`280441b`](https://togithub.com/99designs/gqlgen/commit/280441b1)</tt></a>
Update changelog

- <a
href="https://togithub.com/99designs/gqlgen/commit/5bc36e142dfffceb96ac8b23bb9c13b492504474"><tt>[`5bc36e1`](https://togithub.com/99designs/gqlgen/commit/5bc36e14)</tt></a>
v0.17.34 postrelease bump

 <!-- end of Commits -->

<!-- end of Else -->

<!-- end of If NoteGroups -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/infratographer/metadata-api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xMTAuMCIsInVwZGF0ZWRJblZlciI6IjM2LjQzLjIiLCJ0YXJnZXRCcmFuY2giOiJtYWluIn0=-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
github-merge-queue bot referenced this pull request in infratographer/x Aug 21, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [github.com/99designs/gqlgen](https://togithub.com/99designs/gqlgen) |
require | patch | `v0.17.34` -> `v0.17.36` |

---

### Release Notes

<details>
<summary>99designs/gqlgen (github.com/99designs/gqlgen)</summary>

###
[`v0.17.36`](https://togithub.com/99designs/gqlgen/releases/tag/v0.17.36)

[Compare
Source](https://togithub.com/99designs/gqlgen/compare/v0.17.35...v0.17.36)

#### What's Changed

- Update gqlparser to v2.5.8 by
[@&#8203;StevenACoffman](https://togithub.com/StevenACoffman) in
[https://github.com/99designs/gqlgen/pull/2716](https://togithub.com/99designs/gqlgen/pull/2716)
- Added go mod tidy to quick start guide by
[@&#8203;UnAfraid](https://togithub.com/UnAfraid) in
[https://github.com/99designs/gqlgen/pull/2718](https://togithub.com/99designs/gqlgen/pull/2718)
- docs: update dataloader docs by
[@&#8203;zenyui](https://togithub.com/zenyui) in
[https://github.com/99designs/gqlgen/pull/2719](https://togithub.com/99designs/gqlgen/pull/2719)
- Fix docs by [@&#8203;zenyui](https://togithub.com/zenyui) in
[https://github.com/99designs/gqlgen/pull/2722](https://togithub.com/99designs/gqlgen/pull/2722)
- Fixed Data Loader docs by
[@&#8203;UnAfraid](https://togithub.com/UnAfraid) in
[https://github.com/99designs/gqlgen/pull/2723](https://togithub.com/99designs/gqlgen/pull/2723)
- Make the resolver implementation configurable via a new template
resolver.gotpl by [@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2720](https://togithub.com/99designs/gqlgen/pull/2720)
- fix: Don't set the package variable for the new Resolver Template by
[@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2725](https://togithub.com/99designs/gqlgen/pull/2725)
- Make models configurable via template by
[@&#8203;penard-cb](https://togithub.com/penard-cb) in
[https://github.com/99designs/gqlgen/pull/2730](https://togithub.com/99designs/gqlgen/pull/2730)
- Fix plugin template resolution by
[@&#8203;douglaswth](https://togithub.com/douglaswth) in
[https://github.com/99designs/gqlgen/pull/2733](https://togithub.com/99designs/gqlgen/pull/2733)

#### New Contributors

- [@&#8203;penard-cb](https://togithub.com/penard-cb) made their first
contribution in
[https://github.com/99designs/gqlgen/pull/2720](https://togithub.com/99designs/gqlgen/pull/2720)
- [@&#8203;douglaswth](https://togithub.com/douglaswth) made their first
contribution in
[https://github.com/99designs/gqlgen/pull/2733](https://togithub.com/99designs/gqlgen/pull/2733)

**Full Changelog**:
99designs/gqlgen@v0.17.35...v0.17.36

###
[`v0.17.35`](https://togithub.com/99designs/gqlgen/blob/HEAD/CHANGELOG.md#v01735---2023-07-15)

[Compare
Source](https://togithub.com/99designs/gqlgen/compare/v0.17.34...v0.17.35)

- <a
href="https://togithub.com/99designs/gqlgen/commit/05006bf1dcb9451b0960d07fd68370145c2697b4"><tt>[`05006bf`](https://togithub.com/99designs/gqlgen/commit/05006bf1)</tt></a>
release v0.17.35

- <a
href="https://togithub.com/99designs/gqlgen/commit/d95d614f8fc2c5983390adf0507027a1efdd778a"><tt>[`d95d614`](https://togithub.com/99designs/gqlgen/commit/d95d614f)</tt></a>
Update gqlparser to v2.5.7 (<a
href="https://togithub.com/99designs/gqlgen/pull/2714">[#&#8203;2714](https://togithub.com/99designs/gqlgen/issues/2714)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/8c378e6bdd1962822216053ae2c01e89ef35034a"><tt>[`8c378e6`](https://togithub.com/99designs/gqlgen/commit/8c378e6b)</tt></a>
Updated GraphiQL playground 2.0.7 -> 3.0.1 and react 17 -> 18 (<a
href="https://togithub.com/99designs/gqlgen/pull/2713">[#&#8203;2713](https://togithub.com/99designs/gqlgen/issues/2713)</a>)

<dl><dd><details><summary><a
href="https://togithub.com/99designs/gqlgen/commit/7880739d48a9aa2d6f4be87129cb361d2c2c0345"><tt>7880739d</tt></a>
Add op ctx safety for apollo tracing (<a
href="https://togithub.com/99designs/gqlgen/pull/2709">#&#8203;2709</a>)</summary>

- Add automated tests for both tracing and tracer to simulate a client
disconnect
- Check for existence of operation context before proceeding to avoid
panic

</details></dd></dl>

- <a
href="https://togithub.com/99designs/gqlgen/commit/6ed9337bce0daf05c1c3bda29fd86368768cdb68"><tt>[`6ed9337`](https://togithub.com/99designs/gqlgen/commit/6ed9337b)</tt></a>
fix function name in comment (<a
href="https://togithub.com/99designs/gqlgen/pull/2707">[#&#8203;2707](https://togithub.com/99designs/gqlgen/issues/2707)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/2cfb9f98c4c2b090a6a65816ed28a67501303768"><tt>[`2cfb9f9`](https://togithub.com/99designs/gqlgen/commit/2cfb9f98)</tt></a>
Fix apollo integrity hash (<a
href="https://togithub.com/99designs/gqlgen/pull/2706">[#&#8203;2706](https://togithub.com/99designs/gqlgen/issues/2706)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/470fca87d3002399fb02e14cf014c3c26755d87b"><tt>[`470fca8`](https://togithub.com/99designs/gqlgen/commit/470fca87)</tt></a>
Update gqlparser again (<a
href="https://togithub.com/99designs/gqlgen/pull/2697">[#&#8203;2697](https://togithub.com/99designs/gqlgen/issues/2697)</a>)

- <a
href="https://togithub.com/99designs/gqlgen/commit/280441b1a0c46652f3b16692839fbdbd024aa06d"><tt>[`280441b`](https://togithub.com/99designs/gqlgen/commit/280441b1)</tt></a>
Update changelog

- <a
href="https://togithub.com/99designs/gqlgen/commit/5bc36e142dfffceb96ac8b23bb9c13b492504474"><tt>[`5bc36e1`](https://togithub.com/99designs/gqlgen/commit/5bc36e14)</tt></a>
v0.17.34 postrelease bump

 <!-- end of Commits -->

<!-- end of Else -->

<!-- end of If NoteGroups -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/infratographer/x).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNi41LjMiLCJ1cGRhdGVkSW5WZXIiOiIzNi4yNC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.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

Successfully merging this pull request may close these issues.

5 participants