apollographql/apollo-client


rocket A fully-featured, production ready caching GraphQL client for every UI framework and GraphQL server

https://apollographql.com/client

License: MIT

Language: TypeScript

Keywords: apollo-client, apollographql, graphql, graphql-client, typescript


Apollo Client npm version Open Source Helpers

Apollo Client is a fully-featured caching GraphQL client with integrations for React, Angular, and more. It allows you to easily build UI components that fetch data via GraphQL. To get the most value out of apollo-client, you should use it with one of its view layer integrations.

To get started with the React integration, go to our React Apollo documentation website.

Apollo Client also has view layer integrations for all the popular frontend frameworks. For the best experience, make sure to use the view integration layer for your frontend framework of choice.

Apollo Client can be used in any JavaScript frontend where you want to use data from a GraphQL server. It's:

  1. Incrementally adoptable, so that you can drop it into an existing JavaScript app and start using GraphQL for just part of your UI.
  2. Universally compatible, so that Apollo works with any build setup, any GraphQL server, and any GraphQL schema.
  3. Simple to get started with, so you can start loading data right away and learn about advanced features later.
  4. Inspectable and understandable, so that you can have great developer tools to understand exactly what is happening in your app.
  5. Built for interactive apps, so your users can make changes and see them reflected in the UI immediately.
  6. Small and flexible, so you don't get stuff you don't need. The core is under 25kb compressed.
  7. Community driven, because Apollo is driven by the community and serves a variety of use cases. Everything is planned and developed in the open.

Get started on the home page, which has great examples for a variety of frameworks.

Installation

# installing the preset package
npm install apollo-boost graphql-tag graphql --save
# installing each piece independently
npm install apollo-client apollo-cache-inmemory apollo-link-http graphql-tag graphql --save

To use this client in a web browser or mobile app, you'll need a build system capable of loading NPM packages on the client. Some common choices include Browserify, Webpack, and Meteor 1.3+.

Install the Apollo Client Developer tools for Chrome for a great GraphQL developer experience!

Usage

You get started by constructing an instance of the core class ApolloClient. If you load ApolloClient from the apollo-boost package, it will be configured with a few reasonable defaults such as our standard in-memory cache and a link to a GraphQL API at /graphql.

import ApolloClient from 'apollo-boost';

const client = new ApolloClient();

To point ApolloClient at a different URL, add your GraphQL API's URL to the uri config property:

import ApolloClient from 'apollo-boost';

const client = new ApolloClient({
  uri: 'https://graphql.example.com'
});

Most of the time you'll hook up your client to a frontend integration. But if you'd like to directly execute a query with your client, you may now call the client.query method like this:

import gql from 'graphql-tag';

client.query({
  query: gql`
    query TodoApp {
      todos {
        id
        text
        completed
      }
    }
  `,
})
  .then(data => console.log(data))
  .catch(error => console.error(error));

Now your client will be primed with some data in its cache. You can continue to make queries, or you can get your client instance to perform all sorts of advanced tasks on your GraphQL data. Such as reactively watching queries with watchQuery, changing data on your server with mutate, or reading a fragment from your local cache with readFragment.

To learn more about all of the features available to you through the apollo-client package, be sure to read through the apollo-client API reference.

Learn how to use Apollo Client with your favorite framework


Contributing

CircleCI codecov

Read the Apollo Contributor Guidelines.

Running tests locally:

npm install
npm test

This project uses TypeScript for static typing and TSLint for linting. You can get both of these built into your editor with no configuration by opening this project in Visual Studio Code, an open source IDE which is available for free on all platforms.

Important discussions

If you're getting booted up as a contributor, here are some discussions you should take a look at:

  1. Static typing and why we went with TypeScript also covered in the Medium post
  2. Idea for pagination handling
  3. Discussion about interaction with Redux and domain vs. client state
  4. Long conversation about different client options, before this repo existed

Maintainers

Project Statistics

Sourcerank 20
Repository Size 26.7 MB
Stars 12,137
Forks 1,408
Watchers 291
Open issues 272
Dependencies 3,222
Contributors 501
Tags 1,032
Created
Last updated
Last pushed

Top Contributors See all

Jonas Helfer Sashko Stubailo Hugh Willson Renovate Bot Dhaivat Pandya Ben Newman James Baxley renovate[bot] Caleb Meredith Peggy Rayzis Slava Kim Kamil Kisiela Tom Coleman Greenkeeper greenkeeper[bot] Amanda Jin Liu Trevor Blades Shadaj Laddad John Pinkerton Cesar Solorzano

Packages Referencing this Repo

@apollo/client
A fully-featured caching GraphQL client.
Latest release 3.0.0-alpha.4 - Updated - 12.1K stars
@nuragic/apollo-client
A simple yet functional GraphQL client.
Latest release 2.6.4-alpha.0 - Published - 12.1K stars
@clayne/apollo-client
A simple yet functional GraphQL client.
Latest release 2.3.8 - Published - 12.1K stars
org.webjars.npm:apollo-cache
WebJar for apollo-cache
Latest release 1.2.0-verify.4 - Updated - 12.1K stars
org.webjars.npm:apollo-boost
WebJar for apollo-boost
Latest release 0.3.0-beta.1 - Published - 12.1K stars
org.webjars.npm:apollo-cache-inmemory
WebJar for apollo-cache-inmemory
Latest release 1.5.0-beta.1 - Published - 12.1K stars
@rmosolgo/apollo-cache
Core abstract of Caching layer for Apollo Client
Latest release 1.1.29-alpha.0 - Published - 12.1K stars
@rmosolgo/apollo-utilities
Utilities for working with GraphQL ASTs
Latest release 1.1.6-alpha.0 - Updated - 12.1K stars
@rmosolgo/apollo-client
A simple yet functional GraphQL client.
Latest release 2.4.16-alpha.0 - Updated - 12.1K stars
@rmosolgo/apollo-cache-inmemory
Core abstract of Caching layer for Apollo Client
Latest release 1.4.6-alpha.0 - Updated - 12.1K stars
@rmosolgo/apollo-boost
The easiest way to get started with Apollo Client
Latest release 0.2.3-alpha.0 - Updated - 12.1K stars
apollo-client-sjnonweb
A simple yet functional GraphQL client.
Latest release 2.3.7 - Published - 12.1K stars
org.webjars.npm:apollo-client
WebJar for apollo-client
Latest release 2.5.0-verify.4 - Updated - 12.1K stars
apollo-client-fork
A simple yet functional GraphQL client.
Latest release 2.2.3 - Published - 12.1K stars
apollo-cache-inmemory-fork
Core abstract of Caching layer for Apollo Client
Latest release 1.1.8 - Published - 12.1K stars
usnews-apollo-client
A simple yet functional GraphQL client.
Latest release 2.2.0 - Published - 12.1K stars
@wdimiceli/apollo-client
A simple yet functional GraphQL client.
Latest release 2.2.0 - Published - 12.1K stars
@beardfury/apollo-client
A simple yet functional GraphQL client.
Latest release 1.10.0-0 - Published - 12.1K stars
apollo-cache-core-inmemory
Core abstract of Caching layer for Apollo Client
Latest release 0.2.0-alpha.11 - Published - 12.1K stars
apollo-client-preset
Core abstract of Caching layer for Apollo Client
Latest release 1.0.8 - Updated - 12.1K stars

Recent Tags See all

v3.0.0-alpha.3 September 17, 2019
apollo-client@2.6.4 August 10, 2019
apollo-cache-inmemory@1.6.3 August 10, 2019
apollo-boost@0.4.4 August 10, 2019
apollo-client@2.6.3 June 18, 2019
apollo-boost@0.4.3 June 18, 2019
apollo-boost@0.4.3 June 18, 2019
graphql-anywhere@4.2.4 June 06, 2019
apollo-utilities@1.3.2 June 06, 2019
apollo-client@2.6.2 June 06, 2019
apollo-cache-inmemory@1.6.2 June 06, 2019
apollo-cache@1.3.2 June 06, 2019
apollo-boost@0.4.2 June 06, 2019
graphql-anywhere@4.2.3 June 04, 2019
apollo-utilities@1.3.1 June 04, 2019

Interesting Forks See all

vanpelt/apollo-client
rocket A fully-featured, production ready caching GraphQL client for every server or UI framework
TypeScript - Updated - 1 stars
bruce/apollo-client
rocket A fully-featured, production ready caching GraphQL client for every server or UI framework
TypeScript - Last pushed - 1 stars
rtorr/apollo-client
rocket A fully-featured caching GraphQL client for any server or UI framework
TypeScript - Updated - 1 stars
rewop/apollo-client
rocket A simple caching client for any GraphQL server and UI framework
TypeScript - Updated - 1 stars

Something wrong with this page? Make a suggestion

Last synced: 2019-04-08 17:03:15 UTC

Login to resync this repository