import { gql, useQuery } from '@apollo/client';
const Username = () => {
const { loading, error, data } = useQuery(gql`
{
me {
username
}
}
`);
if (loading) return <text>Loading...</text>;
if (error) return (
<text>Error! ${error.message}</text>
);
if (!data || !data.user) return (
<text>Could not find user :(</text>
);
return (
<text>Your username: {data.me.username}</text>
);
}
Write a query and receive data without manually tracking loading, error, or network states.
Cut down on network traffic and keep data consistent throughout your application with Apollo Client’s normalized reactive data cache.
Enjoy cross stack type safety, runtime cache inspectors, and full featured editor integrations to keep you writing applications faster.
Use any build setup and any GraphQL API. Drop Apollo Client into any app seamlessly without re-architecting your entire data strategy.
Take advantage of modern UI architectures in the web, iOS, and Android ecosystems.
Share knowledge with thousands of developers, thanks to our active open source community.
"Apollo is the de facto standard GraphQL implementation, but we were also pleasantly surprised to find built-in support for things like caching, deduplication, and error handling. You just write the code that’s specific to interacting with your backend, and Apollo takes care of the rest."
Neil Lokare @ NerdWallet
"In a build vs. buy decision, Apollo Platform was a clear buy. We wanted to deliver the promise of GraphQL to our developers now rather than later."
Mark Stuart @ PayPal
"We have developed a very close working relationship with the Apollo team. We talk to them almost every day, which is critical to ensuring that we can help our customers through both good times and difficult times."
Sankha Pathak @ Glassdoor
Cache Policies
Reactivity
Pagination
Subscriptions
React
const cache = new InMemoryCache({
typePolicies: {
Person: {
fields: {
name: {
read(name) {
// Return cached name, upper-cased:
return name.toUpperCase();
}
}
},
},
},
});