Skip to content

Commit

Permalink
Initial support for GraphQL ObjectTypeDefinition (prettier#2305)
Browse files Browse the repository at this point in the history
It appears in some files inside of fb codebase
  • Loading branch information
vjeux authored Jun 28, 2017
1 parent 189027c commit f96fe1e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/printer-graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -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([
"...",
Expand Down
14 changes: 14 additions & 0 deletions tests/graphql_object_type_def/__snapshots__/jsfmt.spec.js.snap
Original file line number Diff line number Diff line change
@@ -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
}
`;
1 change: 1 addition & 0 deletions tests/graphql_object_type_def/jsfmt.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
run_spec(__dirname, { parser: "graphql" });
4 changes: 4 additions & 0 deletions tests/graphql_object_type_def/object_type_def.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type FeedHomeStories {
debug_info: String
query_title: String
}

0 comments on commit f96fe1e

Please sign in to comment.