Skip to content

Commit

Permalink
update schema manipulation for gatsby v4
Browse files Browse the repository at this point in the history
  • Loading branch information
CiotkaCierpienia committed Jan 10, 2022
1 parent a177086 commit 13a0ac5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
25 changes: 16 additions & 9 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ let createNodeGlobal;
let resolveMissingRelationsGlobal;
let downloadMediaFileGlobal = false;
let headers = {};
let globalSchema = {};
let contentTypeDefsData = [];

exports.sourceNodes = async (gatsbyFunctions, options) => {

const {actions, store, getNodes, reporter, schema} = gatsbyFunctions;
const {createNode, setPluginStatus, touchNode, deleteNode} = actions;
exports.onPluginInit = async ({actions, schema, reporter}, options) => {
const {createNode} = actions;
const {
baseUrl = "https://api.flotiq.com",
authToken,
forceReload,
includeTypes = null,
resolveMissingRelations = true,
downloadMediaFile = false
Expand All @@ -37,6 +36,8 @@ exports.sourceNodes = async (gatsbyFunctions, options) => {
resolveMissingRelationsGlobal = resolveMissingRelations;
downloadMediaFileGlobal = downloadMediaFile;
apiUrl = baseUrl;
globalSchema = schema;
contentTypeDefsData = await getContentTypes(options, apiUrl);

if (!apiUrl) {
reporter.panic('FLOTIQ: You must specify API url ' +
Expand All @@ -50,6 +51,14 @@ exports.sourceNodes = async (gatsbyFunctions, options) => {
if (includeTypes && (!Array.isArray(includeTypes) || typeof includeTypes[0] !== "string")) {
reporter.panic("FLOTIQ: `includeTypes` should be an array of content type api names. It cannot be empty.");
}
}

exports.sourceNodes = async (gatsbyFunctions, options) => {

const {actions, store, getNodes, reporter, schema} = gatsbyFunctions;
const {createNode, setPluginStatus, touchNode, deleteNode} = actions;
const {forceReload} = options;

try {
if (forceReload) {
setPluginStatus({'updated_at': null});
Expand All @@ -64,9 +73,6 @@ exports.sourceNodes = async (gatsbyFunctions, options) => {
lastUpdate = undefined;
}

const contentTypeDefsData = await getContentTypes(options, apiUrl);
createTypeDefs(contentTypeDefsData, schema);

let changed = 0;
let removed = 0;

Expand Down Expand Up @@ -110,8 +116,9 @@ exports.sourceNodes = async (gatsbyFunctions, options) => {
return {};
};

exports.createSchemaCustomization = ({actions}) => {
exports.createSchemaCustomization = ({actions}, options) => {
const {createTypes} = actions;
createTypeDefs(contentTypeDefsData, globalSchema);

typeDefinitionsPromise.then(typeDefs => {
typeDefs.push(`type FlotiqInternal {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "gatsby-source-flotiq",
"version": "4.1.2",
"version": "4.1.3",
"license": "MIT",
"author": "Flotiq team <hello@flotiq.com>",
"repository": "https://github.com/flotiq/gatsby-source-flotiq",
Expand Down

0 comments on commit 13a0ac5

Please sign in to comment.