From 3c142a7f1790b6373e546bc0b87d9d85c67a1a79 Mon Sep 17 00:00:00 2001 From: Emanuel Souza Date: Fri, 31 Jul 2020 12:29:11 -0300 Subject: [PATCH 1/3] chore: upgrade storyblok-js-client to v2.5.2 --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 1099add67..f6a59503a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "gatsby-source-storyblok", - "version": "0.2.6", + "version": "0.0.0-development", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -6426,9 +6426,9 @@ "dev": true }, "storyblok-js-client": { - "version": "2.5.1", - "resolved": "https://registry.npmjs.org/storyblok-js-client/-/storyblok-js-client-2.5.1.tgz", - "integrity": "sha512-BNje8bqYmy2f+b2rpD6X7XtksK1ciqw9vohQl8mFE6e1TRpMqT6u8Ep9Va9zh/Pw7SN9vECSiqSKLKUt7dasuA==", + "version": "2.5.2", + "resolved": "https://registry.npmjs.org/storyblok-js-client/-/storyblok-js-client-2.5.2.tgz", + "integrity": "sha512-EfRrQS6XQTsjyaRtlxpbfgw1AVc3OHSP4UrkCUHYeCug7XtFxZGI9+iHPLyUBDny21WjancJ9YqrEGGAIUT/SA==", "requires": { "@babel/runtime-corejs3": "^7.4.5", "axios": "^0.19.0", diff --git a/package.json b/package.json index c85033fa9..d40ffab95 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "Alexander Feiglstorfer ", "dependencies": { "json-stringify-safe": "^5.0.1", - "storyblok-js-client": "^2.5.1" + "storyblok-js-client": "^2.5.2" }, "scripts": { "test": "jest" From 0117f3bd54c534dcfb0745215ca05e43ea7a7ea0 Mon Sep 17 00:00:00 2001 From: Emanuel Souza Date: Fri, 31 Jul 2020 12:51:43 -0300 Subject: [PATCH 2/3] feat: create a separate type for DataSourceEntry and get the dimensions as well --- gatsby-node.js | 33 +++++++++++++++++++++++++++------ src/sync.js | 32 ++++++++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/gatsby-node.js b/gatsby-node.js index 00c47e460..a4a9206a4 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -17,10 +17,10 @@ exports.sourceNodes = async function({ boundActionCreators }, options) { const languages = space.language_codes.map((lang) => { return lang + '/*' }) languages.push('') - for (var spKey = 0; spKey < languages.length; spKey++) { + for (const language of languages) { await Sync.getAll('stories', { node: 'StoryblokEntry', - params: getStoryParams(languages[spKey], options), + params: getStoryParams(language, options), process: (item) => { for (var prop in item.content) { if (!item.content.hasOwnProperty(prop) || ['_editable', '_uid'].indexOf(prop) > -1) { @@ -59,13 +59,34 @@ exports.sourceNodes = async function({ boundActionCreators }, options) { node: 'StoryblokDatasource' }) - for (var dsKey = 0; dsKey < datasources.length; dsKey++) { + for (const datasource of datasources) { + const datasourceSlug = datasource.slug + await Sync.getAll('datasource_entries', { - node: 'StoryblokDatasource', - params: {datasource: datasources[dsKey].slug}, + node: 'StoryblokDatasourceEntry', + params: { + datasource: datasourceSlug + }, process: (item) => { - item.data_source = datasources[dsKey].slug + item.data_source_dimension = null + item.data_source = datasourceSlug } }) + + const datasourceDimensions = datasource.dimensions || [] + + for (const dimension of datasourceDimensions) { + await Sync.getAll('datasource_entries', { + node: 'StoryblokDatasourceEntry', + params: { + datasource: datasourceSlug, + dimension: dimension.entry_value + }, + process: (item) => { + item.data_source_dimension = dimension.entry_value + item.data_source = datasourceSlug + } + }) + } } } diff --git a/src/sync.js b/src/sync.js index ddef0ba2e..2c7d450d7 100644 --- a/src/sync.js +++ b/src/sync.js @@ -28,8 +28,23 @@ module.exports = { }, createNode(name, item) { + const nodeObject = this.builderNode(name, item) + + this.$createNode(nodeObject) + }, + + builderNode (name, item) { + if (name ==='StoryblokDatasourceEntry') { + return this.factoryDatasourceEntryNode(name, item) + } + + return this.factoryDefaultNode(name, item) + }, + + factoryDefaultNode (name, item) { const lang = item.lang || 'default' - const node = Object.assign({}, item, { + + return Object.assign({}, item, { id: `${name.toLowerCase()}-${item.id}-${lang}`, internalId: item.id, parent: null, @@ -40,8 +55,21 @@ module.exports = { contentDigest: crypto.createHash(`md5`).update(stringify(item)).digest(`hex`) } }) + }, - this.$createNode(node) + factoryDatasourceEntryNode (name, item) { + const dimension = item.data_source_dimension || 'default' + return Object.assign({}, item, { + id: `${name.toLowerCase()}-${item.id}-${dimension}`, + internalId: item.id, + parent: null, + children: [], + internal: { + mediaType: `application/json`, + type: name, + contentDigest: crypto.createHash(`md5`).update(stringify(item)).digest(`hex`) + } + }) }, async getOne(single, type, options) { From 6cb4dde19b51155feb5fc6957360a8e66e4477fa Mon Sep 17 00:00:00 2001 From: Emanuel Souza Date: Fri, 31 Jul 2020 12:59:10 -0300 Subject: [PATCH 3/3] docs: update documentation about Datasource and DatasourceEntries --- README.md | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 080a0ca70..e629ba733 100644 --- a/README.md +++ b/README.md @@ -202,10 +202,10 @@ This lets you for example to query for a specific component: } ``` -### Datasources (without the entries) +### Datasources ```GraphQL -allStoryblokDatasource(filter: {data_source: {eq: null}}) { +allStoryblokDatasource { edges { node { id @@ -217,16 +217,35 @@ allStoryblokDatasource(filter: {data_source: {eq: null}}) { } ``` -### Datasource Entries by specific Datasource +### Datasource Entries + +This will return all datasources, with or not dimensions values: + +```GraphQL +allStoryblokDatasourceEntry(filter: { data_source: { eq: "DATASOURCE_SLUG" } }) { + edges { + node { + id + name + value + data_source + data_source_dimension + } + } +} +``` + +If you want to **filter by a specific dimension**, you should use: ```GraphQL -allStoryblokDatasource(filter: { data_source: { eq: "DATASOURCE_SLUG" } }) { +allStoryblokDatasourceEntry(filter: { data_source: { eq: "DATASOURCE_SLUG" }, data_source_dimension: { eq: "DATASOURCE_DIMENSION_VALUE" } }) { edges { node { id name value data_source + data_source_dimension } } }