You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or report a bug?
Report a bug
I'm trying to implement an optimistic response and cache update for one of my queries in my react native app so I can support offline use, but I'm running into an issue when using this workflow while the device still has service. I can see my mutation updater fire twice, as expected. The first time it fires it puts the optimistic response into the cache and the query component with the query I am updating re-renders correctly, as far as I can tell. The second time the updater fires (to update the cache with the actual server response) the part of the query I am updating comes out of the query component as null even though I have observed inside my updater the response from the server is identical to my optimistic response. I even find the query correctly after the update by querying the cache for it again inside the updater (see below).
This issue does not occur when I use import { ApolloClient } from 'apollo-client'; (I didn't install a different version, its the 2.4.6 version brought in by appsync). It only occurs when using import AWSAppSyncClient from 'aws-appsync';
Here's my code:
// SurveyQueryContainer.jsimportReactfrom'react';importPropTypesfrom'prop-types';import{Query}from'react-apollo';importSurveyNavigatorfrom'./SurveyNavigator';import{SurveyQueryContainerQuery}from'./graphql/SurveyQueryContainer';exportdefaultfunctionSurveyQueryContainer({ route, navigation }){const{ surveyTemplateId, surveyResponseId }=route.params;return(<Queryvariables={{ surveyTemplateId, surveyResponseId }}query={SurveyQueryContainerQuery}>{({ loading, error, data, refetch })=>{// data.getSurveyResponse is null after the 2nd mutation updater callreturn<SurveyNavigatorsurveyTemplate={data.getSurveyTemplate}surveyResponse={data.getSurveyResponse}/>;}}</Query>);}
// SurveyQueryContainer.jsimportgqlfrom'graphql-tag';import{SurveyNavigatorFragments}from'../SurveyNavigator';exportconstsurveyTemplateFragment=gql` fragment SurveyQueryContainer_surveyTemplate on SurveyTemplate { id name ...SurveyNavigator_surveyTemplate }${SurveyNavigatorFragments.surveyTemplate}`;exportconstsurveyResponseFragment=gql` fragment SurveyQueryContainer_surveyResponse on SurveyResponse { id ...SurveyNavigator_surveyResponse }${SurveyNavigatorFragments.surveyResponse}`;exportconstSurveyQueryContainerQuery=gql` query SurveyQueryContainerQuery($surveyTemplateId: ID!, $surveyResponseId: ID!) { getSurveyTemplate(id: $surveyTemplateId) { ...SurveyQueryContainer_surveyTemplate } getSurveyResponse(id: $surveyResponseId) { ...SurveyQueryContainer_surveyResponse } }${surveyTemplateFragment}${surveyResponseFragment}`;
// The mutation configimportgqlfrom'graphql-tag';import*asSurveyQueryContainerGqlfrom'../../Survey/graphql/SurveyQueryContainer';exportconstcreateSurveyResponseMutation=gql` mutation createSurveyResponse($input: CreateSurveyResponseInput!) { createSurveyResponse(input: $input) { id surveyTemplateId ...SurveyQueryContainer_surveyResponse } }${SurveyQueryContainerGql.surveyResponseFragment}`;exportconstgetCreateSurveyResponseMutationConfig=({ variables })=>({mutation: createSurveyResponseMutation,
variables,optimisticResponse: {createSurveyResponse: {
...variables.input,__typename: 'SurveyResponse',questionResponses: {__typename: 'ModelQuestionResponseConnection',items: []},},},update: (store,{data: { createSurveyResponse }})=>{// createSurveyResponse looks exactly as I expect during BOTH updatesletgetSurveyTemplate;try{getSurveyTemplate=store.readFragment({id: `SurveyTemplate:${createSurveyResponse.surveyTemplateId}`,fragment: SurveyQueryContainerGql.surveyTemplateFragment,fragmentName: 'SurveyQueryContainer_surveyTemplate',});}catch(e){console.warn("Could not read survey template from store",e);}store.writeQuery({query: SurveyQueryContainerGql.SurveyQueryContainerQuery,variables: {surveyTemplateId: createSurveyResponse.surveyTemplateId,surveyResponseId: createSurveyResponse.id,},data: {
getSurveyTemplate,getSurveyResponse: createSurveyResponse,},});// const result = store.readQuery({// query: SurveyQueryContainerGql.SurveyQueryContainerQuery,// variables: {// surveyTemplateId: createSurveyResponse.surveyTemplateId,// surveyResponseId: createSurveyResponse.id,// },// });//// console.log('ITS ALWAYS CORRECT HERE!', result.getSurveyResponse);},});
What is the expected behavior?
That data.getSurveyResponse is not null after the response from the server
Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
React Native + Expo (iOS and Android)
Do you want to request a feature or report a bug?
Report a bug
I'm trying to implement an optimistic response and cache update for one of my queries in my react native app so I can support offline use, but I'm running into an issue when using this workflow while the device still has service. I can see my mutation updater fire twice, as expected. The first time it fires it puts the optimistic response into the cache and the query component with the query I am updating re-renders correctly, as far as I can tell. The second time the updater fires (to update the cache with the actual server response) the part of the query I am updating comes out of the query component as
null
even though I have observed inside my updater the response from the server is identical to my optimistic response. I even find the query correctly after the update by querying the cache for it again inside the updater (see below).This issue does not occur when I use
import { ApolloClient } from 'apollo-client';
(I didn't install a different version, its the 2.4.6 version brought in by appsync). It only occurs when usingimport AWSAppSyncClient from 'aws-appsync';
Here's my code:
What is the expected behavior?
That
data.getSurveyResponse
is not null after the response from the serverWhich versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions?
React Native + Expo (iOS and Android)
Unknown if it works in other versions
The text was updated successfully, but these errors were encountered: