2016-12-23 5 views
0

私は、リゾルバがクライアントにデータを返す時点まで、最初のリレーショナルデータベースのスキーマ/クエリ/リゾルバをapollo/postgres/sequelizeで処理しています。明らかに、私はまだクライアント上でnullになるので、正しい形状のデータを持っていません。Apollo:サーバー応答の必要な形状?

QUERY

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 
       } 
      } 
`; 

RESOLVERからの応答が現在の形状

を介してクライアントに送信される前に、サーバー上で実行されている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' 
     } 
    } 
} 

HOWそれが戻ってくると、Chrome DEVツールの情報が表示されますCLIENT

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

FINAL THEN BLOCKはRESOLVER

.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; 
    }) 

の誰かは、サーバーの応答の形状と間違っているものを見ての方向に私を指すことができますか?

答えて

0
私は最後 thenブロックを変更することで、サーバへのUserDataの配列を除いて、すべてのデータを、得た

:私はまだUserDataをそのサーバーに取得する必要が

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

、それは話題です別のスレッドのために。