Last active
February 10, 2021 09:31
Revisions
-
iksent revised this gist
Feb 10, 2021 . 1 changed file with 8 additions and 4 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,10 @@ const path = require('path') const fs = require('fs') function replaceAll(str, find, replace) { return str.replace(new RegExp(find, 'g'), replace) } export const createSchemaCustomization = ({ actions, schema }) => { const { createTypes } = actions @@ -12,12 +16,12 @@ export const createSchemaCustomization = ({ actions, schema }) => { .readFileSync(path.resolve('../backend/exports/graphql/schema.graphql'), 'utf8') .toString() // Changed name for reserved scalars: strapiTypes = replaceAll(strapiTypes, 'scalar JSON', 'scalar JSON__IGNORED') strapiTypes = replaceAll(strapiTypes, 'scalar Date\n', 'scalar Date__IGNORED\n') // Change name for File-type: strapiTypes = replaceAll(strapiTypes, 'type UploadFile {', 'type UploadFile__IGNORED {') // Change File-type to type with localFile strapiTypes = replaceAll(strapiTypes, 'UploadFile', 'LocalFile') const myTypes = ` type LocalFile { -
iksent created this gist
Feb 10, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,66 @@ const path = require('path') const fs = require('fs') export const createSchemaCustomization = ({ actions, schema }) => { const { createTypes } = actions // // Solving "dummy-content" problem for Strapi Dynamic Zones: // let strapiTypes = fs .readFileSync(path.resolve('../backend/exports/graphql/schema.graphql'), 'utf8') .toString() // Changed name for reserved scalars: strapiTypes = strapiTypes.replaceAll('scalar JSON', 'scalar JSON__IGNORED') strapiTypes = strapiTypes.replaceAll('scalar Date\n', 'scalar Date__IGNORED\n') // Change name for File-type: strapiTypes = strapiTypes.replaceAll('type UploadFile {', 'type UploadFile__IGNORED {') // Change File-type to type with localFile strapiTypes = strapiTypes.replaceAll('UploadFile', 'LocalFile') const myTypes = ` type LocalFile { localFile: File @link(from: "localFile___NODE") } type StrapiProject implements Node { sections_start: [UnionDynamicSection] sections_end: [UnionDynamicSection] } type StrapiOutsourcingPage implements Node { sections: [UnionDynamicSection] } type StrapiCompanyPage implements Node { sections: [UnionDynamicSection] } type StrapiDesignPage implements Node { sections: [UnionDynamicSection] } type StrapiPortfolioPage implements Node { dynamic: [UnionDynamicSection] } ` const ComponentsByType = { image_text: 'ComponentSectionsSectionImageText', counters: 'ComponentSectionsSectionCounters', texts: 'ComponentSectionsSectionTexts', techs: 'ComponentSectionsSectionTechs', dev: 'ComponentSectionsSectionDev', advanced: 'ComponentSectionsSectionAdvanced', } const PortfolioPageDynamicDynamicZone = schema.buildUnionType({ name: `UnionDynamicSection`, types: Object.values(ComponentsByType), resolveType: (value, info) => { // Each section has a special hidden param "type" return ComponentsByType[value.type] || 'ComponentSectionsSectionTexts' }, }) createTypes(strapiTypes) createTypes(myTypes) createTypes([PortfolioPageDynamicDynamicZone]) } This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,4 @@ require(`@babel/register`)({ presets: ['@babel/preset-env', '@babel/preset-react'], }) module.exports = require(`./gatsby-node-es6.js`) This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,10 @@ Frontend: { "gatsby-source-strapi": "^1.0.0-alpha.0", "gatsby": "^2.32.3", } Backend: { "strapi": "3.4.3", }