From f4a22d0cab2ec078de34db98b92206c1b9cdadf1 Mon Sep 17 00:00:00 2001
From: Jacob Larfors <jlarfors@verifa.io>
Date: Wed, 26 May 2021 17:53:01 +0300
Subject: [PATCH] Define a default limit for all subqueries

---
 store/postgres_graphql.go | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/store/postgres_graphql.go b/store/postgres_graphql.go
index 094fb652..607156bd 100644
--- a/store/postgres_graphql.go
+++ b/store/postgres_graphql.go
@@ -14,8 +14,9 @@ import (
 )
 
 const (
-	orderAsc  string = "ASC"
-	orderDesc string = "DESC"
+	orderAsc     string = "ASC"
+	orderDesc    string = "DESC"
+	defaultLimit uint64 = 100
 )
 
 // tableColumns is used to store the columns that are SELECT'd in a SQl
@@ -329,6 +330,10 @@ func psqlSubQuery(tenant string, graph *SchemaGraph, sql *sq.SelectBuilder, pare
 		}
 	}
 
+	// Set a default limit on each query
+	if limitArg == nil {
+		nodeQuery = nodeQuery.Limit(defaultLimit)
+	}
 	if limitArg != nil {
 		limitStr, ok := limitArg.Value.GetValue().(string)
 		if !ok {