Khan / Khan/genqlient

Global decorators

Open
#190 4 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
1.3k
Forks
143
Avg merge
4h 50m
Merged PRs (30d)
1

Description

If you want to apply some option to all cases where a particular field of a particular type is referenced in an operation (most commonly an input type) we have the `for` directive option for that. But you might want to do that not just for a single operation, but globally in your `genqlient.yaml`, for example because some particular type always wants `omitempty` or suchlike. (This came up as a workaround in #187, which is a reasonable thing to want and would require several new features to implement otherwise.) ~~It might be better to add proper features to avoid the need (e.g. in this case #178), but this could be a good way for schemas that find themselves needing these kinds of workarounds.~~ This could potentially even subsume features like `bind:` or a future `pointer: always`, although there are advantages to having the full power of YAML instead of our weird decorator-syntax.

I think this would look something like
```
# A list of directives which will be applied to every operation. Typically
# uses `for` but doesn't have to. Overridden by directives in the
# operation itself. The '# ' is omitted [because that's also a
# comment in YAML].
global_directives: |
@genqlient(omitempty: true)
@genqlient(for: "MyType.myField", bind: "MyGoType")
```

Contributor guide

Open the contributing guide

Research direction

Start by reviewing how genqlient.yaml is parsed and how directives on individual operations are currently handled. Define how global_directives are applied across operations, including precedence for operation-level directives, and verify that the proposed YAML block supports the shown @genqlient examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, graphql
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.