From 4f958ddb683c1fceb1d162f58a5dc2957e26fe5d Mon Sep 17 00:00:00 2001 From: Jessica Mauerhan Date: Tue, 16 Aug 2022 15:05:32 -0400 Subject: [PATCH] fix: ensure default directives do not get replaced by custom directives (#27) * fix: ensure default directives do not get replaced by custom directives * style: fix imports --- src/FederatedSchema.php | 3 ++- test/SchemaTest.php | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/FederatedSchema.php b/src/FederatedSchema.php index 1704d07..af3682b 100644 --- a/src/FederatedSchema.php +++ b/src/FederatedSchema.php @@ -6,6 +6,7 @@ use GraphQL\Type\Schema; use GraphQL\Type\Definition\CustomScalarType; +use GraphQL\Type\Definition\Directive; use GraphQL\Type\Definition\ObjectType; use GraphQL\Type\Definition\UnionType; use GraphQL\Type\Definition\Type; @@ -63,7 +64,7 @@ class FederatedSchema extends Schema public function __construct($config) { $this->entityTypes = $this->extractEntityTypes($config); - $this->entityDirectives = Directives::getDirectives(); + $this->entityDirectives = array_merge(Directives::getDirectives(), Directive::getInternalDirectives()); $config = array_merge($config, $this->getEntityDirectivesConfig($config), $this->getQueryTypeConfig($config)); diff --git a/test/SchemaTest.php b/test/SchemaTest.php index 8f9b882..f41fefc 100644 --- a/test/SchemaTest.php +++ b/test/SchemaTest.php @@ -62,6 +62,12 @@ public function testDirectives() $this->assertArrayHasKey('external', $directives); $this->assertArrayHasKey('provides', $directives); $this->assertArrayHasKey('requires', $directives); + + // These are the default directives, which should not be replaced + // https://www.apollographql.com/docs/apollo-server/schema/directives#default-directives + $this->assertArrayHasKey('include', $directives); + $this->assertArrayHasKey('skip', $directives); + $this->assertArrayHasKey('deprecated', $directives); } public function testServiceSdl()