问题
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