Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lemol/umi-plugin-apollo
Apollo graphql plugin for umi
https://github.com/lemol/umi-plugin-apollo
apollographql graphql plugin react umi umijs
Last synced: about 6 hours ago
JSON representation
Apollo graphql plugin for umi
- Host: GitHub
- URL: https://github.com/lemol/umi-plugin-apollo
- Owner: lemol
- Created: 2018-09-25T23:31:19.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T15:02:07.000Z (almost 2 years ago)
- Last Synced: 2024-09-10T11:01:26.501Z (2 months ago)
- Topics: apollographql, graphql, plugin, react, umi, umijs
- Language: JavaScript
- Size: 5.27 MB
- Stars: 49
- Watchers: 4
- Forks: 3
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# umi-plugin-apollo
[![NPM version](https://img.shields.io/npm/v/umi-plugin-apollo.svg?style=flat)](https://npmjs.org/package/umi-plugin-apollo)
Umi plugin for apollo graphql client.
### Install
```bash
$ yarn add umi-plugin-apollo # OR npm install --save umi-plugin-apollo
```### Setup
Having setup the `umi-plugin-react`, add the `umi-plugin-apollo` plugin:
```js
// .umirc.jsexport default {
plugins: [
['umi-plugin-react', {
routes: {
exclude: [
/schema\.(js|jsx|ts|tsx)$/,
/resolvers\.(js|jsx|ts|tsx)$/,
],
},
// other umi-plugin-react options
}],
['umi-plugin-apollo', {/*
uri: 'https://my.endpoint.com/graphql',
mock: true,
hooksImportFrom: 'react-apollo-hooks',
options: 'path/to/options/file',
*/}],
]
}
```Done.
### Options
| name | type | default |
| --------------- | --------------------------------------- | ------------------------- |
| uri | string (required in production) | `process.env.GRAPHQL_URI` |
| mock | string (optional) | `process.env.MOCK` |
| hooksImportFrom | `'react-apollo-hooks' | 'react-apollo'` | `'react-apollo-hooks'` |
| options | string (optional) | `./options/apollo.js` |### Options file
You can create an options file that will be used to customize the creation of ApolloClient.
Define this file on the `options` field in the plugin options:```js
// .umirc.js
export default {
plugins: [
['umi-plugin-apollo', {
options: 'path/to/options/file',
}],
]
}
```This file can define the following fields:
```js
// path/to/options/file.js'export const cacheOptions = {
};export const httpLinkOptions = {
};export const stateLinkOptions = {
};export const extraLinks = [
];export const clientOptions = {
};export const providerOptions = {
};export const makeCache = undefined; // : ({ cacheOptions }) => Cache
export const makeHttpLink = undefined; // : ({ clientStateLink, remoteLink, httpLinkOptions }) => ApolloLink
export const makeClientStateLink = undefined; // : ({ resolvers, defaults, cache, typeDefs, stateLinkOptions }) => ApolloLink
export const makeLink = undefined; // : ({ clientStateLink, remoteLink, extraLinks }) => ApolloLink
export const makeClient = undefined; // : ({ link, cache, clientOptions }) => ApolloClient
export const makeProvider = undefined; // : ({ client, providerOptions }) => ReactElement (eg: ({ children }) => {children}