# @apollo/client local-only field is not resolved when working with service worker

**URL:** <https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016>\
**Category:** Client SDKs\
**Tags:** client\
**Created:** [December 3, 2023, 7:18pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016 "2023-12-03T19:18:24Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Crismon96](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/crismon96/32/4781_2.png) [@Crismon96](https://community.apollographql.com/u/Crismon96)\
**Post date:** [December 3, 2023, 7:18pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/1 "2023-12-03T19:18:24Z")

</div>

I have problems getting local-only fields via typePolicies to work in my app. My setup is the following:

This is one of my queries:

```auto
export const GET_ALL_DEBT_TOKENS = gql`
  query GetDebtTokens {
    getDebtTokens {
      totalSupplyUSD
      totalReserve
      totalReserve24hAgo

      token {
        address
        symbol
        priceUSD @client
        priceUSD24hAgo
      }
    }
  }
`;

```

And this is the config to resolve my local field:

```auto
export function CustomApolloProvider({ children }: PropsWithChildren<{}>) {
  const client = new ApolloClient({
    // TODO: replace with your own graphql server
    uri: 'https://flyby-router-demo.herokuapp.com/',

    cache: new InMemoryCache({
      typePolicies: {
        Token: {
          fields: {
            priceUSD: {
              read() {
                console.log('priceUSD read function is called');
                return 100;
              },
            },
          },
        },
      },
    }),
  });

  return <ApolloProvider client={client}>{children}</ApolloProvider>;
}

```

This is the relevant schema:

```auto

type Token {
  address: String! # contract address, used as id
  symbol: String!
  createdAt: String!
  #
  priceUSD24hAgo: Float!
  #
  isPoolToken: Boolean!
}

type DebtTokenMeta {
  token: Token!
  # borrower specific
  walletAmount: Float
  troveMintedAmount: Float
  stabilityLostAmount: Float
  stabilityCompoundAmount: Float

  # global
  stabilityDepositAPY: Float!
  totalDepositedStability: Float!
  totalReserve: Float!
  totalReserve24hAgo: Float!
  totalSupplyUSD: Float!
  totalSupplyUSD24hAgo: Float!
}

```

My dev server returns everything except the “priceUSD” field. I also never see that log in the console. I am wondering how I can mess up this simple get-started guide.  
The field marked with “@client” is not in the query to my Mock Service Worker. I wonder if it is the mock service worker that is causing the issue or a simple mistake by me.

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [December 4, 2023, 9:16am UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/2 "2023-12-04T09:16:02Z")

</div>

The `@client` annotation means “we get that from a `typePolicy`, don’t request this field from the server” so it seems correct that this will never be sent as part of your request - to the server or mock service worker.

I’m honestly not sure what problem you encounter in this case - could you please go into your actual problem a little more? What behaviour do you expect, and what do you see instead?

---

<div class="post-metadata">

**Author:** ![Crismon96](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/crismon96/32/4781_2.png) [@Crismon96](https://community.apollographql.com/u/Crismon96)\
**Post date:** [December 4, 2023, 12:31pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/3 "2023-12-04T12:31:24Z")

</div>

Thanks @lenz that you care about my issue.  
Yes, this far it is expected, that the field is left from the API request. It just doesn’t happen, that the typePolicy for my field is considered.

This is one of the responses I have:

```auto
{
  "token": {
    "id": "908fd53a-cb88-432b-8c2d-1fbcec500a8a",
    "address": "578b9a18-7b07-4028-8354-7861f78b22ea",
    "symbol": "CUP",
    "createdAt": "2023-09-07T16:13:40.183Z",
    "priceUSD24hAgo": 2467.94,
    "isPoolToken": false
  },
  "walletAmount": null,
  "troveMintedAmount": null,
  "stabilityLostAmount": null,
  "stabilityCompoundAmount": null,
  "totalDepositedStability": 4310.92,
  "totalReserve": 0,
  "totalReserve24hAgo": 0,
  "totalSupplyUSD": 11552.7,
  "totalSupplyUSD24hAgo": 16380.9,
  "stabilityDepositAPY": 0.1
}

```

This is not the response from the mock service worker but my logged value from `useQuery`. This is the symptom of the same issue that I “dont see the console.log from my typePolicy”. The typePolicy for “priceUSD” is not used to resolve the @client field somehow.

I have tried to follow the [guide](https://www.apollographql.com/docs/react/local-state/managing-state-with-field-policies/) on local-only fields to the best of my abilities.

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [December 4, 2023, 2:11pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/4 "2023-12-04T14:11:47Z")

</div>

Does your API response contain a `__typename`?  
Without that, the cache won’t be able to figure out if this is a `Token` instance.

If that’s the case: is `__typename` really `"Token"` here or some kind of inherited class?

---

<div class="post-metadata">

**Author:** ![Crismon96](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/crismon96/32/4781_2.png) [@Crismon96](https://community.apollographql.com/u/Crismon96)\
**Post date:** [December 4, 2023, 2:30pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/5 "2023-12-04T14:30:32Z")

</div>

Dude, that was it. I already added an id that was missing but I forgot about the typename. It often gets included when using Apollo tools :')  
Danke Mann, du bist mein Held des Tages!

---

<div class="post-metadata">

**Author:** ![lenz](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/lenz/32/4007_2.png) [@lenz](https://community.apollographql.com/u/lenz)\
**Post date:** [December 4, 2023, 2:35pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/6 "2023-12-04T14:35:57Z")

</div>

Bitte bitte - gern geschehen!

---

<div class="post-metadata">

**Author:** ![Justin\_Gonzalez](https://sea1.discourse-cdn.com/flex019/user_avatar/community.apollographql.com/justin_gonzalez/32/5359_2.png) [@Justin\_Gonzalez](https://community.apollographql.com/u/Justin_Gonzalez)\
**Post date:** [February 6, 2025, 8:47pm UTC](https://community.apollographql.com/t/apollo-client-local-only-field-is-not-resolved-when-working-with-service-worker/7016/8 "2025-02-06T20:47:51Z")

</div>


