-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
81 lines (71 loc) · 1.97 KB
/
Copy pathapp.js
File metadata and controls
81 lines (71 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* eslint-env es6 */
import React from 'react';
import {
View,
Text,
} from 'react-native';
import Relay, { Mutation } from 'react-relay';
Relay.injectNetworkLayer(
new Relay.DefaultNetworkLayer('http://localhost:1337/graphql'
)
);
class Post extends React.Component {
render() {
return <Text>{ this.props.post.title }</Text>
}
}
class Posts extends React.Component {
render() {
let page = this.props.page;
let posts = page.posts;
console.log(this.props);
return (
<View style={{marginTop: 30}}>
<Text>Posts Page:</Text>
<View>
{posts.map((post) => <Post key={post.id} post={ post } />)}
</View>
</View>
)
}
}
// The component we need to export is a Relay wrapper around our App component
// from above. It declares the GraphQL fragments where we list the properties
// we want to be fetched – eg, user.name, user.widgets.edges, etc
let PostContainer = Relay.createContainer(Post, {
fragments: {
post: () => Relay.QL`
fragment on Post {
id
title
}
`,
},
})
exports.PostList = Relay.createContainer(Posts, {
fragments: {
// The property name here reflects what is added to `this.props` above.
// This template string will be parsed by babel-relay-plugin when we browserify.
page: () => Relay.QL`
fragment on Viewer {
posts { id, title }
}
`,
},
})
// The Relay root container needs to know what queries will occur at the top
// level – these configurations are currently called Routes in Relay, but this
// name is misleading and under review so we don't use it here.
exports.queries = {
name: 'AppQueries', // can be anything, just used as an identifier
params: {},
queries: {
// We can use this shorthand so long as the component we pair this with has
// a fragment named "user", as we do above.
page: (Component) => Relay.QL`
query {
posts(offset: 0) { ${Component.getFragment('page')} }
}
`,
},
}