Almost deprecated since the introduction ApolloLinks in Apollo 2
Use ApolloClient without a GraphQL server. This is a porting of relay-local-schema for Apollostack.
This package implements a common pattern for using ApolloClient without a GraphQL server. The code is simple, even trivial, and you might prefer to roll up your own version. You can add this package to your project with:
npm install mstn:apollo-local-network-interface#v1.0.0
LocalNetworkInterface
enables ApolloClient to execute GraphQL queries and mutations locally.
import ApolloClient from 'apollo-client';
import schema from './data/schema';
const networkInterface = createLocalNetworkInterface({ schema });
const client = new ApolloClient({ networkInterface });
// ... then you can use client.query or client.mutate as usual (see tests for examples)
As the original package relay-local-schema for Relay framework, LocalNetworkInterface
could be useful in a variety of cases:
- testing,
- demos,
- client side wrapper for legacy REST APIs.
- Strongly influenced by and based on relay-local-schema.
- Steven Luscher REST API GraphQL wrapper
- @dalgard @stubailo and @linonetwo in this discussion on GH. In particular @linonetwo implemented a very similar
NetworkInterface
in his blog.
- @lucasconstantino wrote a very nice blog post about this topic. I recommend it!
If you use Apollo 2, you do not need this package. Indeed, you can pass an apollo-link-schema to your Apollo client. From official documentation:
import { ApolloClient } from 'apollo-client';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { SchemaLink } from 'apollo-link-schema';
import schema from './data/schema';
const client = new ApolloClient({
cache: new InMemoryCache(),
link: new SchemaLink({ schema })
});