Skip to content

Commit

Permalink
graphql: Support variable directives. (prettier#6020)
Browse files Browse the repository at this point in the history
  • Loading branch information
adek05 authored and duailibe committed Apr 4, 2019
1 parent 7c9823f commit 9cb50ad
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 18 deletions.
42 changes: 31 additions & 11 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,31 +239,51 @@ Examples:
<div *ngIf="isRendered | async"></div>
```
- GraphQL: Support GraphQL fragment variables ([#6016] by [@adek05])
- TypeScript: Support `readonly` operator ([#6027] by [@ikatyang])
<!-- prettier-ignore -->
```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.
<!-- prettier-ignore -->
```
// 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])
<!-- prettier-ignore -->
```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
}
```
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/language-graphql/printer-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -52,5 +60,13 @@ query listslong(
ok
}
query withvariabledirective($foo: Int @directive) {
ok
}
query withvariabledirectives($foo: Int @directive @another) {
ok
}
================================================================================
`;
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
12 changes: 7 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"

[email protected]:
version "0.13.2"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-0.13.2.tgz#4c740ae3c222823e7004096f832e7b93b2108270"
[email protected]:
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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 9cb50ad

Please sign in to comment.