Add GraphQL variable definition support (#1995)
parent
d679f235ed
commit
6d00644c78
|
@ -27,7 +27,24 @@ function genericPrint(path, options, print) {
|
|||
return concat([
|
||||
n.name === null ? "" : concat([n.operation, " "]),
|
||||
path.call(print, "name"),
|
||||
n.name ? " " : "",
|
||||
n.variableDefinitions && n.variableDefinitions.length
|
||||
? group(
|
||||
concat([
|
||||
"(",
|
||||
indent(
|
||||
concat([
|
||||
softline,
|
||||
join(
|
||||
concat([",", ifBreak("", " "), softline]),
|
||||
path.map(print, "variableDefinitions")
|
||||
)
|
||||
])
|
||||
),
|
||||
softline,
|
||||
") "
|
||||
])
|
||||
)
|
||||
: n.name ? " " : "",
|
||||
path.call(print, "selectionSet")
|
||||
]);
|
||||
}
|
||||
|
@ -74,10 +91,9 @@ function genericPrint(path, options, print) {
|
|||
case "StringValue": {
|
||||
return concat(['"', n.value, '"']);
|
||||
}
|
||||
case "IntValue": {
|
||||
return n.value;
|
||||
}
|
||||
case "FloatValue": {
|
||||
case "IntValue":
|
||||
case "FloatValue":
|
||||
case "EnumValue": {
|
||||
return n.value;
|
||||
}
|
||||
case "BooleanValue": {
|
||||
|
@ -112,6 +128,19 @@ function genericPrint(path, options, print) {
|
|||
]);
|
||||
}
|
||||
|
||||
case "NamedType": {
|
||||
return path.call(print, "name");
|
||||
}
|
||||
|
||||
case "VariableDefinition": {
|
||||
return concat([
|
||||
path.call(print, "variable"),
|
||||
": ",
|
||||
path.call(print, "type"),
|
||||
n.defaultValue ? concat([" = ", path.call(print, "defaultValue")]) : ""
|
||||
]);
|
||||
}
|
||||
|
||||
default:
|
||||
throw new Error("unknown graphql type: " + JSON.stringify(n.kind));
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`variable_definitions.graphql 1`] = `
|
||||
query short($foo:ComplexType, $site : Site = MOBILE) {
|
||||
hello
|
||||
}
|
||||
|
||||
query long($foo: ComplexType, $site: Float = 124241.12312,
|
||||
$bar: String = "Long string here", $arg: String = "Hello world!",,,,) {
|
||||
hello
|
||||
}
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
query short($foo: ComplexType, $site: Site = MOBILE) {
|
||||
hello
|
||||
}
|
||||
|
||||
query long(
|
||||
$foo: ComplexType,
|
||||
$site: Float = 124241.12312,
|
||||
$bar: String = "Long string here",
|
||||
$arg: String = "Hello world!"
|
||||
) {
|
||||
hello
|
||||
}
|
||||
`;
|
|
@ -0,0 +1 @@
|
|||
run_spec(__dirname, { parser: "graphql" });
|
|
@ -0,0 +1,8 @@
|
|||
query short($foo:ComplexType, $site : Site = MOBILE) {
|
||||
hello
|
||||
}
|
||||
|
||||
query long($foo: ComplexType, $site: Float = 124241.12312,
|
||||
$bar: String = "Long string here", $arg: String = "Hello world!",,,,) {
|
||||
hello
|
||||
}
|
Loading…
Reference in New Issue