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

Global decorators #190

Open
benjaminjkraft opened this issue Apr 29, 2022 · 4 comments
Open

Global decorators #190

benjaminjkraft opened this issue Apr 29, 2022 · 4 comments
Labels
enhancement New feature or request

Comments

@benjaminjkraft
Copy link
Collaborator

benjaminjkraft commented Apr 29, 2022

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")
@benjaminjkraft benjaminjkraft added the enhancement New feature or request label Apr 29, 2022
@benjaminjkraft benjaminjkraft changed the title Global version of for option Global decorators May 4, 2022
@benjaminjkraft
Copy link
Collaborator Author

benjaminjkraft commented May 4, 2022

One thing that would be useful to get a sense of from people with bigger codebases using genqlient (@Khan or elsewhere): how commonly useful would this be? Do you see lots of directives that get repeated basically everywhere a certain type is used, such that it would be simpler to make them global?

@csilvers
Copy link
Member

csilvers commented May 4, 2022

From the Khan side: I agree this is most useful for for:, so I just grepped for that. We're only using that directive twice in our entire codebase, and for different things each time. So I think this isn't super-useful for us.

Honestly, except maybe for for: I think having these global configs is too magical for my tastes. I wouldn't want it to be the case that some types are automatically omitempty and some aren't, and the only way to know is to look at some config file far away from the genqlient definition.

@csilvers
Copy link
Member

csilvers commented May 4, 2022

edit: I guess omitempty would apply to all types, that's not so bad.

@benjaminjkraft
Copy link
Collaborator Author

Ah, interesting. I guess since Khan got to define the defaults that's not super surprising; it's the users using things like hasura that want this sort of thing. It's a good point that it's a bit magical, in any case, although I worry that the alternative is just adding config options to do the same things, which is not necessarily any less magical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants