GraphQL Query Runs Sucessfully One Time and Fails To Run Again using Apollo and AWS AppSync

佐手、 提交于 2019-12-23 02:44:29

问题


I'm using the basic client configuration from the example on the first page of https://github.com/awslabs/aws-mobile-appsync-sdk-js repo:

const client = new AWSAppSyncClient({
  url: appSyncConfig.graphqlEndpoint,
  region: appSyncConfig.region,
  auth: {
    type: appSyncConfig.authenticationType,
    apiKey: appSyncConfig.apiKey,
  }
});

But without the <Rehydrated> component, and with a Redux <Provider> component. The highest level parent component is wrapped like this:

<Provider store={store}>
  <ApolloProvider client={client}>
    <App/>
  </ApolloProvider>
</Provider>

I've tried swapping the order for the Provider and ApolloProvider, but that did not change the result.

The problem is that the query runs successfully one time but, doesn't run again. The AppSync's CloudWatch logs show the initial successful query, but show no further query attempts. That leads me to believe that the problem is due to something on the client.

I've set the fetchPolicy on the query to 'network-only' with no results:

const mapDataToProps = graphql(GET_ALL_STORIES, {
  name: 'getAllStories',
  options: { fetchPolicy: 'network-only' }
});

I've confirmed that the named query "getAllStories" does actually exist on the component by inspecting the component in the Chrome debugger. The query props NetworkStatus and loading properties remain at 1 and true the entire time, and no response is ever received.

I am currently using the following versions of relevant libraries: aws-appsync: 1.0.17 Apollo-client: 2.2.8 react-Apollo: 2.1.3 redux: 3.6.0

Edit Additional information. This is happening in a react-native program created with Expo. Reloading the program by shaking the device and selecting "Reload" results in the above behavior. However, restarting Expo, and running the program again causes the query to be refetched as desired.

来源:https://stackoverflow.com/questions/50099028/graphql-query-runs-sucessfully-one-time-and-fails-to-run-again-using-apollo-and

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!