From fbf4c3a952435836ad9ba34b44b9fdb307d5c6de Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Tue, 27 Jun 2017 18:51:56 -0700 Subject: [PATCH] GraphQL: Support object definition implements (#2307) --- src/printer-graphql.js | 11 +++++++++-- .../__snapshots__/jsfmt.spec.js.snap | 9 +++++++++ tests/graphql_object_type_def/implements.graphql | 2 ++ 3 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 tests/graphql_object_type_def/implements.graphql diff --git a/src/printer-graphql.js b/src/printer-graphql.js index 838062fad..a43f0c726 100644 --- a/src/printer-graphql.js +++ b/src/printer-graphql.js @@ -214,12 +214,19 @@ function genericPrint(path, options, print) { } case "ObjectTypeDefinition": { - const parent = path.getParentNode(); return concat([ "type ", path.call(print, "name"), + n.interfaces && n.interfaces.length > 0 + ? concat([" implements ", join(", ", path.map(print, "interfaces"))]) + : "", + printDirectives(path, print, n), " {", - indent(concat([hardline, join(hardline, path.map(print, "fields"))])), + n.fields && n.fields.length > 0 + ? indent( + concat([hardline, join(hardline, path.map(print, "fields"))]) + ) + : "", hardline, "}" ]); 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 048bc3eaf..14a33e43c 100644 --- a/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap +++ b/tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap @@ -11,6 +11,15 @@ extend type Feedback { `; +exports[`implements.graphql 1`] = ` +type VRMConversation implements Node, Entity @foo { +} +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +type VRMConversation implements Node, Entity @foo { +} + +`; + exports[`object_type_def.graphql 1`] = ` type FeedHomeStories { debug_info: String diff --git a/tests/graphql_object_type_def/implements.graphql b/tests/graphql_object_type_def/implements.graphql new file mode 100644 index 000000000..62e65f891 --- /dev/null +++ b/tests/graphql_object_type_def/implements.graphql @@ -0,0 +1,2 @@ +type VRMConversation implements Node, Entity @foo { +}