Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanhefner committed Sep 10, 2020
0 parents commit 8eb2908
Show file tree
Hide file tree
Showing 18 changed files with 9,340 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [ "./tools/babel-preset.js" ]
}
20 changes: 20 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Misc
.DS_Store

# Coverage reports
coverage

# Dependencies
node_modules

# Build files/directories
es
/parsers
umd
/*.js

# Include Rollup config
!rollup.config.js

# Temporarily ignore site
site/
17 changes: 17 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Coverage reports
coverage

# Supporting directories
docs
site

# Tooles
tools

# Configs
.babelrc
src/.babelrc
rollup.config.js

# Test files
**/*.test.js
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Ryan Hefner <hi@ryanhefner.com> (https://www.ryanhefner.com)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# 🔗 apollo-link-contentful

[![npm](https://img.shields.io/npm/v/apollo-link-contentful?style=flat-square)](https://www.pkgstats.com/pkg:apollo-link-contentful)
[![NPM](https://img.shields.io/npm/l/apollo-link-contentful?style=flat-square)](https://www.pkgstats.com/pkg:apollo-link-contentful)
[![npm](https://img.shields.io/npm/dt/apollo-link-contentful?style=flat-square)](https://www.pkgstats.com/pkg:apollo-link-contentful)
[![Coveralls github](https://img.shields.io/coveralls/github/ryanhefner/apollo-link-contentful?style=flat-square)](https://coveralls.io/github/ryanhefner/apollo-link-contentful)
![CircleCI](https://img.shields.io/circleci/build/github/ryanhefner/apollo-link-contentful?style=flat-square)

Perform GraphQL queries against Contentful’s Rest API. No more, query size limits! No more, query complexities!!

## Install

Via [npm](https://npmjs.com/package/apollo-link-contentful)

```sh
npm install --save apollo-link-contentful
```

Via [Yarn](https://yarn.fyi/apollo-link-contentful)

```sh
yarn add apollo-link-contentful
```

## How to use

`ContentfulRestLink` makes it easy to query the Contentful REST API via GraphQL +
Apollo, without all the fuss about query size, nor complexity, limit issues. Simply
setup the `link` when you are creating your `ApolloClient`, then feel free to
perform your `GraphQL` queries like you normally do.

The `ContentfulRestLink` class accepts two arguments, `clientOptions` and `queryDefaults` _(optional)_.

* `clientOptions` - Accepts all Contentful Client options, reference available [here](https://contentful.github.io/contentful.js/contentful/7.14.6/contentful.html#.createClient).

_The only exception is that if you plan to use the Contentful Preview API, you’ll have to include an optional `previewAccessToken`, which will create a client for all queries where `preview` variable is `true`._

* `queryDefaults` - This is just a handy tool if you happen to have some defaults
that you would like to include for all queries being made to Contentful. Handy ones
that you might use would be, `{ include: 10, locale: 'en-US' }`. Where `include` sets
the depth of linked references to include in responses, [Link docs](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/links),
and `locale` specifies the localization of the entry(ies) returned, [Localization docs](https://www.contentful.com/developers/docs/references/content-delivery-api/#/reference/localization).

## Example

```js
import { ApolloClient, InMemoryCache } from '@apollo/client'
import { ContentfulRestLink } from 'apollo-link-contentful'
import introspectionQueryResultData from 'schema/possibleTypes.json'

const space = process.env.CONTENTFUL_SPACE
const accessToken = process.env.CONTENTFUL_ACCESS_TOKEN

const apolloClient = new ApolloClient({
link: new ContentfulRestLink({
space,
accessToken,
}, {
include: 10,
}),
cache: new InMemoryCache({ possibleTypes }),
});
```

## License

[MIT](LICENSE) © [Ryan Hefner](https://www.ryanhefner.com)
Loading

0 comments on commit 8eb2908

Please sign in to comment.