{"id":28101560,"url":"https://github.com/workwithpact/gatsby-plugin-pact-contentful-schema-resolver","last_synced_at":"2025-05-13T18:57:11.035Z","repository":{"id":57684652,"uuid":"493669728","full_name":"workwithpact/gatsby-plugin-pact-contentful-schema-resolver","owner":"workwithpact","description":null,"archived":false,"fork":false,"pushed_at":"2022-06-29T16:38:42.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-22T12:37:05.316Z","etag":null,"topics":["contentful-api","contentful-custom-fields","gatsby-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"0bsd","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/workwithpact.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-05-18T13:14:16.000Z","updated_at":"2022-05-18T21:41:03.000Z","dependencies_parsed_at":"2022-09-17T00:20:48.894Z","dependency_job_id":null,"html_url":"https://github.com/workwithpact/gatsby-plugin-pact-contentful-schema-resolver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/workwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/workwithpact","download_url":"https://codeload.github.com/workwithpact/gatsby-plugin-pact-contentful-schema-resolver/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254010768,"owners_count":21998993,"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-api","contentful-custom-fields","gatsby-plugin"],"created_at":"2025-05-13T18:57:04.743Z","updated_at":"2025-05-13T18:57:11.028Z","avatar_url":"https://github.com/workwithpact.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gatsby-plugin-pact-contentful-schema-resolver\n\nWe've built a (small) [Contentful app](https://github.com/workwithpact/Pact-Contentful-Shopify-Schemas) that allows extending fields using [Shopify's settings schema](https://shopify.dev/themes/architecture/settings/input-settings).\n\nThis Gatsby plugin allows querying section settings (and blocks!) on any contentful type.\n\n## Features\n- Ability to query sections by id (field)\n- Ability to query blocks by type within a section\n- Ability to gather setting values (for either sections or blocks) as text, boolean, number or node\n- Ability to gather setting values (for either sections or blocks) as an existing ContentfulType (ex: you have a `blogPost` type and linked a `blogPost` entry to a setting using the Contentful app, you're able to request the value as a true `ContentfulBlogPost` from GraphQL)\n\n\n## Why ?\nWhile the JSON fields are automatically exposed as GraphQL nodes, once you change data in contentful, you risk making queries on inexistent fields.\nThis plugin solves that by exposing an array of fields as opposed to fields.\n\n## Prerequisites\nThis plugin assumes you are using the [gatsby-source-contentful](https://www.gatsbyjs.com/plugins/gatsby-source-contentful/) plugin (or any plugin utilizing this under the hood)\n\nThis plugin also assumes your Contentful space has the following Content Model and definitons:\n\n```json\n{\n  \"name\": \"Custom Field Definitions\",\n  \"description\": \"\",\n  \"displayField\": \"title\",\n  \"fields\": [\n    {\n      \"id\": \"title\",\n      \"name\": \"Title\",\n      \"type\": \"Symbol\",\n      \"localized\": false,\n      \"required\": false,\n      \"validations\": [],\n      \"disabled\": false,\n      \"omitted\": false\n    },\n    {\n      \"id\": \"models\",\n      \"name\": \"Content models and field\",\n      \"type\": \"Array\",\n      \"localized\": false,\n      \"required\": true,\n      \"validations\": [],\n      \"disabled\": false,\n      \"omitted\": false,\n      \"items\": {\n        \"type\": \"Symbol\",\n        \"validations\": [\n          {\n            \"regexp\": {\n              \"pattern\": \"^([a-zA-Z0-9_-]+|\\\\*):([a-zA-Z0-9_-]+)$\",\n              \"flags\": null\n            },\n            \"message\": \"Please use the contentId:fieldId format\"\n          }\n        ]\n      }\n    },\n    {\n      \"id\": \"config\",\n      \"name\": \"Configuration\",\n      \"type\": \"Object\",\n      \"localized\": false,\n      \"required\": false,\n      \"validations\": [],\n      \"disabled\": false,\n      \"omitted\": false\n    }\n  ],\n  \"sys\": {\n    \"id\": \"pactSectionsDefinitions\",\n    \"type\": \"ContentType\",\n  }\n}\n```\n\nIf you're using our Contentful App, then this is likely already the case :-)\n\n## Installation\nFirst, you'll want to install the package through either npm or yarn:\n- Are you using npm? A simple `npm install @workwithpact/pact-contentful-schema-gatsby --save` will suffice!\n- Or are you more of a yarn type of person? `yarn add @workwithpact/pact-contentful-schema-gatsby` will get the job done.\n\nNext, you'll want to open up your `gatsby-config.js` file and add `@workwithpact/pact-contentful-schema-gatsby` to the array of plugins. Anywhere within the array works, we're not picky.\n\nHere's what it would look like:\n\n```javascript\nmodule.exports = {\n  ...stuff,\n  plugins: [\n    ...somePlugins,\n    {\n      resolve: `gatsby-source-contentful`,\n      options: {\n        ...contentfulOptions\n      },\n    },\n    `@workwithpact/pact-contentful-schema-gatsby`,\n    ...maybeSomeMorePlugins\n  ]\n}\n```\n\n\n## Querying for settings and blocks\n\nThe easiest way to query for all sections and their settings (and blocks) is to use the `sections` field and its child `settings` (or `blocks`).\nWe suggest you take a very quick glance at the [type definitions](https://github.com/workwithpact/gatsby-plugin-pact-contentful-schema-resolver/blob/main/gatsby-node.js#L22-L67) created by this plugin before proceeding, to familiarize yourself with how content is exposed.\n\n### Querying all settings of a section, using `... on`\n\n```gql\n  AllContentfulSomeType {\n    sections {\n      id\n      name\n      settings {\n        ... on PactSectionSettingString {\n          id\n          value\n        }\n        ... on PactSectionSettingNumber {\n          id\n          value\n        }\n        ... on PactSectionSettingBoolean {\n          id\n          value\n        }\n        ... on PactSectionSettingNode {\n          id\n          value {\n           ...\n          }\n        }\n      }\n    }\n  }\n```\n### Querying a specific setting for a specific section, using `section(id:\"field\")` and `setting:(id:\"key\")`\n\n```gql\n  AllContentfulSomeType {\n    section(id: \"data\") {\n      mySetting: setting(id: \"title\") {\n        ... on PactSectionSettingString {\n          value\n        }\n      }\n    }\n  }\n```\n\n### Querying a specific setting as text for a specific section, using `section(id:\"field\")` and `settingValueAsText:(id:\"key\")`\n\n```gql\n  AllContentfulSomeType {\n    section(id: \"data\") {\n      mySetting: settingValueAsText(id: \"title\")\n    }\n  }\n```\n\n### Querying a specific setting as an asset for a specific section, using `section(id:\"field\")` and `settingValueAsContentfulAsset:(id:\"key\")`\n\n```gql\n  AllContentfulSomeType {\n    section(id: \"data\") {\n      mySetting: settingValueAsContentfulAsset(id: \"image\") {\n        width\n        height\n      }\n    }\n  }\n```\n\n### Querying blocks\n```gql\n  AllContentfulSomeType {\n    section(id: \"data\") {\n      blocks {\n        type\n        name\n        index\n        settings {\n          .. on PactSectionSettingString {\n            value\n            id\n          }\n        }\n      }\n    }\n  }\n```\n\n### Querying blocks of a specific type\n```gql\n  AllContentfulSomeType {\n    section(id: \"data\") {\n      blocksOfType(type:\"hero\") { \n        type\n        name\n        index\n        settings {\n          .. on PactSectionSettingString {\n            value\n            id\n          }\n        }\n      }\n    }\n  }\n```\n## Other things you can do\nWe're getting a little tired of writing GraphQL examples with data you can't access in our Contentful. \nThe best way to understand it all is to play with the plugin.\n\nCan you query a block's settings by id, as a specific GraphQL Type? Try it ou! (pssst: the answer's yes)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fworkwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fworkwithpact%2Fgatsby-plugin-pact-contentful-schema-resolver/lists"}