diff --git a/docs/6/federation/getting-started.md b/docs/6/federation/getting-started.md index 9074497dc4..979894c359 100644 --- a/docs/6/federation/getting-started.md +++ b/docs/6/federation/getting-started.md @@ -28,8 +28,9 @@ See [the Apollo documentation on federated directives](https://www.apollographql ```graphql extend schema @link( - url: "https://specs.apollo.dev/federation/v2.3" + url: "https://specs.apollo.dev/federation/v2.9" import: [ + "@authenticated" "@composeDirective" "@extends" "@external" @@ -37,8 +38,10 @@ extend schema "@interfaceObject" "@key" "@override" + "@policy" "@provides" "@requires" + "@requiresScopes" "@shareable" "@tag" ] diff --git a/src/Federation/Directives/AuthenticatedDirective.php b/src/Federation/Directives/AuthenticatedDirective.php new file mode 100644 index 0000000000..c735075bd4 --- /dev/null +++ b/src/Federation/Directives/AuthenticatedDirective.php @@ -0,0 +1,32 @@ +assertStringContainsString('type SimplePaginatorInfo @shareable {', $sdl); } + public function testServiceQueryShouldReturnFederationV2AccessControlDirectives(): void + { + $schemaExtension = /** @lang GraphQL */ <<<'GRAPHQL' + extend schema @link(url: "https://specs.apollo.dev/federation/v2.9", import: ["@key", "@authenticated", "@requiresScopes", "@policy"]) + GRAPHQL; + + $typeUser = /** @lang GraphQL */ <<<'GRAPHQL' + type User @key(fields: "id") @authenticated @requiresScopes(scopes: [["profile.read"], ["admin"]]) @policy(policies: [["read:user"], ["admin"]]) { + id: ID! + email: String! @authenticated @requiresScopes(scopes: [["email.read"]]) @policy(policies: [["email_policy"]]) + } + GRAPHQL; + + $this->schema = "{$schemaExtension} {$typeUser}"; + + $sdl = $this->_serviceSdl(); + + $this->assertSdlContainsString($schemaExtension, $sdl); + $this->assertStringContainsString('type User @key(fields: "id") @authenticated @requiresScopes(scopes: [["profile.read"], ["admin"]]) @policy(policies: [["read:user"], ["admin"]]) {', $sdl); + $this->assertStringContainsString('email: String! @authenticated @requiresScopes(scopes: [["email.read"]]) @policy(policies: [["email_policy"]])', $sdl); + } + private function _serviceSdl(): string { $response = $this->graphQL(/** @lang GraphQL */ <<<'GRAPHQL'