GraphQL: Support "Fragment arguments" (#19297)

This commit is contained in:
fisker Cheung authored and GitHub committed 2026-06-05 19:39:29 +08:00
1 parent 6b0bc8e6d4
commit 8cb163504a
8 files changed
+98 -8

No files matched your search

+1 -1
View File
@@ -1,4 +1,4 @@
#### Support directives on directive definitions (#19171 by @YBJ0000) #### Support "directives on directive definitions" (#19171 by @YBJ0000)
[Directives on directive definitions](https://github.com/graphql/graphql-js/pull/4521) (and `extend directive` extensions) are now supported. [Directives on directive definitions](https://github.com/graphql/graphql-js/pull/4521) (and `extend directive` extensions) are now supported.
+23
View File
@@ -0,0 +1,23 @@
#### Support "Fragment arguments" (#19297 by @fisker)
[Fragment arguments](https://github.com/graphql/graphql-js/pull/4015) are now supported.
<!-- prettier-ignore -->
```gql
# Input
fragment variableProfilePic on User {
...dynamicProfilePic(size: $size)
}
# Prettier stable
SyntaxError: Syntax Error: Expected Name, found "(". (2:23)
1 | fragment variableProfilePic on User {
> 2 | ...dynamicProfilePic(size: $size)
| ^
3 | }
# Prettier main
fragment variableProfilePic on User {
...dynamicProfilePic(size: $size)
}
```
+7 -1
View File
@@ -167,6 +167,7 @@ function genericPrint(path, options, print) {
case "ObjectField": case "ObjectField":
case "Argument": case "Argument":
case "FragmentArgument":
return [print("name"), ": ", print("value")]; return [print("name"), ": ", print("value")];
case "Directive": case "Directive":
@@ -373,7 +374,12 @@ function genericPrint(path, options, print) {
return [node.operation, ": ", print("type")]; return [node.operation, ": ", print("type")];
case "FragmentSpread": case "FragmentSpread":
return ["...", print("name"), printDirectives(path, print)]; return [
"...",
print("name"),
printArguments(path, options, print),
printDirectives(path, print),
];
case "InlineFragment": case "InlineFragment":
return [ return [
-6
View File
@@ -13,10 +13,4 @@ for (const kind of [
delete visitorKeys[kind]; delete visitorKeys[kind];
} }
// Not supported yet
visitorKeys.FragmentSpread = visitorKeys.FragmentSpread.filter(
(key) => key !== "arguments",
);
delete visitorKeys.FragmentArgument;
export default visitorKeys; export default visitorKeys;
@@ -0,0 +1,46 @@
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
exports[`fragment-arguemnts.graphql format 1`] = `
====================================options=====================================
parsers: ["graphql"]
printWidth: 80 (default) |
=====================================input======================================
query withShadowedVariables($size: Int!) {
user(id: 4) {
...variableProfilePic
}
secondUser: user(id: 5) {
...dynamicProfilePic(size: 10)
}
}
fragment variableProfilePic on User {
...dynamicProfilePic(size: $size)
}
fragment a on t { ...b(v: $v) }
fragment a on t { ...b(v: $v) @foo }
=====================================output=====================================
query withShadowedVariables($size: Int!) {
user(id: 4) {
...variableProfilePic
}
secondUser: user(id: 5) {
...dynamicProfilePic(size: 10)
}
}
fragment variableProfilePic on User {
...dynamicProfilePic(size: $size)
}
fragment a on t {
...b(v: $v)
}
fragment a on t {
...b(v: $v) @foo
}
================================================================================
`;
@@ -0,0 +1 @@
runFormatTest(import.meta, ["graphql"]);
@@ -0,0 +1,15 @@
query withShadowedVariables($size: Int!) {
user(id: 4) {
...variableProfilePic
}
secondUser: user(id: 5) {
...dynamicProfilePic(size: 10)
}
}
fragment variableProfilePic on User {
...dynamicProfilePic(size: $size)
}
fragment a on t { ...b(v: $v) }
fragment a on t { ...b(v: $v) @foo }
@@ -1337,6 +1337,10 @@ exports[`visitor keys graphql 1`] = `
"type", "type",
], ],
"FloatValue": [], "FloatValue": [],
"FragmentArgument": [
"name",
"value",
],
"FragmentDefinition": [ "FragmentDefinition": [
"description", "description",
"directives", "directives",
@@ -1346,6 +1350,7 @@ exports[`visitor keys graphql 1`] = `
"variableDefinitions", "variableDefinitions",
], ],
"FragmentSpread": [ "FragmentSpread": [
"arguments",
"directives", "directives",
"name", "name",
], ],