2017-11-15 5 views
0

refetchQueries이 작동하는 데 문제가 있습니다.아폴로에서 refetchQueries를 사용하여 반응하십시오.

"물건 추가"라는 양식이 있지만 "물건 목록"으로 돌아 가면 새로 작성한 것은 페이지를 새로 고칠 때만 나타납니다. (중간 단계로) 성공적인 "추가"후 사물 목록을 업데이트하고 싶습니다.

다음을 시도했지만 작동하지 않습니다. docs은 매우 간단합니다, 그래서 간단하게 뭔가 빠진해야처럼 난 느낌 :

// Called successfully 
    const updateThing = gql` 
    mutation AddThing($id: ID, $title: String!) { 
    problem(id: $id, title: $title) { 
     id 
     title 
    } 
    } 

    // NOT CALLED :(
    const listThings = gql` 
    query ListThings($includeArchived: Boolean = false) { 
    problems(includeArchived: $includeArchived) { 
     id, 
     archived 
    } 
    } 

    // Form (simplified version of Formik form) 
    const ThingForm = props => (
    <form onSubmit={e=> { 
     e.preventDefault(); 
     e.handleSave({ 
     variables: { 
      title: 'test' 
     } 
     }) 
    }} 
    > 
     <button type="submit">Add thing</button> 
    </form> 
) 

    // Connect 
    export const ThingAdd = compose(
    graphql(
     updateThing, 
     { 
     name: 'handleSave', 
     options: ({values}) => ({...values }), 
     refetchQueries: [{ 
      query: listThing, 
      variables: ({includeArchived: true}) 
     }] 
     } 
    ) 
)(
    ThingForm 
); 

관련 deps :

"apollo-cache-inmemory": "^1.1.0", 
"apollo-client": "^2.0.2", 
"apollo-fetch": "^0.6.0", 
"apollo-link-core": "^0.5.4", 
"apollo-link-http": "^1.1.0", 
"graphql": "0.10.5", 
"graphql-tag": "^2.5.0", 
"graphql-tools": "^2.7.2", 
"react": "^16.0.0", 
"react-apollo": "^2.0.0", 

답변

1

refetchQueries 당신이에 전달하는 options 객체의 속성되어야한다 graphql HOC :

options: ({values}) => ({ 
    refetchQueries: [{ 
    query: listThing, 
    variables: ({includeArchived: true}) 
    }], 
    ...values 
}),