Skip to content

Commit 0902e28

Browse files
committed
Add query variables
1 parent 832ca12 commit 0902e28

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

src/graphql/queries.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import gql from 'graphql-tag';
22

33
export const EXAMPLE = gql`
4-
{
5-
search(term: "burrito", location: "san francisco") {
4+
query Search($term: String!,$location:String!) {
5+
search(term: $term, location: $location) {
66
total
77
business {
88
name

src/screens/home.js

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,39 @@ import { Query } from "react-apollo";
55

66

77
export default class Home extends Component {
8+
getYelp({ term, location }) {
9+
return (
10+
<Query query={EXAMPLE} variables={{ term, location }}>
11+
{({ loading, data: { search }, error }) => {
12+
if (loading) {
13+
return <Text>Loading...</Text>
14+
}
15+
if (search) {
16+
const result = search.business.map((i, index) => {
17+
return (
18+
<View key={index}>
19+
<Text>{index + 1 + ". " + i.name}</Text>
20+
<Text>Rating: {i.rating} - Review: {i.review_count}</Text>
21+
<Text>{i.location.address1}</Text>
22+
</View>)
23+
})
24+
return result;
25+
}
26+
if (error)
27+
return <Text>{error.message}</Text>
28+
29+
return (
30+
<Text>No result</Text>
31+
);
32+
}}
33+
</Query>
34+
)
35+
}
836
render() {
37+
938
return (
1039
<ScrollView>
11-
<Query query={EXAMPLE}>
12-
{({ client, loading, data: { search } }) => {
13-
if (loading) {
14-
return <Text>Loading...</Text>
15-
}
16-
if (search) {
17-
const result = search.business.map((i, index) => {
18-
return (
19-
<View key={index}>
20-
<Text>{index+1 + ". " + i.name}</Text>
21-
<Text>Rating: {i.rating} - Review: {i.review_count}</Text>
22-
<Text>{i.location.address1}</Text>
23-
</View>)
24-
})
25-
return result;
26-
}
27-
return (
28-
<Text>No result</Text>
29-
);
30-
}}
31-
</Query>
40+
{this.getYelp({ term: "burrito", location: "san francis" })}
3241
</ScrollView>
3342
)
3443
}

0 commit comments

Comments
 (0)