GraphQL: Add support for printing operation names (#1992)

* Add support for printing GraphQL operation names

* Remove extra empty line at the end
master
Sashko Stubailo 2017-06-05 22:24:01 -07:00 committed by Christopher Chedeau
parent 76c5733b55
commit 8cb259eac7
5 changed files with 84 additions and 3 deletions

View File

@ -20,10 +20,15 @@ function genericPrint(path, options, print) {
switch (n.kind) {
case "Document": {
return concat([join(hardline, path.map(print, "definitions")), hardline]);
return join(concat([hardline, hardline]), path.map(print, "definitions"));
}
case "OperationDefinition": {
return path.call(print, "selectionSet");
return concat([
n.name === null ? "" : concat([n.operation, " "]),
path.call(print, "name"),
n.name ? " " : "",
path.call(print, "selectionSet")
]);
}
case "SelectionSet": {
return concat([

View File

@ -0,0 +1,52 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`fields.graphql 1`] = `
query MyFirstQuery {
hello
}
mutation
MyFirstMutation {
world
}
subscription, ThisIsASub, {
excellent
}
, query, ThisIsASub, {
excellent
}
query {
noName
}
{
noOperationType
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
query MyFirstQuery {
hello
}
mutation MyFirstMutation {
world
}
subscription ThisIsASub {
excellent
}
query ThisIsASub {
excellent
}
query {
noName
}
{
noOperationType
}
`;

View File

@ -0,0 +1,24 @@
query MyFirstQuery {
hello
}
mutation
MyFirstMutation {
world
}
subscription, ThisIsASub, {
excellent
}
, query, ThisIsASub, {
excellent
}
query {
noName
}
{
noOperationType
}

View File

@ -0,0 +1 @@
run_spec(__dirname, { parser: "graphql" });

View File

@ -12,5 +12,4 @@ exports[`hello.graphql 1`] = `
tagline
}
}
`;