Created
November 21, 2018 15:39
-
-
Save jmn/98c0740086046c23ce97b3911349ad04 to your computer and use it in GitHub Desktop.
React Native GraphQL Apollo Boost in FlatList
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import { Text, View, SafeAreaView, FlatList } from 'react-native'; | |
import ApolloClient from "apollo-boost"; | |
import gql from "graphql-tag"; | |
import { ApolloProvider } from "react-apollo"; | |
import { Query } from "react-apollo"; | |
const client = new ApolloClient({ | |
uri: "https://www.fedry.net/graphql" | |
}); | |
const App = () => ( | |
<ApolloProvider client={client}> | |
<Text>My first Apollo app ??</Text> | |
<ExchangeRates /> | |
</ApolloProvider> | |
); | |
export default App; | |
const ExchangeRates = () => ( | |
<Query | |
query={gql` | |
{ | |
posts(first: 6) { | |
edges { | |
node { | |
title | |
id | |
} | |
} | |
} | |
} | |
`} | |
> | |
{({ loading, error, data }) => { | |
if (loading) return <Text>Loading...</Text>; | |
if (error) return <Text>Error </Text>; | |
return <FlatList | |
data={data.posts.edges} | |
renderItem={({item}) => <Text>{`${item.node.title}`}</Text>} | |
keyExtractor={(item, index) => index.toString()} | |
/> | |
}} | |
</Query> | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment