0

我刚刚让我的第一个关系数据库模式/查询/解析器在 apollo/postgres/sequelize 中工作,直到解析器将数据返回给客户端的时候。显然我还没有正确形状的数据,因为它在客户端上显示为空。

询问

const CREATE_APPT_MUTATION = gql`
            mutation createAPPT ($originatingUserID: String!, $apptWithUserID: String!, $apptDateTime: String!, $apptNotes: String!, $apptTitle: String!){
                createAPPT(originatingUserID: $originatingUserID, apptWithUserID: $apptWithUserID, apptDateTime: $apptDateTime, apptNotes: $apptNotes, apptTitle: $apptTitle){
                    originatingUserID
                    apptWithUserID
                    apptDateTime
                    apptNotes
                    apptTitle
                }
            }
`;

解析器的当前响应形状

通过在服务器上运行的 console.log,在发送到客户端之前:

{ data: 
   { __typename: 'Mutation',
     createAPPT: 
      { id: '76',
        originatingUserID: 'DsmkoaYPeAumREsqC',
        apptWithUserID: '9W95z8A7Y6i34buk7',
        apptDateTime: '2016-12-24T02:48:50.000Z',
        apptTitle: 'Appointment with Benedict Sama',
        apptNotes: 'asdf',
        createdAt: Fri Dec 23 2016 10:49:12 GMT-0800 (PST),
        updatedAt: Fri Dec 23 2016 10:49:12 GMT-0800 (PST),
        UserData: [Object],
        __typename: 'Appts' 
        } 
    } 
}

当它返回给客户端时,它在 Chrome 开发工具中的外观

mutationResult: Object
    data: Object
        createAPPT: Object
            __typename: "Appts"
            apptDateTime: null
            apptNotes: null
            apptTitle: null
            apptWithUserID: null
            originatingUserID: null
        __proto__: Object
    __proto__: Object
__proto__: Object

解析器中的最后THEN一块

.then(apptWithJoinedData => {
        //package up the results in the way that the client is expecting
        const apptDataValues = apptWithJoinedData[0].dataValues;
        apptDataValues.__typename = "Appts";
        var serverResponse = {};
        serverResponse.data = {};
        serverResponse.data.__typename = 'Mutation';
        serverResponse.data.createAPPT = apptDataValues;

        // publish subscription notification
        debugger;
        console.log(serverResponse);
        pubsub.publish('APPTAdded', serverResponse);
        return serverResponse;
    })

有人可以指点我看看服务器响应的形状有什么问题吗?

4

1 回答 1

0

我通过将最后一个then块更改为:

            .then(apptWithJoinedData => {
                 // publish subscription notification
                debugger;
                console.log('createAPPT cp#2');
                console.log(apptWithJoinedData);
                pubsub.publish('APPTAdded', apptWithJoinedData);
                return apptWithJoinedData;
            })

我仍然必须将该 UserData 发送到服务器,但这是另一个线程的主题。

于 2016-12-24T08:01:26.810 回答