[graphql] Add support for printing SchemaExtension nodes (#12519)

* Add support for printing SchemaExtension nodes

* Add changelog entry

* Lint

* Update 12519.md

Co-authored-by: fisker Cheung <lionkay@gmail.com>
This commit is contained in:
Trevor Scheerandfisker Cheung authored and GitHub committed 2022-03-27 00:59:04 +09:00
1 parent 63f1ee2c17
commit 570c3180b9
6 files changed
+74

No files matched your search

+17
View File
@@ -0,0 +1,17 @@
#### Add support for printing SchemaExtension nodes (#12519 by @trevor-scheer)
<!-- prettier-ignore -->
```graphql
# Input
extend schema { subscription: Subscription }
extend schema @directive
# Prettier stable
N/A - throws error
# Prettier main
extend schema {
subscription: Subscription
}
extend schema @directive
```
+23
View File
@@ -402,6 +402,29 @@ function genericPrint(path, options, print) {
];
}
case "SchemaExtension": {
return [
"extend schema",
printDirectives(path, print, node),
...(node.operationTypes.length > 0
? [
" {",
indent([
hardline,
join(
hardline,
path.call(
(opsPath) => printSequence(opsPath, options, print),
"operationTypes"
)
),
]),
hardline,
"}",
]
: []),
];
}
case "SchemaDefinition": {
return [
print("description"),
@@ -149,6 +149,10 @@ schema {
mutation: MutationType
}
extend schema @directive {
subscription: Subscription
}
"""
This is a description
of the \`Foo\` type.
@@ -271,6 +275,10 @@ schema {
mutation: MutationType
}
extend schema @directive {
subscription: Subscription
}
"""
This is a description
of the \`Foo\` type.
@@ -8,6 +8,10 @@ schema {
mutation: MutationType
}
extend schema @directive {
subscription: Subscription
}
"""
This is a description
of the `Foo` type.
@@ -13,6 +13,13 @@ schema {
subscription: Subscription
}
extend schema { subscription: Subscription }
# \`SchemaExtension\`s don't require any operation types and doesn't print
# curlies in their abscence.
extend schema
@directive
=====================================output=====================================
"""
Schema definition description
@@ -23,5 +30,13 @@ schema {
subscription: Subscription
}
extend schema {
subscription: Subscription
}
# \`SchemaExtension\`s don't require any operation types and doesn't print
# curlies in their abscence.
extend schema @directive
================================================================================
`;
@@ -4,3 +4,10 @@ schema {
mutation: Mutation
subscription: Subscription
}
extend schema { subscription: Subscription }
# `SchemaExtension`s don't require any operation types and doesn't print
# curlies in their abscence.
extend schema
@directive