Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/primecms/apollo-link-prime
Apollo Link that allow you query and preview Prime endpoints
https://github.com/primecms/apollo-link-prime
Last synced: 3 months ago
JSON representation
Apollo Link that allow you query and preview Prime endpoints
- Host: GitHub
- URL: https://github.com/primecms/apollo-link-prime
- Owner: primecms
- Created: 2019-01-03T16:14:49.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2019-02-14T17:26:22.000Z (almost 6 years ago)
- Last Synced: 2024-10-20T20:58:50.339Z (3 months ago)
- Language: JavaScript
- Size: 51.8 KB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome - apollo-link-prime - Apollo Link that allow you query and preview Prime endpoints (JavaScript)
- awesome-starred - primecms/apollo-link-prime - Apollo Link that allow you query and preview Prime endpoints (others)
README
# apollo-link-prime
Apollo Link provider for Prime
## Installation
`yarn add -S apollo-link-prime`or
`npm install -S apollo-link-prime`
## Usage
```ts
import { PrimeLink } from 'apollo-link-prime';const apolloClient = new ApolloClient({
link: PrimeLink({
url: 'https://prime.example.com',
accessToken?: '',
ssrMode?: false,
linkResolver?: (document, schema) => '/',
cookies?: { [key: string]: string },
}),
cache: new InMemoryCache()
});
```| parameter | type | default | description |
| --------- | ---- | ------- | ----------- |
| **url** | string | required | Absolute URL with no path at the end to a Prime endpoint |
| **accessToken** | string | undefined | Permanent server token or JWT access token (private api enabled) |
| **ssrMode** | boolean | false | If enabled, client will store a preview cookie and reload the page. |
| **linkResolver** | Function | undefined | This function can return a redirect path for the previewed document in question |
| **cookies** | object | undefined | Pass cookies from express etc. in object format. The link will read stored preview cookie from _ssrMode_ |### Client
You read preview state and clear it with the following utility functions.
```js
import { clearPreview, isPreviewing } from 'apollo-link-prime';// client code
if (isPreviewing()) {
button.onclick = () => clearPreview();
}
```