From 14caabd6356fc582582fb83b8a911d99cb8548e0 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Jun 2017 19:49:59 -0700 Subject: [PATCH] GraphQL: Print arguments for FieldDefinition (#2314) --- src/printer-graphql.js | 24 ++++++++++++++++++- .../__snapshots__/jsfmt.spec.js.snap | 11 +++++++++ .../graphql_object_type_def/arguments.graphql | 3 +++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 tests/graphql_object_type_def/arguments.graphql diff --git a/src/printer-graphql.js b/src/printer-graphql.js index 999a55af7..51e433e17 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -233,7 +233,29 @@ function genericPrint(path, options, print) { } case "FieldDefinition": { - return concat([path.call(print, "name"), ": ", path.call(print, "type")]); + return concat([ + path.call(print, "name"), + n.arguments.length > 0 + ? group( + concat([ + "(", + indent( + concat([ + softline, + join( + concat([ifBreak("", ", "), softline]), + path.map(print, "arguments") + ) + ]) + ), + softline, + ")" + ]) + ) + : "", + ": ", + path.call(print, "type") + ]); } case "DirectiveDefinition": { diff --git a/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap index b4bbbb61b..f72dbd64b 100644 --- a/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap @@ -1,5 +1,16 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`arguments.graphql 1`] = ` +type Video { + playable_url(quality: String, preferred: String): Url +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type Video { + playable_url(quality: String, preferred: String): Url +} + +`; + exports[`extend.graphql 1`] = ` extend type Feedback { custom_int: Int diff --git a/tests/graphql_object_type_def/arguments.graphql b/tests/graphql_object_type_def/arguments.graphql new file mode 100644 index 000000000..1d5e903d9 --- /dev/null +++ b/tests/graphql_object_type_def/arguments.graphql @@ -0,0 +1,3 @@ +type Video { + playable_url(quality: String, preferred: String): Url +}