{"id":15064917,"url":"https://github.com/microcmsio/gatsby-source-microcms","last_synced_at":"2025-08-18T05:13:56.090Z","repository":{"id":39912365,"uuid":"216459565","full_name":"microcmsio/gatsby-source-microcms","owner":"microcmsio","description":":memo: Source plugin for Gatsby from microCMS. ","archived":false,"fork":false,"pushed_at":"2023-01-06T02:14:16.000Z","size":584,"stargazers_count":26,"open_issues_count":3,"forks_count":8,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-18T01:35:52.005Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/gatsby-source-microcms","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/microcmsio.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null}},"created_at":"2019-10-21T02:17:11.000Z","updated_at":"2025-01-24T11:10:51.000Z","dependencies_parsed_at":"2023-02-05T02:30:48.562Z","dependency_job_id":null,"html_url":"https://github.com/microcmsio/gatsby-source-microcms","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"purl":"pkg:github/microcmsio/gatsby-source-microcms","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcmsio%2Fgatsby-source-microcms","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcmsio%2Fgatsby-source-microcms/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcmsio%2Fgatsby-source-microcms/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcmsio%2Fgatsby-source-microcms/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/microcmsio","download_url":"https://codeload.github.com/microcmsio/gatsby-source-microcms/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/microcmsio%2Fgatsby-source-microcms/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270946068,"owners_count":24672890,"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","status":"online","status_checked_at":"2025-08-18T02:00:08.743Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2024-09-25T00:27:46.634Z","updated_at":"2025-08-18T05:13:56.071Z","avatar_url":"https://github.com/microcmsio.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gatsby-source-microcms\n\n[![npm version](https://img.shields.io/npm/v/gatsby-source-microcms.svg)](https://www.npmjs.com/package/gatsby-source-microcms)\n[![install size](https://packagephobia.now.sh/badge?p=gatsby-source-microcms)](https://packagephobia.now.sh/result?p=gatsby-source-microcms)\n\nSource plugin for Gatsby from [microCMS](https://microcms.io/).\n\n## Install\n\n```sh\n# npm\n$ npm install gatsby-source-microcms\n\n# or yarn\n$ yarn add gatsby-source-microcms\n```\n\n## How to use\n\n### gatsby-config.js\n\nFirst, to fetch contents from microCMS, you need setting options in `gatsby-config.js`.\n\n```js\nmodule.exports = {\n  plugins: [\n    {\n      resolve: 'gatsby-source-microcms',\n      options: {\n        apiKey: 'MICROCMS_API_KEY',\n        serviceId: 'myblog',\n        apis: [\n          {\n            endpoint: 'posts',\n          },\n        ],\n      },\n    },\n  ],\n};\n```\n\n### gatsby-node.js\n\nYou can query like the following. Gatsby create Pages based on microCMS contents.\n\n```js\nexports.createPages = async ({ graphql, actions }) =\u003e {\n  const { createPage } = actions;\n\n  const result = await graphql(\n    `\n      {\n        allMicrocmsPost(sort: { fields: [createdAt], order: DESC }) {\n          edges {\n            node {\n              id\n              createdAt\n            }\n          }\n        }\n      }\n    `\n  );\n\n  if (result.errors) {\n    throw result.errors;\n  }\n\n  result.data.allMicrocmsPost.edges.forEach((post, index) =\u003e {\n    createPage({\n      path: post.node.id,\n      component: path.resolve('./src/templates/blog-post.js'),\n      context: {\n        slug: post.node.id,\n      },\n    });\n  });\n};\n```\n\n### Options\n\n```js\nmodule.exports = {\n  plugins: [\n    {\n      resolve: 'gatsby-source-microcms',\n      options: {\n        /**\n         * The authentication key required for API requests. (Required)\n         *\n         * Type: string.\n         **/\n        apiKey: '11111111-2222-3333-4444-555555555555',\n\n        /**\n         * Service information. (Required)\n         * xxxx.microcms.io\n         *\n         * Type: string.\n         **/\n        serviceId: 'xxxx',\n\n        /**\n         * API information. (Required)\n         * Multiple APIs can be specified.\n         *\n         * Type: array.\n         **/\n        apis: [\n          {\n            /**\n             * API endpoint name. (Required)\n             * https://xxxx.microcms.io/api/v1/posts\n             *\n             * Type: string.\n             **/\n            endpoint: 'posts',\n\n            /**\n             * Graphql type. (Optional)\n             * This is used in GraphQL queries.\n             * If type = 'post', the GraphQL types are named 'microcmsPost' and 'allMicrocmsPost'.\n             *\n             * Type: string.\n             * Default: endpoint value.\n             **/\n            type: 'post',\n\n            /**\n             * microCMS's content type('list' or 'object'). (Optional)\n             * if format is 'list', read all contents by fetching multiple times.\n             *\n             * Type: string.\n             * Default: 'list'.\n             **/\n            format: 'object',\n\n            /**\n             * API request query options. (Optional)\n             *\n             * Type:\n             *   draftKey: string.\n             *   limit: number.\n             *   offset: number.\n             *   fields: string.\n             *   filters: string.\n             *   depth: number.\n             * Default: {}.\n             **/\n            query: {\n              draftKey: 'DRAFT_KEY',\n              limit: 100,\n              offset: 40,\n              fields: ['id', 'title', 'body'].join(','),\n              filters: 'tag[exists]',\n              depth: 2,\n            },\n          },\n        ],\n      },\n    },\n  ],\n};\n```\n\n#### filters\n\nThis plugin provides [filters query](https://microcms.io/blog/filters-parameter/) building helper.\n\n```js\n// gatsby-config.js\nconst {\n  and,\n  contains,\n  exists,\n} = require('gatsby-source-microcms/src/query-builder');\n\nmodule.exports = {\n  plugins: [\n    {\n      resolve: 'gatsby-source-microcms',\n      options: {\n        apis: [\n          {\n            query: {\n              filters: and(contains('title', 'sale'), exists('tag')),\n              //=\u003e `title[contains]sale[and]tag[exists]`\n            },\n          },\n        ],\n      },\n    },\n  ],\n};\n```\n\nHelper list:\n\n- `equals` (alias: `eq`)\n\n```js\nequals('gender', 'women');\n//=\u003e gender[equals]women\n```\n\n- `notEquals` (alias: `neq`)\n\n```js\nnotEquals('gender', 'women');\n//=\u003e gender[not_equals]women\n```\n\n- `lessThan` (alias: `lg`)\n\n```js\nlessThan('createdAt', '2019-11');\n//=\u003e createdAt[less_than]2019-11\n```\n\n- `greaterThan` (alias: `gt`)\n\n```js\ngreaterThan('createdAt', '2019-11');\n//=\u003e createdAt[greater_than]2019-11\n```\n\n- `contains`\n\n```js\ncontains('title', 'sale');\n//=\u003e title[contains]sale\n```\n\n- `exists`\n\n```js\nexists('nextLink');\n//=\u003e nextLink[exists]\n```\n\n- `notExists`\n\n```js\nnotExists('nextLink');\n//=\u003e nextLink[not_exists]\n```\n\n- `beginsWith`\n\n```js\nbeginsWith('publishedAt', '2019-11');\n//=\u003e publishedAt[begins_with]2019-11\n```\n\n- `and`\n\n```js\nand('filter1', 'filter2', ..., 'filter10')\n//=\u003e filter1[and]filter2[and]...[and]filter10\n```\n\n- `or`\n\n```js\nor('filter1', 'filter2', ..., 'filter10')\n//=\u003e filter1[or]filter2[or]...[or]filter10\n```\n\n## Contributing\n\n日本語歓迎 🇯🇵\nPull Request, Issue お気軽にどうぞ。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocmsio%2Fgatsby-source-microcms","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmicrocmsio%2Fgatsby-source-microcms","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmicrocmsio%2Fgatsby-source-microcms/lists"}