From f96fe1ea5e91d2ea94ee8053559288353aec6702 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Jun 2017 18:22:04 -0700 Subject: [PATCH] Initial support for GraphQL ObjectTypeDefinition (#2305) It appears in some files inside of fb codebase --- src/printer-graphql.js | 15 +++++++++++++++ .../__snapshots__/jsfmt.spec.js.snap | 14 ++++++++++++++ tests/graphql_object_type_def/jsfmt.spec.js | 1 + .../object_type_def.graphql | 4 ++++ 4 files changed, 34 insertions(+) create mode 100644 tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap create mode 100644 tests/graphql_object_type_def/jsfmt.spec.js create mode 100644 tests/graphql_object_type_def/object_type_def.graphql diff --git a/src/printer-graphql.js b/src/printer-graphql.js index abace73ba..454529ac8 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -209,6 +209,21 @@ function genericPrint(path, options, print) { ]); } + case "ObjectTypeDefinition": { + return concat([ + "type ", + path.call(print, "name"), + " = {", + indent(concat([hardline, join(hardline, path.map(print, "fields"))])), + hardline, + "}" + ]); + } + + case "FieldDefinition": { + return concat([path.call(print, "name"), ": ", path.call(print, "type")]); + } + case "FragmentSpread": { return concat([ "...", diff --git a/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap b/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap new file mode 100644 index 000000000..f4fe9dad4 --- /dev/null +++ b/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap @@ -0,0 +1,14 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`object_type_def.graphql 1`] = ` +type FeedHomeStories { + debug_info: String + query_title: String +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type FeedHomeStories = { + debug_info: String + query_title: String +} + +`; diff --git a/tests/graphql_object_type_def/jsfmt.spec.js b/tests/graphql_object_type_def/jsfmt.spec.js new file mode 100644 index 000000000..335646fb2 --- /dev/null +++ b/tests/graphql_object_type_def/jsfmt.spec.js @@ -0,0 +1 @@ +run_spec(__dirname, { parser: "graphql" }); diff --git a/tests/graphql_object_type_def/object_type_def.graphql b/tests/graphql_object_type_def/object_type_def.graphql new file mode 100644 index 000000000..ce8c7eff7 --- /dev/null +++ b/tests/graphql_object_type_def/object_type_def.graphql @@ -0,0 +1,4 @@ +type FeedHomeStories { + debug_info: String + query_title: String +}