Support directives on directive definitions in GraphQL (#19171)
This commit is contained in:
1 parent
afb9c080bd
commit
5adf567676
7 files changed
+66
-6
No files matched your search
@@ -0,0 +1,17 @@
|
||||
#### Support directives on directive definitions (#19171 by @YBJ0000)
|
||||
|
||||
[Directives on directive definitions](https://github.com/graphql/graphql-js/pull/4521) (and `extend directive` extensions) are now supported.
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```gql
|
||||
# Input
|
||||
directive @a @b on QUERY
|
||||
extend directive @a @b
|
||||
|
||||
# Prettier stable
|
||||
Error: Syntax Error: Expected "on", found "@".
|
||||
|
||||
# Prettier main
|
||||
directive @a @b on QUERY
|
||||
extend directive @a @b
|
||||
```
|
||||
@@ -17,6 +17,7 @@ function parseComments(ast) {
|
||||
|
||||
const parseOptions = {
|
||||
allowLegacyFragmentVariables: true,
|
||||
experimentalDirectivesOnDirectiveDefinitions: true,
|
||||
};
|
||||
|
||||
function createParseError(error) {
|
||||
|
||||
@@ -290,11 +290,19 @@ function genericPrint(path, options, print) {
|
||||
")",
|
||||
])
|
||||
: "",
|
||||
printDirectives(path, print),
|
||||
node.repeatable ? " repeatable" : "",
|
||||
" on ",
|
||||
...join(" | ", path.map(print, "locations")),
|
||||
];
|
||||
|
||||
case "DirectiveExtension":
|
||||
return [
|
||||
"extend directive @",
|
||||
print("name"),
|
||||
printDirectives(path, print),
|
||||
];
|
||||
|
||||
case "EnumTypeExtension":
|
||||
case "EnumTypeDefinition":
|
||||
return [
|
||||
|
||||
@@ -13,10 +13,4 @@ for (const kind of [
|
||||
delete visitorKeys[kind];
|
||||
}
|
||||
|
||||
// Not supported yet
|
||||
visitorKeys.DirectiveDefinition = visitorKeys.DirectiveDefinition.filter(
|
||||
(key) => key !== "directives",
|
||||
);
|
||||
delete visitorKeys.DirectiveExtension;
|
||||
|
||||
export default visitorKeys;
|
||||
@@ -42,3 +42,30 @@ directive @a(as: String = 1) on QUERY
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
exports[`directives-on-directive-definitions.graphql format 1`] = `
|
||||
====================================options=====================================
|
||||
parsers: ["graphql"]
|
||||
printWidth: 80 (default) |
|
||||
=====================================input======================================
|
||||
directive @a @b on QUERY
|
||||
directive @a(x: Int) @b @c on QUERY
|
||||
directive @a @b repeatable on QUERY
|
||||
directive @a(x: Int) @b repeatable on QUERY | MUTATION
|
||||
directive @a @b(reason: "deprecated") on QUERY
|
||||
|
||||
extend directive @a @b
|
||||
extend directive @a @b @c
|
||||
|
||||
=====================================output=====================================
|
||||
directive @a @b on QUERY
|
||||
directive @a(x: Int) @b @c on QUERY
|
||||
directive @a @b repeatable on QUERY
|
||||
directive @a(x: Int) @b repeatable on QUERY | MUTATION
|
||||
directive @a @b(reason: "deprecated") on QUERY
|
||||
|
||||
extend directive @a @b
|
||||
extend directive @a @b @c
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -0,0 +1,8 @@
|
||||
directive @a @b on QUERY
|
||||
directive @a(x: Int) @b @c on QUERY
|
||||
directive @a @b repeatable on QUERY
|
||||
directive @a(x: Int) @b repeatable on QUERY | MUTATION
|
||||
directive @a @b(reason: "deprecated") on QUERY
|
||||
|
||||
extend directive @a @b
|
||||
extend directive @a @b @c
|
||||
@@ -1294,9 +1294,14 @@ exports[`visitor keys graphql 1`] = `
|
||||
"DirectiveDefinition": [
|
||||
"arguments",
|
||||
"description",
|
||||
"directives",
|
||||
"locations",
|
||||
"name",
|
||||
],
|
||||
"DirectiveExtension": [
|
||||
"directives",
|
||||
"name",
|
||||
],
|
||||
"Document": [
|
||||
"definitions",
|
||||
],
|
||||
|
||||
Reference in new issue
Block a user