GraphQL: Implement DirectiveDefinition (#2309)

master
Christopher Chedeau 2017-06-27 19:10:07 -07:00 committed by GitHub
parent fbf4c3a952
commit 51c7503dae
4 changed files with 63 additions and 0 deletions

View File

@ -236,6 +236,43 @@ function genericPrint(path, options, print) {
return concat([path.call(print, "name"), ": ", path.call(print, "type")]);
}
case "DirectiveDefinition": {
return concat([
"directive ",
"@",
path.call(print, "name"),
n.arguments.length > 0
? group(
concat([
"(",
indent(
concat([
softline,
join(
concat([ifBreak("", ", "), softline]),
path.map(print, "arguments")
)
])
),
softline,
")"
])
)
: "",
concat([" on ", join(", ", path.map(print, "locations"))])
]);
}
case "InputValueDefinition": {
return concat([
path.call(print, "name"),
": ",
path.call(print, "type"),
n.defaultValue ? concat([" = ", path.call(print, "defaultValue")]) : "",
printDirectives(path, print, n)
]);
}
case "FragmentSpread": {
return concat([
"...",

View File

@ -0,0 +1,20 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`directive_decl.graphql 1`] = `
directive @a on FIELD1
directive @a(as: String) on FIELD1
directive @a(as: String = 1) on FIELD1
directive @a(as: String, b: Int!) on FIELD1
directive @a(as: String! = 1 @deprecated) on FIELD1
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
directive @a on FIELD1
directive @a(as: String) on FIELD1
directive @a(as: String = 1) on FIELD1
directive @a(as: String, b: Int!) on FIELD1
directive @a(as: String! = 1 @deprecated) on FIELD1
`;

View File

@ -0,0 +1,5 @@
directive @a on FIELD1
directive @a(as: String) on FIELD1
directive @a(as: String = 1) on FIELD1
directive @a(as: String, b: Int!) on FIELD1
directive @a(as: String! = 1 @deprecated) on FIELD1

View File

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