# contentful-helper

> Helpfer library for connecting with Contentful.

Latest version **0.0.11** (published 2023-04-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install contentful-helper
pnpm add contentful-helper
yarn add contentful-helper
bun add contentful-helper
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.11 |
| Published | 2023-04-05 |
| First published | 2023-04-05 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 8.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Timmy Morrissey |
| Maintainers | tmorr |

## Links

- npm: https://www.npmjs.com/package/contentful-helper
- npm.io page: https://npm.io/package/contentful-helper

## Dependencies (2)

- [contentful](https://npm.io/package/contentful.md) ^10.0.0-beta-v10.20
- [graphql-tag](https://npm.io/package/graphql-tag.md) ^2.12.6

## Recent versions

- 0.0.11 (latest) — 2023-04-05
- 0.0.10 — 2023-04-05

## README

# Contentful helper

This is an npm module that provides a REST client for fetching data from a [Contentful](https://www.contentful.com/) space and a suite of GraphQL queries to do the same.

## Installation

You can install this module using npm:

`npm install contentful-helper`

## REST client

The module exports a `RESTClient` class with a `getComponentStyles` method for fetching data from Contentful.

Here's an example of how to use the module to fetch an array of `ComponentStyle` objects filtered by a given affiliate:

```js
import { RESTClient } from 'contentful-helper'

const space = 'your-space-id'
const accessToken = 'your-access-token'
const environment = 'master'

const client = new RESTClient(space, accessToken, environment)

const affiliate = 'some-affiliate'
const contentType = 'styleComponentStyle'

const componentStyles = await client.getComponentStyles(affiliate, contentType)

console.log(componentStyles)
```

## GraphQL queries

The module exports a GraphQL query called `getComponentStylesQuery` used to get the `styleComponentStyle` content for an affiliate.

Here's an example of how to use the query to fetch an array of `ComponentStyle` objects filtered by a given affiliate using Apollo client:

```js
import { getComponentStylesQuery } from 'contentful-helper'
import { ApolloClient, HttpLink, InMemoryCache } from "@apollo/client";

const space = 'your-space-id'
const accessToken = 'your-access-token'
const environment = 'master'

const link = new HttpLink({
  fetch,
  uri: `https://graphql.contentful.com/content/v1/spaces/${space}/environments/${environment}r`,
  headers: {
    authorization: `Bearer ${accessToken}`,
    'Content-Language': 'en-us',
  }
})

const client = new ApolloClient({
    link,
    cache: new InMemoryCache(),
});

async function getClassesGraphQL() {
  const { data, loading, error } = await client.query({
    query: getComponentStylesQuery('some-affiliate')
  });

  return data.styleComponentStyleCollection.items
}

const componentStyle = await getClassesGraphQL()

console.log(componentStyles)
```

---
_Source: https://npm.io/package/contentful-helper · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
