diff --git a/src/printer-graphql.js b/src/printer-graphql.js index 821e5cd7..33540a0f 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -74,6 +74,7 @@ function genericPrint(path, options, print) { case "Field": { return group( concat([ + n.alias ? concat([path.call(print, "alias"), ": "]) : "", path.call(print, "name"), n.arguments.length > 0 ? group( @@ -113,6 +114,9 @@ function genericPrint(path, options, print) { case "BooleanValue": { return n.value ? "true" : "false"; } + case "NullValue": { + return "null"; + } case "Variable": { return concat(["$", path.call(print, "name")]); } diff --git a/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 00000000..00400b11 --- /dev/null +++ b/tests/graphql_kitchen_sink/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,113 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`kitchen_sink.graphql 1`] = ` +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id , + ... on User @defer { + field2 { + id , + alias: field1(first:10, after:$foo,) @include(if: $foo) { + id, + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo(size: $size, bar: $b, obj: {key: "value"}) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null), + query +} + +query { + field +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id + ... on User @defer { + field2 { + id + alias: field1(first: 10, after: $foo) @include(if: $foo) { + id + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo(size: $size, bar: $b, obj: { key: "value" }) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null) + query +} + +query { + field +} +`; diff --git a/tests/graphql_kitchen_sink/jsfmt.spec.js b/tests/graphql_kitchen_sink/jsfmt.spec.js new file mode 100644 index 00000000..335646fb --- /dev/null +++ b/tests/graphql_kitchen_sink/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "graphql" }); diff --git a/tests/graphql_kitchen_sink/kitchen_sink.graphql b/tests/graphql_kitchen_sink/kitchen_sink.graphql new file mode 100644 index 00000000..5f0900e8 --- /dev/null +++ b/tests/graphql_kitchen_sink/kitchen_sink.graphql @@ -0,0 +1,54 @@ +query queryName($foo: ComplexType, $site: Site = MOBILE) { + whoever123is: node(id: [123, 456]) { + id , + ... on User @defer { + field2 { + id , + alias: field1(first:10, after:$foo,) @include(if: $foo) { + id, + ...frag + } + } + } + ... @skip(unless: $foo) { + id + } + ... { + id + } + } +} + +mutation likeStory { + like(story: 123) @defer { + story { + id + } + } +} + +subscription StoryLikeSubscription($input: StoryLikeSubscribeInput) { + storyLikeSubscribe(input: $input) { + story { + likers { + count + } + likeSentence { + text + } + } + } +} + +fragment frag on Friend { + foo(size: $size, bar: $b, obj: {key: "value"}) +} + +{ + unnamed(truthy: true, falsey: false, nullish: null), + query +} + +query { + field +}