2016-12-23 2 views
0

Ich habe gerade arbeite bis zu dem Punkt in apollo/postgres/sequelize, meine ersten relationalen Datenbank-Schema/Abfrage/Resolver bekommen, wo es an der Zeit für die Resolver seiner Daten an den Client zurück. Offensichtlich habe ich die Daten nicht in der richtigen Form noch, wie es null auf dem Client kommt.Apollo: Form von Server-Antwort erforderlich?

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

AKTUELLE FORM DER REAKTION VON RESOLVER

Via console.log auf dem Server ausgeführt werden, bevor an den Client gesendet werden:

{ 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 ES SUCHT IN CHROM-DEV-TOOLS, WENN ES ZURÜCK KOMMT DER KUNDE

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

Kann mich jemand Punkt in Richtung zu sehen, was mit der Form der Server-Antwort falsch ist?

Antwort

0

ich alle Daten erhalten, mit Ausnahme der Anordnung von Userdata, an den Server, indem Sie den letzten then Block Wechsel zu:

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

Ich habe immer noch das Userdata auf den Server zu bekommen, aber das ist ein Thema für einen anderen Thread.