the-guild-org / the-guild-org/apollo-angular

Apollo Angular SSR use state transfer: not respect default cache policy `cache-first`, have to add manual on each request

Open
#1,765 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted
Dominant language
TypeScript
Stars
1.5k
Forks
309
Avg merge
1h 45m
Merged PRs (30d)
3

Description

Describe the bug

As Apollo Client describe, it default policy is cache-first which is not really understand why not working on apollo angular universal if I use TransferState.

image

To Reproduce
Steps to reproduce the behavior:

  • add SSR and apollo-angular Store rehydration#
  • make request, it cached on server, check the request, it still make the request to server on client again.
  • console.log(this.apollo.client.cache.readQuery(query)) can see the cache result still here.
  • add cache-first to the query. Client apollo happy now and don't make request.

Expected behavior

  • I do not need to add cache-first on every request.
    I don't know is that by design or miss take. the Apollo Angular change it?
    if it by design. we should note the developer. "You should add fetchPolicy: 'cache-first' if you want your query read the cache from
    on the document.

Environment:

dependencies:
@angular/cli 13.1.2
@angular/core 13.2.1
@apollo/client 3.5.8
apollo-angular 3.0.0
graphql 15.8.0
typescript 4.5.4

Additional context

I'm willing to check source code. I already look in source code and don't find that Apollo Angular change anything relevant to fetchPolicy. I still cannot find the reason. I can make a PR which have some test case if you like. or an other PR for document if you think we need notice developer should add cache-first if you want to cache.
BTW, what is the default cache policy of Apollo Angular? did I miss something?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the SSR store rehydration documentation and trace the server cache and client request sequence described in the reproduction. Compare the reported default fetch policy with Apollo Client behavior; done means confirming whether this is an Apollo Angular bug and adding a regression test, or documenting when cache-first is required.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, graphql, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.