react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

MockedProvider does not return data when fetchPolicy is set to "cache-and-network"

Open eskimoblood opened this issue 9 years ago • 15 comments

MockedProvider does not return data when fetchPolicy is set to cache-and-network. When removing the fetchPolicy part from my graphql call, the test data are returned.

Version

  • apollo-client@<1.1.2r>
  • react-apollo@<1.4.2>

eskimoblood avatar Jun 14 '17 11:06 eskimoblood

Thanks for filing an issue @eskimoblood. Would you be able to provide a reproduction of this using the react-apollo-error-template?

helfer avatar Jun 14 '17 18:06 helfer

This issue has been automatically marked as stale becuase it has not had recent activity. It will be closed if not further activity occurs. Thank you for your contributions to React Apollo!

stale[bot] avatar Jul 05 '17 22:07 stale[bot]

Same issue. Try mounting a graphql component with fetchPolicy: 'cache-and-network wrapped in a <MockedProvider>.

derek-duncan avatar Jul 20 '17 20:07 derek-duncan

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

stale[bot] avatar Aug 12 '17 14:08 stale[bot]

I'm also having this issue, I get:

Network error: No more mocked responses for the query: query allPublications

When using 'cache-and-network' as fetchPolicy.

carlows avatar Aug 16 '17 04:08 carlows

Can you provide a reproduction we can run please?

stubailo avatar Aug 16 '17 05:08 stubailo

This issue has been automatically labled because it has not had recent activity. If you have not received a response from anyone, please mention the repository maintainer (most likely @jbaxleyiii). It will be closed if no further activity occurs. Thank you for your contributions to React Apollo!

stale[bot] avatar Sep 06 '17 05:09 stale[bot]

This issue has been automatically closed because it has not had recent activity after being marked as no recent activyt. If you belive this issue is still a problem or should be reopened, please reopen it! Thank you for your contributions to React Apollo!

stale[bot] avatar Sep 20 '17 05:09 stale[bot]

not a complete reproduction, but cache-only is also not working with a mock:

graphql(gql`
query {
  __schema {
    types {
      name
    }
  }
}`, {
  options: () => ({
    fetchPolicy: 'cache-only',
  }),
  props: ({ data }) => ({
    data: console.log(data) || data,
  }),
})

logs twice:

{ 
      refetch: [Function: bound ],
      fetchMore: [Function: bound ],
      updateQuery: [Function: bound ],
      startPolling: [Function: bound ],
      stopPolling: [Function: bound ],
      subscribeToMore: [Function: bound ],
      loading: false,
      networkStatus: 7,
      error: [Getter],
}

when changing to:

graphql(gql`
query {
  __schema {
    types {
      name
    }
  }
}`, {
  options: () => ({}),
  props: ({ data }) => ({
    data: console.log(data) || data,
  }),
})

it logs the second time:

{
      refetch: [Function: bound ],
      fetchMore: [Function: bound ],
      updateQuery: [Function: bound ],
      startPolling: [Function: bound ],
      stopPolling: [Function: bound ],
      subscribeToMore: [Function: bound ],
      loading: false,
      networkStatus: 7,
      error: [Getter],
      __schema: {...},
}

jbreckel avatar Sep 25 '17 15:09 jbreckel

@stubailo @helfer using what @jbreckel provided above were you able to reproduce this issue?

polmann avatar Nov 01 '17 20:11 polmann

Any update on this issue?

flpStrri avatar Nov 22 '18 21:11 flpStrri

I'm having this problem too when trying to update the cache with a MockedProvider.

vctormb avatar Dec 11 '18 23:12 vctormb

I'm also running into this issue when using a Query component with a cache-only fetchPolicy.

jozanza avatar Jan 16 '19 18:01 jozanza

The same to me

hashina avatar Feb 28 '19 11:02 hashina

Any way to get this issue re-opened? I'm seeing it too when using fetchPolicy: cache-only

kpruden avatar Mar 08 '19 19:03 kpruden