diff --git a/CHANGELOG.md b/CHANGELOG.md index a83e50ef2..886fb48d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,11 @@ You can find and compare releases at the [GitHub release page](https://github.co ## Unreleased -- Allow `@show`, `@hide` and `@feature` directive to be used on types, arguments and input types. https://github.com/nuwave/lighthouse/pull/2638 +## v6.46.0 + +### Added + +- Allow `@show`, `@hide`, and `@feature` directives to be used on types, arguments and input types https://github.com/nuwave/lighthouse/pull/2638 ## v6.45.1 diff --git a/docs/6/digging-deeper/feature-toggles.md b/docs/6/digging-deeper/feature-toggles.md index 6d371ac3c..fe4e56587 100644 --- a/docs/6/digging-deeper/feature-toggles.md +++ b/docs/6/digging-deeper/feature-toggles.md @@ -1,6 +1,6 @@ # Feature Toggles -Lighthouse allows you to conditionally show or hide elements of your schema. +Lighthouse allows you to conditionally show or hide elements (fields, types, arguments or input fields) of your schema. ## @show and @hide @@ -27,8 +27,8 @@ type Query { ## @feature -The [@feature](../api-reference/directives.md#feature) directive allows to include fields in the schema depending -on a [Laravel Pennant](https://laravel.com/docs/pennant) feature. +The [@feature](../api-reference/directives.md#feature) directive allows to include fields, types, arguments, or input fields in the schema +depending on whether a [Laravel Pennant](https://laravel.com/docs/pennant) feature is active. For example, you might want a new experimental field only to be available when the according feature is active: @@ -57,6 +57,22 @@ type Query { } ``` +## Conditional Type Inclusion + +When you conditionally include a type using [@show](../api-reference/directives.md#show), [@hide](../api-reference/directives.md#hide) or [@feature](../api-reference/directives.md#feature), +any fields using it must also be conditionally included. +If the type is omitted but still used somewhere, the schema will be invalid. + +```graphql +type ExperimentalType @feature(name: "new-api") { + field: String! +} + +type Query { + experimentalField: ExperimentalType @feature(name: "new-api") +} +``` + ## Interaction With Schema Cache [@show](../api-reference/directives.md#show) and [@hide](../api-reference/directives.md#hide) work by manipulating the schema. diff --git a/docs/master/digging-deeper/feature-toggles.md b/docs/master/digging-deeper/feature-toggles.md index 0af41f38a..fe4e56587 100644 --- a/docs/master/digging-deeper/feature-toggles.md +++ b/docs/master/digging-deeper/feature-toggles.md @@ -27,8 +27,8 @@ type Query { ## @feature -The [@feature](../api-reference/directives.md#feature) directive allows to include fields, types, arguments or input fields, in the schema depending -on a [Laravel Pennant](https://laravel.com/docs/pennant) feature. +The [@feature](../api-reference/directives.md#feature) directive allows to include fields, types, arguments, or input fields in the schema +depending on whether a [Laravel Pennant](https://laravel.com/docs/pennant) feature is active. For example, you might want a new experimental field only to be available when the according feature is active: @@ -59,8 +59,9 @@ type Query { ## Conditional Type Inclusion -When you conditionally include a type, using [@show](../api-reference/directives.md#show), [@hide](../api-reference/directives.md#hide) or [@feature](../api-reference/directives.md#feature), any fields using it must -also be conditionally included, otherwise the schema might be invalid in case the type is missing. +When you conditionally include a type using [@show](../api-reference/directives.md#show), [@hide](../api-reference/directives.md#hide) or [@feature](../api-reference/directives.md#feature), +any fields using it must also be conditionally included. +If the type is omitted but still used somewhere, the schema will be invalid. ```graphql type ExperimentalType @feature(name: "new-api") { diff --git a/tests/Unit/Schema/Directives/HideDirectiveTest.php b/tests/Unit/Schema/Directives/HideDirectiveTest.php index fbcc0e448..160277957 100644 --- a/tests/Unit/Schema/Directives/HideDirectiveTest.php +++ b/tests/Unit/Schema/Directives/HideDirectiveTest.php @@ -118,7 +118,8 @@ public function testHiddenInputField(): void } '; - $types = $this->graphQL($introspectionQuery)->json('data.__schema.types'); + $types = $this->graphQL($introspectionQuery) + ->json('data.__schema.types'); $input = array_filter($types, fn (array $type): bool => $type['name'] === 'Input');