2017-10-05 8 views
0

Im은 업데 이터를 돌연변이에 적용하려고하는데 잘 작동하지 않으면 'setValue가 함수가 아닙니다'라고 나와 내게 newEvent 및 relayEvent에 console.log를 수행 할 때 나에게 올바른 데이터를 돌려 주면 누군가 제발 나를 도울 수 있습니다! Relay Store Updater가 작동하지 않음

내 돌연변이의 일하는하지만 어떻게 든 데이터가 업데이트되지 않는, 그래서 내가 Heres는

내 코드 작동하지 않는 갱신 할 필요가 :

/* @flow */ 

import { graphql, commitMutation } from "react-relay"; 
import environment from "../../../relay/environment"; 
import type { EventSetAttendedInput } from "./__generated__/EventSetAttendedMutation.graphql"; 
import { connectionUpdater } from "../../../relay/mutationUtils"; 

const mutation = graphql` 
    mutation EventSetAttendedMutation($input: EventSetAttendedInput!) { 
    EventSetAttended(input: $input) { 
     event { 
     id 
     _id 
     attended(first: 10000) { 
      __typename 
      edges { 
      node { 
       person { 
       name 
       _id 
       id 
       } 
      } 
      } 
     } 
     invitations(first: 10000) { 
      __typename 
      edges { 
      node { 
       attended 
       person { 
       name 
       _id 
       id 
       } 
      } 
      } 
     } 
     } 
     error 
    } 
    } 
`; 

let tempID = 0; 

const commit = (input: EventSetAttendedInput, onCompleted, onError) => { 
    return commitMutation(environment, { 
    mutation, 
    variables: { 
     input: { 
     ...input, 
     clientMutationId: tempID++ 
     } 
    }, 
    onCompleted, 
    onError, 
    updater: store => { 
     let createAttendedField = store.getRootField("EventSetAttended"); 
     let newEvent = createAttendedField.getLinkedRecord("event"); 

     const relayEvent = store.get(input.eventId); 

     console.log(`eventStore: `, newEvent); 

     console.log(`relayEvent: `, relayEvent); 

     store.setValue(newEvent, "event"); 
    } 
    }); 
}; 

export default { commit }; 

답변

1
updater: (store, data) => { 
     let createAttendedField = store.getRootField("EventSetAttended"); 
     let newEvent = createAttendedField.getLinkedRecord("event"); 

     const relayEvent = store.get(input.eventId); 

     relayEvent.setLinkedRecord(newEvent, "event"); 
    }