Skip to content

Commit

Permalink
Merge pull request #91 from TylerBarnes/fix/reference-field-dependenc…
Browse files Browse the repository at this point in the history
…y-tracking

fix(schema-customization): reference field dependency tracking for inc builds
  • Loading branch information
Ninad Hatkar authored Apr 23, 2021
2 parents b4ee818 + 1ddbb5c commit 140777d
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
37 changes: 21 additions & 16 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,18 +393,19 @@ exports.createResolvers = function (_ref7) {
resolve: function resolve(source, args, context, info) {
if (fileField.field.multiple && source[fileField.field.uid + '___NODE']) {
var nodesData = [];

source[fileField.field.uid + '___NODE'].forEach(function (id) {
context.nodeModel.getAllNodes().find(function (node) {
if (node.id === id) {
nodesData.push(node);
}
});
var existingNode = context.nodeModel.getNodeById({ id: id });

if (existingNode) {
nodesData.push(existingNode);
}
});

return nodesData;
} else {
return context.nodeModel.getAllNodes().find(function (node) {
return node.id === source[fileField.field.uid + '___NODE'];
});
var id = source[fileField.field.uid + '___NODE'];
return context.nodeModel.getNodeById({ id: id });
}
}
}));
Expand All @@ -414,13 +415,17 @@ exports.createResolvers = function (_ref7) {
resolve: function resolve(source, args, context, info) {
if (source[reference.uid + '___NODE']) {
var nodesData = [];

source[reference.uid + '___NODE'].forEach(function (id) {
context.nodeModel.getAllNodes().find(function (node) {
if (node.id === id) {
nodesData.push(node);
}
var existingNode = context.nodeModel.getNodeById({
id: id
});

if (existingNode) {
nodesData.push(existingNode);
}
});

return nodesData;
}
return [];
Expand All @@ -440,8 +445,8 @@ exports.createResolvers = function (_ref7) {
createResolvers(resolvers);
};

exports.pluginOptionsSchema = function (_ref7) {
var Joi = _ref7.Joi;
exports.pluginOptionsSchema = function (_ref8) {
var Joi = _ref8.Joi;

return Joi.object({
api_key: Joi.string().required().description('API Key is a unique key assigned to each stack.'),
Expand All @@ -455,7 +460,7 @@ exports.pluginOptionsSchema = function (_ref7) {
};

var validateContentstackAccess = function () {
var _ref8 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(pluginOptions) {
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee3(pluginOptions) {
var host;
return _regenerator2.default.wrap(function _callee3$(_context3) {
while (1) {
Expand Down Expand Up @@ -494,6 +499,6 @@ var validateContentstackAccess = function () {
}));

return function validateContentstackAccess(_x5) {
return _ref8.apply(this, arguments);
return _ref9.apply(this, arguments);
};
}();
30 changes: 18 additions & 12 deletions src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,17 +350,19 @@ exports.createResolvers = ({ createResolvers }) => {
resolve(source, args, context, info) {
if (fileField.field.multiple && source[`${fileField.field.uid}___NODE`]) {
const nodesData = [];

source[`${fileField.field.uid}___NODE`].forEach(id => {
context.nodeModel.getAllNodes().find(node => {
if (node.id === id) {
nodesData.push(node);
}
});
const existingNode = context.nodeModel.getNodeById({ id })

if (existingNode) {
nodesData.push(existingNode);
}
});

return nodesData;
} else {
return context.nodeModel.getAllNodes().find(
node => node.id === source[`${fileField.field.uid}___NODE`])
const id = source[`${fileField.field.uid}___NODE`]
return context.nodeModel.getNodeById({ id })
}
},
},
Expand All @@ -374,13 +376,17 @@ exports.createResolvers = ({ createResolvers }) => {
resolve(source, args, context, info) {
if (source[`${reference.uid}___NODE`]) {
const nodesData = [];

source[`${reference.uid}___NODE`].forEach(id => {
context.nodeModel.getAllNodes().find(node => {
if (node.id === id) {
nodesData.push(node);
}
});
const existingNode = context.nodeModel.getNodeById({
id
})

if (existingNode) {
nodesData.push(existingNode);
}
});

return nodesData;
}
return [];
Expand Down

0 comments on commit 140777d

Please sign in to comment.