{"id":14991007,"url":"https://github.com/buildinamsterdam/contentful-graphql","last_synced_at":"2026-01-05T00:08:57.147Z","repository":{"id":188796740,"uuid":"671090001","full_name":"buildinamsterdam/contentful-graphql","owner":"buildinamsterdam","description":"Contentful GraphQL connection","archived":false,"fork":false,"pushed_at":"2023-10-19T11:43:33.000Z","size":473,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-03-06T13:45:24.333Z","etag":null,"topics":["contentful","data","graphql"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/buildinamsterdam.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-26T14:12:20.000Z","updated_at":"2023-08-16T20:39:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"f789ff34-b6e7-4994-a3f7-6f4750dc0ac6","html_url":"https://github.com/buildinamsterdam/contentful-graphql","commit_stats":null,"previous_names":["buildinamsterdam/contentful-graphql"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildinamsterdam%2Fcontentful-graphql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildinamsterdam%2Fcontentful-graphql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildinamsterdam%2Fcontentful-graphql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/buildinamsterdam%2Fcontentful-graphql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/buildinamsterdam","download_url":"https://codeload.github.com/buildinamsterdam/contentful-graphql/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244287901,"owners_count":20428892,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["contentful","data","graphql"],"created_at":"2024-09-24T14:21:16.979Z","updated_at":"2026-01-05T00:08:57.118Z","avatar_url":"https://github.com/buildinamsterdam.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# contentful-graphql\n\n[![NPM version][npm-image]][npm-url]\n[![Actions Status][ci-image]][ci-url]\n[![PR Welcome][npm-downloads-image]][npm-downloads-url]\n\nContentful GraphQL client\n\n## Introduction\n\nPackage introduction, couple of paragraphs.\n\n```typescript\nimport { createClient } from \"@buildinams/contentful-graphql\";\n\nconst makeQuery = createClient({\n  environment: process.env.CONTENTFUL_ENV || \"\",\n  spaceId: process.env.CONTENTFUL_SPACE_ID || \"\",\n  accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || \"\",\n  previewKey: process.env.CONTENTFUL_PREVIEW_KEY || \"\",\n});\n```\n\n## Installation\n\nInstall this package with `npm`.\n\n```bash\nnpm i @buildinams/contentful-graphql\n```\n\n## Usage\n\n```tsx\nimport {\n  createClient,\n  ContentfulAdaptor,\n} from \"@buildinams/contentful-graphql\";\n\nconst makeQuery = createClient({\n  environment: process.env.CONTENTFUL_ENV || \"\",\n  spaceId: process.env.CONTENTFUL_SPACE_ID || \"\",\n  accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || \"\",\n  previewKey: process.env.CONTENTFUL_PREVIEW_KEY || \"\",\n});\n\nconst Adaptor = new ContentfulAdaptor({});\n\nconst fetchData = async (args: DataTypeArgs) =\u003e {\n  const data = await makeQuery\u003cDataType\u003e({\n    query: dataTypeGraphQLQuery,\n    variables: args,\n  });\n\n  return Adaptor.adapt(data);\n};\n```\n\n### createClient\n\n```typescript\nimport { createClient } from \"@buildinams/contentful-graphql\";\nconst makeQuery = createClient({\n  environment: process.env.CONTENTFUL_ENV || \"\",\n  spaceId: process.env.CONTENTFUL_SPACE_ID || \"\",\n  accessToken: process.env.CONTENTFUL_ACCESS_TOKEN || \"\",\n  previewKey: process.env.CONTENTFUL_PREVIEW_KEY || \"\",\n});\n```\n\nCreate client creates a helper function that is able to send GraphQL queries to your Contentful space. The expected arguments are;\n\n- **accessToken** - [Access token](https://www.contentful.com/developers/docs/references/authentication/) of your Contentful space\n- **previewKey** - [Preview key](https://www.contentful.com/developers/docs/references/content-preview-api/) to be able to query draft data\n- **spaceId** - Space to get data from\n- **baseUrl** - Optional; Location of your Contentful space, defaults to; \"https://graphql.contentful.com/content\"\n- **environment** - Optional; Environment to query, default to; \"master\"\n\n### ContentfulAdaptor\n\n```typescript\nimport { ContentfulAdaptor } from \"@buildinams/contentful-graphql\";\nconst Adaptor = new ContentfulAdaptor({\n  contentAdaptors: {\n    BlockMedia: blockMediaAdaptor,\n  },\n  pageAdaptors: {\n    Homepage: homepageAdaptor,\n  },\n});\n```\n\nThis generates a JavaScript class that gives you the option to adapt the data. Expected arguments;\n\n- **contentAdaptors** - Content adaptors run recursively over the provided data. When an object matches the pattern: `{ __typename: {key} }` it will run the adaptor with the matching `{key}`.\n- **pageAdaptors** - Page adaptors only run top level. These can be used if you want to format the initial data but you don't want to run to run them when they are referenced. Example; we want a `pageLayout` to contain all data but when referenced in a `cta` we don't want the page adaptor.\n\n#### Adaptors\n\nThe concept of adaptors are generics that modifiy certain data by content type (`__typename`). Often these can follow the structure below;\n\n```typescript\nconst blockMediaAdaptor = (data: ContentfulQueryResponse) =\u003e {\n  return {\n    type: data.file.fileType,\n    src: data.src,\n    ratio: data.height / data.width,\n  };\n};\n\nexport type BlockMedia = ReturnType\u003ctypeof blockMediaAdaptor\u003e;\n```\n\nWithin your application you can then use the `BlockMedia` type to link back to the type of data you expect to receive.\n\n### getIndicatorProps\n\n```typescript\nimport { getIndicatorProps } from \"@buildinams/contentful-graphql/getIndicatorProps\";\n\u003ch1 {...getIndicatorProps({ entryId: entry.sys.id, fieldId: \"title\" })}\u003e\n  {entry.title}\n\u003c/h1\u003e;\n```\n\nA small helper function to get [indicator mode](https://www.contentful.com/developers/docs/tutorials/general/live-preview/#set-up-inspector-mode) in Contentful preview mode. Expected arugments;\n\n- **entryId** - ID of the linked content entry, usually `entry.sys.id`\n- **fieldId** - Name of the field that's displayed\n- **locale** - Optional; Locale of the displayed entry\n\n## Requests and Contributing\n\nFound an issue? Want a new feature? Get involved! Please contribute using our guideline [here](https://github.com/buildinamsterdam/contentful-graphql/blob/main/CONTRIBUTING.md).\n\n[npm-image]: https://img.shields.io/npm/v/@buildinams/contentful-graphql.svg?style=flat-square\u0026logo=react\n[npm-url]: https://npmjs.org/package/@buildinams/contentful-graphql\n[ci-image]: https://github.com/buildinamsterdam/contentful-graphql/actions/workflows/test.yml/badge.svg\n[ci-url]: https://github.com/buildinamsterdam/contentful-graphql/actions\n[npm-downloads-image]: https://img.shields.io/npm/dm/@buildinams/contentful-graphql.svg\n[npm-downloads-url]: https://npmcharts.com/compare/@buildinams/contentful-graphql?minimal=true\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildinamsterdam%2Fcontentful-graphql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbuildinamsterdam%2Fcontentful-graphql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbuildinamsterdam%2Fcontentful-graphql/lists"}