From 9cb50add5eec9d755e268e7510552ec2e0b1201b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adrian=20Zgorza=C5=82ek?= Date: Thu, 4 Apr 2019 13:47:05 +0100 Subject: [PATCH] graphql: Support variable directives. (#6020) --- CHANGELOG.unreleased.md | 42 ++++++++++++++----- package.json | 2 +- src/language-graphql/printer-graphql.js | 3 +- .../__snapshots__/jsfmt.spec.js.snap | 16 +++++++ .../variable_definitions.graphql | 8 ++++ yarn.lock | 12 +++--- 6 files changed, 65 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 3281eabcc8c6..3f98ee104564 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -239,31 +239,51 @@ Examples:
``` -- GraphQL: Support GraphQL fragment variables ([#6016] by [@adek05]) +- TypeScript: Support `readonly` operator ([#6027] by [@ikatyang]) + + + ```ts + // Input + declare const array: readonly number[]; + + // Output (Prettier stable) + // SyntaxError: ',' expected. + // Output (Prettier master) + declare const array: readonly number[]; + ``` + +- GraphQL: Support variable directives ([#6020] by [@adek05]) + + Upgrading to graphql-js 14.0 enables new GraphQL language feature - variable directives. Support for printing them is added along with the graphql-js version bump. + + ``` // Input - fragment F($var: Int) on Type { node } + query Q($variable: Int @directive) {node} // Output (Prettier stable) - // Fails to parse + query Q($variable: Int) { + node + } // Output (Prettier master) - fragment F($var: Int) on Type { - node + query Q($variable: Int @directive) { + node } ``` -- TypeScript: Support `readonly` operator ([#6027] by [@ikatyang]) +- GraphQL: Support GraphQL fragment variables ([#6016] by [@adek05]) - - ```ts + ``` // Input - declare const array: readonly number[]; + fragment F($var: Int) on Type { node } // Output (Prettier stable) - // SyntaxError: ',' expected. + // Fails to parse // Output (Prettier master) - declare const array: readonly number[]; + fragment F($var: Int) on Type { + node + } ``` diff --git a/package.json b/package.json index 918b9a5ab88b..8c07466de63a 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ "flow-parser": "0.84.0", "get-stream": "3.0.0", "globby": "6.1.0", - "graphql": "0.13.2", + "graphql": "14.2.0", "html-element-attributes": "2.0.0", "html-styles": "1.0.0", "html-tag-names": "1.1.2", diff --git a/src/language-graphql/printer-graphql.js b/src/language-graphql/printer-graphql.js index 787681374bed..70f0df48a4d9 100644 --- a/src/language-graphql/printer-graphql.js +++ b/src/language-graphql/printer-graphql.js @@ -266,7 +266,8 @@ function genericPrint(path, options, print) { path.call(print, "variable"), ": ", path.call(print, "type"), - n.defaultValue ? concat([" = ", path.call(print, "defaultValue")]) : "" + n.defaultValue ? concat([" = ", path.call(print, "defaultValue")]) : "", + printDirectives(path, print, n) ]); } diff --git a/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap index 110f4719727b..12ef7d37edfd 100644 --- a/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap @@ -24,6 +24,14 @@ query listslong($foo: [String ], $bar: [String!], $arg: [ Int! ]!, $veryLong ok } +query withvariabledirective($foo: Int @directive) { + ok +} + +query withvariabledirectives($foo: Int @directive @another) { + ok +} + =====================================output===================================== query short($foo: ComplexType, $site: Site = MOBILE, $nonNull: Int!) { hello @@ -52,5 +60,13 @@ query listslong( ok } +query withvariabledirective($foo: Int @directive) { + ok +} + +query withvariabledirectives($foo: Int @directive @another) { + ok +} + ================================================================================ `; diff --git a/tests/graphql_variable_definitions/variable_definitions.graphql b/tests/graphql_variable_definitions/variable_definitions.graphql index 85e42277f309..7c46d9e0768c 100644 --- a/tests/graphql_variable_definitions/variable_definitions.graphql +++ b/tests/graphql_variable_definitions/variable_definitions.graphql @@ -15,3 +15,11 @@ query lists($foo: [Int ], $bar: [Int!], $arg: [ Int! ]!) { query listslong($foo: [String ], $bar: [String!], $arg: [ Int! ]!, $veryLongName: [ Int! ]) { ok } + +query withvariabledirective($foo: Int @directive) { + ok +} + +query withvariabledirectives($foo: Int @directive @another) { + ok +} diff --git a/yarn.lock b/yarn.lock index 5dc16936a04e..194572700ab8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2701,11 +2701,12 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.2: version "4.1.11" resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" -graphql@0.13.2: - version "0.13.2" - resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270" +graphql@14.2.0: + version "14.2.0" + resolved "https://registry.yarnpkg.com/graphql/-/graphql-14.2.0.tgz#ff25813ad6d186f3975977d56bc2d2434871f3b9" + integrity sha512-dlFHRtxsL4sBy1C1e3v64IUd5ndZhAOHZ/z3Dr4Nm6+cvr9elrnz4BhMF9h9mRBBnhUCGLc4GH4xvPbKG6sUeA== dependencies: - iterall "^1.2.1" + iterall "^1.2.2" growly@^1.3.0: version "1.3.0" @@ -3330,9 +3331,10 @@ istanbul-reports@^1.3.0: dependencies: handlebars "^4.0.3" -iterall@^1.2.1: +iterall@^1.2.2: version "1.2.2" resolved "https://registry.yarnpkg.com/iterall/-/iterall-1.2.2.tgz#92d70deb8028e0c39ff3164fdbf4d8b088130cd7" + integrity sha512-yynBb1g+RFUPY64fTrFv7nsjRrENBQJaX2UL+2Szc9REFrSNm1rpSXHGzhmAy7a9uv3vlvgBlXnf9RqmPH1/DA== jest-changed-files@^23.4.2: version "23.4.2"