2016-11-15 26 views
0

如何添加拉到刷新功能到阿波罗客户端演示http://dev.apollodata.com/如何添加拉到刷新到阿波罗例子

看起来像graphql函数是一个包装或工厂函数,它创建一个graphql组件?我应该如何实现像pull那样的功能来刷新graphql组件?

import React from 'react'; 
import { Text, View } from 'react-native'; 
import { graphql } from 'react-apollo'; 
import gql from 'graphql-tag'; 

const styles = { 
    outer: { paddingTop: 22 }, 
    wrapper: { height: 45, flex: 1, flexDirection: 'row' }, 
    header: { fontSize: 20 }, 
    subtextWrapper: { flex: 1, flexDirection: 'row' }, 
    votes: { color: '#999' }, 
} 

// The data prop, which is provided by the wrapper below contains, 
// a `loading` key while the query is in flight and posts when ready 
function PostList({ data: { loading, posts } }) { 
    if (loading) { 
    return <Text style={styles.outer}>Loading</Text>; 
    } else { 
    return (
     <View style={styles.outer}> 
     {posts.sort((x, y) => y.votes - x.votes).map(post => (
      <View key={post.id} style={styles.wrapper}> 
      <View> 
       <Text style={styles.header}>{post.title}</Text> 
       <View style={styles.subtextWrapper}> 
       <Text> 
       by {post.author.firstName} {' '} 
       {post.author.lastName} {' '} 
       </Text> 
       <Text style={styles.votes}>{post.votes} votes</Text> 
       </View> 
      </View> 
      </View> 
     ))} 
     </View> 
    ); 
    } 
} 

// The `graphql` wrapper executes a GraphQL query and makes the results 
// available on the `data` prop of the wrapped component (PostList here) 
export default graphql(gql` 
    query allPosts { 
    posts { 
     id 
     title 
     votes 
     author { 
     id 
     firstName 
     lastName 
     } 
    } 
    } 
`)(PostList); 

回答

1

graphql()的装饰传递props.data一个refetch()方法。当用户拉下来时,拨打​​应该为您完成此操作。