Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
spawnia committed Dec 4, 2024
1 parent e259164 commit 50ff357
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 19 additions & 3 deletions docs/6/digging-deeper/feature-toggles.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -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:

Expand Down Expand Up @@ -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.
Expand Down
9 changes: 5 additions & 4 deletions docs/master/digging-deeper/feature-toggles.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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") {
Expand Down
3 changes: 2 additions & 1 deletion tests/Unit/Schema/Directives/HideDirectiveTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit 50ff357

Please sign in to comment.