首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么AWSAppSyncClient抛出错误网络错误:在lambda脱机时缺少optimisticResponse?

为什么AWSAppSyncClient抛出错误网络错误:在lambda脱机时缺少optimisticResponse?
EN

Stack Overflow用户
提问于 2018-10-12 05:43:28
回答 1查看 415关注 0票数 0

兰巴人称之为AWSAppSync突变。它的行为是不稳定的。同时,它会抛出所提到的错误。

错误:网络错误:脱机时缺少optimisticResponse。

这是初始化AWSAppSyncClient客户端对象的代码段。

代码语言:javascript
复制
 client = new AWSAppSyncClient({
        url: settings.url,
        region: settings.region,
        auth: {
            type: type,
            apiKey: settings.apiKey,
        },
        disableOffline: false
    });

似乎在突变发生时,lambda和AppSync之间的连接就失去了。

代码语言:javascript
复制
 client.hydrated().then((client,error) => { 
         client.mutate({ 
                mutation: updateMutation, 
                variables: { 
                    ID: vehicle.VehicleID
             }
         });
 });

-在lambda中使用appsync的原因是进行突变,所有订阅者都会以muated.的形式获得更新。

详细错误日志

代码语言:javascript
复制
{ Error: Network error: Missing optimisticResponse while offline.
at new ApolloError (/var/task/node_modules/aws-appsync/node_modules/apollo-client/bundle.umd.js:124:32)
at Object.error (/var/task/node_modules/aws-appsync/node_modules/apollo-client/bundle.umd.js:1088:32)
at notifySubscription (/var/task/node_modules/zen-observable/lib/Observable.js:130:18)
at onNotify (/var/task/node_modules/zen-observable/lib/Observable.js:161:3)
at SubscriptionObserver.error (/var/task/node_modules/zen-observable/lib/Observable.js:220:7)
at notifySubscription (/var/task/node_modules/zen-observable/lib/Observable.js:130:18)
at flushSubscription (/var/task/node_modules/zen-observable/lib/Observable.js:112:5)
at /var/task/node_modules/zen-observable/lib/Observable.js:156:14
at /var/task/node_modules/zen-observable/lib/Observable.js:67:7
at <anonymous>
graphQLErrors: [],
networkError: Error: Missing optimisticResponse while offline.
at /var/task/node_modules/aws-appsync/lib/link/offline-link.js:80:35
at new Subscription (/var/task/node_modules/zen-observable/lib/Observable.js:179:34)
at Observable.subscribe (/var/task/node_modules/zen-observable/lib/Observable.js:258:14)
at /var/task/node_modules/aws-appsync/lib/client.js:151:55
at <anonymous>,
message: 'Network error: Missing optimisticResponse while offline.',
extraInfo: undefined }
EN

回答 1

Stack Overflow用户

发布于 2018-10-13 03:58:01

调用mutaion的正确方法是在突变方法中包含optimisticReponse选项,如下所示。

代码语言:javascript
复制
client.mutate({ 
                mutation: updateMutation, 
                variables: tempVehicle,
                optimisticResponse: () => ({ 
                    updateDslvehicleStateMutation: 
                    {
                        ID: tempVehicle.ID,
                        OPP: tempVehicle.OPP,
                        CDC: tempVehicle.CDC,
                        MND: tempVehicle.MND,
                        loc: tempVehicle.loc,
                        CSP: tempVehicle.CSP,
                        __typename: 'UpdateVehicleInput'
                    }
                })
            })

如果不能在变体方法中添加optimisticResponse,将无法在Appsync中执行突变。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52772966

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档