From 2e2a23fa08b1ea8c49df6c6e6fcfcb37b5cb2849 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Fri, 5 Jun 2026 18:49:38 +0800 Subject: [PATCH] Update GraphQL to v17 (#19175) --- package.json | 2 +- scripts/build/transform/index.js | 2 +- src/language-graphql/parser-graphql.js | 7 ++++- src/language-graphql/printer-graphql.js | 37 +++++++++++++------------ src/language-graphql/visitor-keys.js | 8 +++++- yarn.lock | 10 +++---- 6 files changed, 40 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index e6989bfea..8ee5b3e4e 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "flow-parser": "0.317.0", "get-east-asian-width": "1.6.0", "get-stdin": "9.0.0", - "graphql": "16.14.1", + "graphql": "17.0.0-rc.0", "hermes-parser": "0.36.1", "html-element-attributes": "3.5.0", "html-ua-styles": "0.3.1", diff --git a/scripts/build/transform/index.js b/scripts/build/transform/index.js index 10f3bb62c..00482e923 100644 --- a/scripts/build/transform/index.js +++ b/scripts/build/transform/index.js @@ -28,7 +28,7 @@ const packageTransforms = new Map([ transforms["method-at"], ["@glimmer/syntax", "angular-estree-parser", "espree"], ], - [transforms["object-has-own"], ["@babel/parser", "meriyah"]], + [transforms["object-has-own"], ["@babel/parser", "meriyah", "graphql"]], [transforms["string-raw"], ["camelcase", "@angular/compiler"]], [transforms["method-is-well-formed"], ["meriyah"]], /* spell-checker: enable */ diff --git a/src/language-graphql/parser-graphql.js b/src/language-graphql/parser-graphql.js index dd9fe9c82..4c53bf128 100644 --- a/src/language-graphql/parser-graphql.js +++ b/src/language-graphql/parser-graphql.js @@ -3,6 +3,10 @@ import createError from "../common/parser-create-error.js"; import { locEnd, locStart } from "./loc.js"; import { hasIgnorePragma, hasPragma } from "./pragma.js"; +/** +@import {ParseOptions} from "graphql" +*/ + function parseComments(ast) { const comments = []; const { startToken, endToken } = ast.loc; @@ -15,8 +19,9 @@ function parseComments(ast) { return comments; } +/** @type {ParseOptions} */ const parseOptions = { - allowLegacyFragmentVariables: true, + experimentalFragmentArguments: true, experimentalDirectivesOnDirectiveDefinitions: true, }; diff --git a/src/language-graphql/printer-graphql.js b/src/language-graphql/printer-graphql.js index c4ec20b17..44caf9d5a 100644 --- a/src/language-graphql/printer-graphql.js +++ b/src/language-graphql/printer-graphql.js @@ -71,7 +71,7 @@ function genericPrint(path, options, print) { return group([ node.alias ? [print("alias"), ": "] : "", print("name"), - node.arguments.length > 0 + isNonEmptyArray(node.arguments) ? group([ "(", indent([ @@ -142,20 +142,20 @@ function genericPrint(path, options, print) { ]); case "ObjectValue": { - const bracketSpace = - options.bracketSpacing && node.fields.length > 0 ? " " : ""; + const isEmpty = !isNonEmptyArray(node.fields); + const bracketSpace = options.bracketSpacing && !isEmpty ? " " : ""; return group([ "{", bracketSpace, printDanglingComments(path, options, { indent: true }), - isNonEmptyArray(node.fields) - ? [ + isEmpty + ? "" + : [ indent([ softline, join([ifBreak("", ", "), softline], path.map(print, "fields")), ]), - ] - : "", + ], softline, ifBreak("", bracketSpace), "}", @@ -170,7 +170,7 @@ function genericPrint(path, options, print) { return [ "@", print("name"), - node.arguments.length > 0 + isNonEmptyArray(node.arguments) ? group([ "(", indent([ @@ -223,7 +223,10 @@ function genericPrint(path, options, print) { } parts.push(" ", print("name")); - if (!kind.startsWith("InputObjectType") && node.interfaces.length > 0) { + if ( + !kind.startsWith("InputObjectType") && + isNonEmptyArray(node.interfaces) + ) { parts.push( " implements ", indent([group([join([" &", line], path.map(print, "interfaces"))])]), @@ -232,7 +235,7 @@ function genericPrint(path, options, print) { parts.push(printDirectives(path, print)); - if (node.fields.length > 0) { + if (isNonEmptyArray(node.fields)) { parts.push([ " {", indent([ @@ -251,7 +254,7 @@ function genericPrint(path, options, print) { return [ printDescription(path, options, print), print("name"), - node.arguments.length > 0 + isNonEmptyArray(node.arguments) ? group([ "(", indent([ @@ -276,7 +279,7 @@ function genericPrint(path, options, print) { "directive ", "@", print("name"), - node.arguments.length > 0 + isNonEmptyArray(node.arguments) ? group([ "(", indent([ @@ -311,7 +314,7 @@ function genericPrint(path, options, print) { "enum ", print("name"), printDirectives(path, print), - node.values.length > 0 + isNonEmptyArray(node.values) ? [ " {", indent([ @@ -345,7 +348,7 @@ function genericPrint(path, options, print) { return [ "extend schema", printDirectives(path, print), - ...(node.operationTypes.length > 0 + ...(isNonEmptyArray(node.operationTypes) ? [ " {", indent([ @@ -367,7 +370,7 @@ function genericPrint(path, options, print) { "schema", printDirectives(path, print), " {", - node.operationTypes.length > 0 + isNonEmptyArray(node.operationTypes) ? indent([ hardline, join( @@ -404,7 +407,7 @@ function genericPrint(path, options, print) { "union ", print("name"), printDirectives(path, print), - node.types.length > 0 + isNonEmptyArray(node.types) ? [ " =", ifBreak("", " "), @@ -442,7 +445,7 @@ function genericPrint(path, options, print) { function printDirectives(path, print) { const { node } = path; - if (node.directives.length === 0) { + if (!isNonEmptyArray(node.directives)) { return ""; } diff --git a/src/language-graphql/visitor-keys.js b/src/language-graphql/visitor-keys.js index 1c8b081b8..8245d4145 100644 --- a/src/language-graphql/visitor-keys.js +++ b/src/language-graphql/visitor-keys.js @@ -1,4 +1,4 @@ -import { QueryDocumentKeys as graphqlVisitorKeys } from "graphql/language/ast.mjs"; +import { QueryDocumentKeys as graphqlVisitorKeys } from "graphql/language/ast"; const visitorKeys = { ...graphqlVisitorKeys }; @@ -13,4 +13,10 @@ for (const kind of [ delete visitorKeys[kind]; } +// Not supported yet +visitorKeys.FragmentSpread = visitorKeys.FragmentSpread.filter( + (key) => key !== "arguments", +); +delete visitorKeys.FragmentArgument; + export default visitorKeys; diff --git a/yarn.lock b/yarn.lock index 997b46265..a388221e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5239,10 +5239,10 @@ __metadata: languageName: node linkType: hard -"graphql@npm:16.14.1": - version: 16.14.1 - resolution: "graphql@npm:16.14.1" - checksum: 10/8e506bdd2a0dac666e3de82461bd3cf337335b9c0a9a209756a4d20c481393a4f664084474ccc1ccd22a1fae174a69695ce4154a59d2b6e1c0de0b2cfc992ca8 +"graphql@npm:17.0.0-rc.0": + version: 17.0.0-rc.0 + resolution: "graphql@npm:17.0.0-rc.0" + checksum: 10/cb23267a03f556ded9072f4307b445aa82239753d46bd33749be7527db29bd9e956937ed0eda0f949e8443108a8673903ff6626ce7e0ce9d835d7cfb0cb992bc languageName: node linkType: hard @@ -8140,7 +8140,7 @@ __metadata: get-stdin: "npm:9.0.0" gfm-test-suite: "npm:0.0.2" globals: "npm:17.6.0" - graphql: "npm:16.14.1" + graphql: "npm:17.0.0-rc.0" hermes-parser: "npm:0.36.1" html-element-attributes: "npm:3.5.0" html-ua-styles: "npm:0.3.1"