From cc224341cb13bd65a28e301686544cd4b0483b3b Mon Sep 17 00:00:00 2001
From: Jerel Miller <jerelmiller@gmail.com>
Date: Thu, 13 Aug 2020 02:33:17 -0700
Subject: [PATCH] feat: add limit argument to relatedResources

---
 plugins/gatsby-source-swiftype/gatsby-node.js | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

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));
         },
       },
     },