-
-
Notifications
You must be signed in to change notification settings - Fork 565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to allow printing of Schema Directives #638
Updates to allow printing of Schema Directives #638
Conversation
If anyone has any ideas on why the pipeline keeps failing on composer dependencies that would be great thanks. |
@Tyler-Gauch try again (eg. rebase on current master). I have just rebased my PR and it's all green. |
Thank you for the PR! But have you seen a discussion in #552 ? It is a bit more complicated than just printing directives. Long story short, we are waiting when this is resolved in So sadly, it is unlikely that this PR will make it into the master. I suggest following graphql/graphql-js#2020 and as soon as it is resolved - we can port the solution. |
@@ -1237,4 +1237,203 @@ interfaces: [__Type!] | |||
EOT; | |||
self::assertEquals($introspectionSchema, $output); | |||
} | |||
|
|||
public function testPrintSchemaDirectiveNoArgs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testPrintSchemaDirectiveNoArgs() | |
public function testPrintSchemaDirectiveNoArgs() : void |
self::assertEquals($exceptedSdl, $actual); | ||
} | ||
|
||
public function testPrintSchemaDirectiveWithStringArgs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testPrintSchemaDirectiveWithStringArgs() | |
public function testPrintSchemaDirectiveWithStringArgs() : void |
self::assertEquals($exceptedSdl, $actual); | ||
} | ||
|
||
public function testPrintSchemaDirectiveWithNumberArgs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testPrintSchemaDirectiveWithNumberArgs() | |
public function testPrintSchemaDirectiveWithNumberArgs() : void |
self::assertEquals($exceptedSdl, $actual); | ||
} | ||
|
||
public function testPrintSchemaDirectiveWithArrayArgs() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testPrintSchemaDirectiveWithArrayArgs() | |
public function testPrintSchemaDirectiveWithArrayArgs() : void |
$schema = BuildSchema::build($exceptedSdl); | ||
$actual = $this->printForTest($schema); | ||
|
||
self::assertEquals($exceptedSdl, $actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::assertEquals($exceptedSdl, $actual); | |
self::assertSame($exceptedSdl, $actual); |
self::assertEquals($exceptedSdl, $actual); | ||
} | ||
|
||
public function testPrintSchemaDirectiveOnInterface() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public function testPrintSchemaDirectiveOnInterface() | |
public function testPrintSchemaDirectiveOnInterface() : void |
$schema = BuildSchema::build($exceptedSdl); | ||
$actual = $this->printForTest($schema); | ||
|
||
self::assertEquals($exceptedSdl, $actual); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self::assertEquals($exceptedSdl, $actual); | |
self::assertSame($exceptedSdl, $actual); |
return $count > 0 ? (' ' . implode( | ||
' ', | ||
array_map( | ||
static function ($directive) : string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to add some type hint for $directive
?
$count = count($directives); | ||
} | ||
|
||
return $count > 0 ? (' ' . implode( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd invert the condition so else
is not hidden at the bottom: ' ' . $count === 0 ? '' : implode(
return ''; | ||
} | ||
|
||
if ($type->astNode instanceof ObjectTypeDefinitionNode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First two codnitions can be merged
@vladar Should we keep these PRs / issues open + add some label like |
@simPod I think it will be a separate PR anyway, so yeah, let's close this. |
Ahhhhhh I had not seen those other issues, good to know, thanks! |
Overview
I have been working to get a working Apollo Federation server set up using this library. In doing so one of the requirements of Apollo Federation is that you need to serve the printed schema via the
Query._service
field, however, Apollo Federation relys heavily on schema directives and the current SchemaPrinter doesn't print any schema directives although the library allows adding them.Problem
The current SchemaPrinter doesn't support printing Schema Directives
Example
Given schema:
SchemaPrinter::doPrint(...);
will print:
Notice the missing
@sd
onBar
.Solution
I added a piece of code similar to the interfaces printing in
printObject
which now prints Schema DirectivesTesting
Added test cases for: