-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 8eb2908
Showing
18 changed files
with
9,340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"presets": [ "./tools/babel-preset.js" ] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# 🔗 apollo-link-contentful | ||
|
||
[](https://www.pkgstats.com/pkg:apollo-link-contentful) | ||
[](https://www.pkgstats.com/pkg:apollo-link-contentful) | ||
[](https://www.pkgstats.com/pkg:apollo-link-contentful) | ||
[](https://coveralls.io/github/ryanhefner/apollo-link-contentful) | ||
 | ||
|
||
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) |
Oops, something went wrong.