diff --git a/plugins/gatsby-source-swiftype/gatsby-node.js b/plugins/gatsby-source-swiftype/gatsby-node.js index 2c44dff34..644030939 100644 --- a/plugins/gatsby-source-swiftype/gatsby-node.js +++ b/plugins/gatsby-source-swiftype/gatsby-node.js @@ -65,9 +65,19 @@ exports.createResolvers = ({ createResolvers }) => { createResolvers({ Mdx: { relatedResources: { + args: { + limit: { + type: 'Int', + defaultValue: 5, + }, + }, type: ['RelatedResource!'], - resolve(source, _args, context) { - return context.nodeModel.getNodesByIds({ ids: source.children }); + resolve(source, args, context) { + const { limit } = args; + + return context.nodeModel + .getNodesByIds({ ids: source.children }) + .slice(0, Math.max(limit, 0)); }, }, },