apollographql / apollo

:rocket: Open source tools for GraphQL. Central repo for discussion.
https://www.apollographql.com
MIT License
2.61k stars 425 forks source link

How to configure fetchPolicy to network-only #82

Closed younisshah closed 7 years ago

younisshah commented 7 years ago

How can I set the fetchPolicy to network-only? I can't understand how to do it!

stubailo commented 7 years ago

Are you using React? If so, it's like this: http://dev.apollodata.com/react/api.html#graphql-query-options\.fetchPolicy

BTW the best place to ask questions is Stack Overflow with the apollo tag: http://stackoverflow.com/questions/tagged/apollo

younisshah commented 7 years ago

@stubailo Thanks for the quick reply. I'm using React Native. I had already checked the API doc for fetchPolicy but I couldn't get it to run. Can you please provide a simple example here? Much appreciated!

stubailo commented 7 years ago

I couldn't get it to run

Can you post the code you tried? Are you using the newest version of Apollo Client?

younisshah commented 7 years ago

@stubailo I have a use-case wherein I need access to ApolloClient so I used withApollo. Here is a snippet

let response = await apolloGraphQLClient.query({
                query: generateOTPQuery,
                variables: {"CountryCode": this.countryCode, "MobileNumber": this.mobileNumber},
                options: {fetchPolicy: 'network-only'}
            });

What am I doing wrong?

stubailo commented 7 years ago

ah - you don't need the extra options:

let response = await apolloGraphQLClient.query({
                query: generateOTPQuery,
                variables: {"CountryCode": this.countryCode, "MobileNumber": this.mobileNumber},
                fetchPolicy: 'network-only'
            });
younisshah commented 7 years ago

@stubailo I tried it as well, but it doesn't work! :(

helfer commented 7 years ago

@younisshah it would help if you followed the issue template and described exactly what you're doing (ideally with relevant code), what you expect to happen, and what you observed instead. "It doesn't work" isn't useful information for us to help you. You should instead tell us how you determined that "it's not working", i.e. tell us what you did, what you expected to happen, and what you saw instead.

semy commented 7 years ago

Hi,

the same is with me. "fetchPolicy" does not work, I get always the cached data until I reload the page.

export default connect(mapStateToProps)(reduxForm({
  form: 'eventform',
  destroyOnUnmount: false,
})(graphql(query, {
  options: (props) => ({
    forceFetch: true,
    fetchPolicy: 'network-only',
    variables: {
      eventId: props.eventId,
    },
  }),
})(new CSSModules(CreateEventFormPage1, styles, { allowMultiple: true }))));

Something wrong?

Thanks for your help!

helfer commented 7 years ago

@semy @younisshah I'm going to close this issue here, because this is a wrong repo. Please open an issue on react-apollo or Apollo Client, depending on which one you're using. Please also follow the issue template there and provide a clear description of what you're doing and what you're observing.

czert commented 7 years ago

Ran into the same issue, but an upgrade solved it: apollo-client@1.0.0-rc.9 and react-apollo@1.0.0-rc.3 refetch the component's query every time.

franciscorubin commented 7 years ago

Works for me on 1.0.0-rc.9, but stops working on 1.0.2