From e9045e4bcf7ab31f28e9a6344acbc3c4d0ca668e Mon Sep 17 00:00:00 2001 From: Tim Griesser Date: Thu, 8 Jun 2017 12:20:41 -0400 Subject: [PATCH] Support graphql NonNullType (#2060) --- src/printer-graphql.js | 7 +++++++ .../__snapshots__/jsfmt.spec.js.snap | 10 ++++++---- .../variable_definitions.graphql | 5 +++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/printer-graphql.js b/src/printer-graphql.js index a45c83d4..ec20e139 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -243,6 +243,13 @@ function genericPrint(path, options, print) { ); } + case "NonNullType": { + return concat([ + path.call(print, "type"), + "!" + ]); + } + default: throw new Error("unknown graphql type: " + JSON.stringify(n.kind)); } diff --git a/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap index 4dbf93c9..2eeca172 100644 --- a/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_variable_definitions/__snapshots__/jsfmt.spec.js.snap @@ -1,16 +1,17 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`variable_definitions.graphql 1`] = ` -query short($foo:ComplexType, $site : Site = MOBILE) { +query short($foo:ComplexType, $site : Site = MOBILE, $nonNull: Int!) { hello } query long($foo: ComplexType, $site: Float = 124241.12312, -$bar: String = "Long string here", $arg: String = "Hello world!",,,,) { +$bar: String = "Long string here", $arg: String = "Hello world!",,,,, +$nonNull: String!) { hello } ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -query short($foo: ComplexType, $site: Site = MOBILE) { +query short($foo: ComplexType, $site: Site = MOBILE, $nonNull: Int!) { hello } @@ -18,7 +19,8 @@ query long( $foo: ComplexType, $site: Float = 124241.12312, $bar: String = "Long string here", - $arg: String = "Hello world!" + $arg: String = "Hello world!", + $nonNull: String! ) { hello } diff --git a/tests/graphql_variable_definitions/variable_definitions.graphql b/tests/graphql_variable_definitions/variable_definitions.graphql index d50a2f1b..8c12db83 100644 --- a/tests/graphql_variable_definitions/variable_definitions.graphql +++ b/tests/graphql_variable_definitions/variable_definitions.graphql @@ -1,8 +1,9 @@ -query short($foo:ComplexType, $site : Site = MOBILE) { +query short($foo:ComplexType, $site : Site = MOBILE, $nonNull: Int!) { hello } query long($foo: ComplexType, $site: Float = 124241.12312, -$bar: String = "Long string here", $arg: String = "Hello world!",,,,) { +$bar: String = "Long string here", $arg: String = "Hello world!",,,,, +$nonNull: String!) { hello }