Skip to content

Commit abb2075

Browse files
author
Kazuki Shibata
authored
Merge pull request #13 from wantainc/add/global-draft-key
X-GLOBAL-DRAFT-KEYを設定できるようにする
2 parents e3ab3db + 72b3185 commit abb2075

File tree

6 files changed

+16
-2
lines changed

6 files changed

+16
-2
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,14 @@ module.exports = {
9292
**/
9393
apiKey: '11111111-2222-3333-4444-555555555555',
9494

95+
/**
96+
* Global draft key.
97+
* If you set this key, you can get all draft contents.
98+
*
99+
* Type: string.
100+
**/
101+
globalDraftKey: '11111111-2222-3333-4444-555555555555',
102+
95103
/**
96104
* Service information. (Required)
97105
* xxxx.microcms.io

example/gatsby-config.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ require('dotenv').config();
22

33
// We prepared one service to make it easy for anyone to develop.
44
const MICROCMS_API_KEY = 'dc59f358-4622-471f-8d1e-6c7a6f969558';
5+
const MICROCMS_GLOBAL_DRAFT_KEY = '0523713e-efeb-4aec-87fd-12c58588c4e3';
56
const MICROCMS_SERVICE_ID = 'example';
67

78
const { and, equals, exists, notExists } = require('../src/query-builder');
@@ -17,6 +18,7 @@ module.exports = {
1718
resolve: require.resolve('../gatsby-node'),
1819
options: {
1920
apiKey: process.env.MICROCMS_API_KEY || MICROCMS_API_KEY,
21+
globalDraftKey: process.env.MICROCMS_GLOBAL_DRAFT_KEY || MICROCMS_GLOBAL_DRAFT_KEY,
2022
serviceId: process.env.MICROCMS_SERVICE_ID || MICROCMS_SERVICE_ID,
2123
apis: [
2224
{

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gatsby-source-microcms",
3-
"version": "1.0.1",
3+
"version": "1.1.0",
44
"description": "Source plugin for Gatsby from microCMS.",
55
"main": "gatsby-node.js",
66
"license": "MIT",

src/fetch.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const fetch = require('node-fetch');
77
* @param {string} param.apiKey
88
* @param {object} param.query
99
*/
10-
module.exports = function fetchData(url, { apiKey, query }) {
10+
module.exports = function fetchData(url, { apiKey, globalDraftKey, query }) {
1111
// remove empty string or undefined or null query
1212
for (let q in query) {
1313
if (!query[q]) {
@@ -21,6 +21,7 @@ module.exports = function fetchData(url, { apiKey, query }) {
2121
return fetch(reqUrl, {
2222
headers: {
2323
'x-api-key': apiKey,
24+
'x-global-draft-key': globalDraftKey,
2425
},
2526
}).then(async res => {
2627
const body = await res.json();

src/pluginOptions.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const optionsSchema = Joi.object().keys({
1717
apiKey: Joi.string()
1818
.required()
1919
.empty(),
20+
globalDraftKey: Joi.string(),
2021
serviceId: Joi.string()
2122
.required()
2223
.empty(),

src/sourceNodes.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const sourceNodes = async (
2929
const query = { ...api.query, offset };
3030
const { statusCode, body } = await fetchData(apiUrl, {
3131
apiKey: pluginConfig.get('apiKey'),
32+
globalDraftKey: pluginConfig.get('globalDraftKey'),
3233
query,
3334
});
3435
if (statusCode !== 200) {
@@ -67,6 +68,7 @@ message: ${body.message}`);
6768
// get object data
6869
const { statusCode, body } = await fetchData(apiUrl, {
6970
apiKey: pluginConfig.get('apiKey'),
71+
globalDraftKey: pluginConfig.get('globalDraftKey'),
7072
query: api.query,
7173
});
7274

0 commit comments

Comments
 (0)