diff --git a/src/GraphQL/Types/BeamClaimType.php b/src/GraphQL/Types/BeamClaimType.php index 9bbc91f..843d90f 100644 --- a/src/GraphQL/Types/BeamClaimType.php +++ b/src/GraphQL/Types/BeamClaimType.php @@ -76,7 +76,7 @@ public function fields(): array 'type' => GraphQL::type('String!'), 'description' => __('enjin-platform-beam::type.beam_claim.field.code'), 'resolve' => fn ($claim) => $claim->code ? $claim->singleUseCode : '', - 'excludeFrom' => ['GetBeams'], + 'excludeFrom' => ['GetBeam', 'GetBeams'], ], 'identifierCode' => [ 'type' => GraphQL::type('String!'), @@ -94,7 +94,7 @@ public function fields(): array }, 'selectable' => false, 'is_relation' => false, - 'excludeFrom' => ['GetBeams'], + 'excludeFrom' => ['GetBeam', 'GetBeams'], ], ]; } diff --git a/tests/Feature/GraphQL/Queries/GetBeamTest.php b/tests/Feature/GraphQL/Queries/GetBeamTest.php index a9b50ea..25f3516 100644 --- a/tests/Feature/GraphQL/Queries/GetBeamTest.php +++ b/tests/Feature/GraphQL/Queries/GetBeamTest.php @@ -6,6 +6,7 @@ use Enjin\Platform\Beam\Tests\Feature\GraphQL\TestCaseGraphQL; use Enjin\Platform\Beam\Tests\Feature\Traits\SeedBeamData; use Enjin\Platform\Providers\Faker\SubstrateProvider; +use Illuminate\Support\Str; class GetBeamTest extends TestCaseGraphQL { @@ -157,4 +158,19 @@ public function test_it_will_fail_with_max_character_limit(): void $this->assertArraySubset(['code' => ['The code field must not be greater than 1024 characters.']], $response['error']); } + + public function test_it_hides_code_field_when_unauthenticated() + { + config([ + 'enjin-platform.auth' => 'basic_token', + 'enjin-platform.auth_drivers.basic_token.token' => Str::random(), + ]); + + $response = $this->graphql($this->method, ['code' => $this->beam->code], true); + $this->assertEquals('Cannot query field "code" on type "BeamClaim".', $response['error']); + + config([ + 'enjin-platform.auth' => null, + ]); + } } diff --git a/tests/Feature/GraphQL/Resources/GetBeam.graphql b/tests/Feature/GraphQL/Resources/GetBeam.graphql index 8938ad6..63faa04 100644 --- a/tests/Feature/GraphQL/Resources/GetBeam.graphql +++ b/tests/Feature/GraphQL/Resources/GetBeam.graphql @@ -24,6 +24,13 @@ query GetBeam($code: String!, $account: String) { frozen network } + claims { + edges { + node { + code + } + } + } claimsRemaining } }