Parameterized fragments
A [recent talk about Relay 2](https://speakerdeck.com/wincent/relay-2-simpler-faster-more-predictable) suggested adding arguments to query fragments via directives. I think first-class support for arguments in fragments would give a few benefits: - Smaller variable scope: instead of checking each usage of a fragment (which may be deeply nested) to determine what variables are available, a fragment would be its own scope. You could determine available variables by the fragment definition alone. - More flexible reuse: since a fragment wouldn't depend on its query's variables, fragments could be applied to queries whose variables had different names. They could also receive literal values when the query has no variables. For example, a fragment might be defined with variables: ``` graphql fragment avatarFields($thumbSize: Int = 40) on Image { thumbURL(size: $thumbSize) uploadedAt } ``` The spread with different values: ``` graphql { person(id: 1) { avatar { ... avatarFields(thumbSize: 80) } } } ``` ``` graphql query findPerson($personId: Int!, $avatarSize: Int!) { person(id: $personId) { avatar { ... avatarFields(thumbSize: $avatarSize) } } } ``` To be honest, I don't have a use case. But this seems like a really solid feature, and as a library maintainer, I'd rather add this language feature than implement some new directives! (Or, would those directives be "compiled out"?) Technically, this could even be backwards compatible.
Posted by rmosolgo on Aug 23, 2016, 7:54 PM
Tags
Related issues
- some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
- I think of this as the kiosk economy.
- What a goofy comment.
- There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
- Compose support in WSLc
- [RFC] Roadmap to v2.0
Raise real-world problems, find people facing the same issue, and discuss solutions.5,000 issues0 comments
support (Other)
some bike vendor told me that the biggest problem with regular to ebike conversion was that regular bike frames were not strong enough to...
I think of this as the kiosk economy.
What a goofy comment.
There's lots of evidence for positive influences of Caffeine on the body (some negative as well), especially the brain.
Compose support in WSLc
[RFC] Roadmap to v2.0
[Feature]: Add TurboQuant Support for KV Cache Quantization
Support for AGENTS.md and .agents/skills/, the community has been asking since August 2025
Parameterized fragments
A [recent talk about Relay 2](https://speakerdeck.com/wincent/relay-2-simpler-faster-more-predictable) suggested adding arguments to query fragments via directives. I think first-class support for arguments in fragments would give a few benefits: - Smaller variable scope: instead of checking each usage of a fragment (which may be deeply nested) to determine what variables are available, a fragment would be its own scope. You could determine available variables by the fragment definition alone. - More flexible reuse: since a fragment wouldn't depend on its query's variables, fragments could be applied to queries whose variables had different names. They could also receive literal values when the query has no variables. For example, a fragment might be defined with variables: ``` graphql fragment avatarFields($thumbSize: Int = 40) on Image { thumbURL(size: $thumbSize) uploadedAt } ``` The spread with different values: ``` graphql { person(id: 1) { avatar { ... avatarFields(thumbSize: 80) } } } ``` ``` graphql query findPerson($personId: Int!, $avatarSize: Int!) { person(id: $personId) { avatar { ... avatarFields(thumbSize: $avatarSize) } } } ``` To be honest, I don't have a use case. But this seems like a really solid feature, and as a library maintainer, I'd rather add this language feature than implement some new directives! (Or, would those directives be "compiled out"?) Technically, this could even be backwards compatible.
Comments (0)
No comments yet. Start the discussion.