-
-
Notifications
You must be signed in to change notification settings - Fork 468
Lighthouse Get Cache Key via php #2621
Unanswered
illusive-ch
asked this question in
Q&A
I have this
chatsPaginated(input: ChatsInput @spread): [Chat!] @guard @can(ability: "viewAny", model: "App\\Models\\Chat") @paginate( defaultCount: 10 builder: "App\\GraphQL\\Queries\\ChatsPaginatedQuery@builder" ) @cache(private: false) @cacheKey(fields: ["user_id"]) @orderBy(column: "chat_updated_at", direction: DESC)
However, if a user is trashed using $user->delete(), I would need to flush the cache for all chat lists the user belongs to. I can do this with an observer and job, but I need help getting the actual key used by Lighthouse.
Stored cache key: lighthouse:query:dcda0ee478e6abe7cee5043b3221241c75c1fb13e8993e42a5196591983d53c0
Here is the written test:
/** * @test */ public function when_a_user_deleted_does_not_show_chat() { $user = User::factory()->create(); $user2 = User::factory()->for($user->brand)->create(); $chat = Chat::factory()->create(['is_paid' => false]); $chat->users()->attach([$user->id, $user2->id]); $this->actingAs($user); $response = $this->graphQL(' query { chatsPaginated { data{ id users { id name } } } } ')->assertStatus(200); // Log cache keys after the query $this->assertCount(1, $response->json('data.chatsPaginated.data')); $user2->delete(); // Dump all cache keys again $response = $this->graphQL(' query { chatsPaginated { data{ id users { id name } } } ')->assertStatus(200); $this->assertCount(0, $response->json('data.chatsPaginated.data')); }
All reactions
Replies: 1 comment
You can get inspired by the implementation of @clearCache, see https://github.com/nuwave/lighthouse/blob/master/src/Cache/ClearCacheDirective.php.
All reactions
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment