pagination.

This commit is contained in:
Bryce Covert
2018-04-13 15:16:37 -07:00
parent 330a276f60
commit 121a38f20d
5 changed files with 139 additions and 64 deletions

View File

@@ -36,15 +36,22 @@
:resolve :get-vendor-for-invoice}
:company {:type :company
:resolve :get-company-for-invoice}}}}
:resolve :get-company-for-invoice}}}
:invoice_page {:fields {:invoices {:type '(list :invoice)}
:count {:type 'Int}
:total {:type 'Int}
:start {:type 'Int}
:end {:type 'Int}}}}
:queries
{:invoice {:type '(list :invoice)
:args {:imported {:type 'Boolean}
:company_id {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
:resolve :get-invoice}
{:invoice_page {:type '(list :invoice_page)
:args {:imported {:type 'Boolean}
:company_id {:type 'Int}
:start {:type 'Int}
:sort_by {:type 'String}
:asc {:type 'Boolean}}
:resolve :get-invoice-page}
:company {:type '(list :company)
:resolve :get-company}
:vendor {:type '(list :vendor)
@@ -93,17 +100,22 @@
node))
m))
(defn get-invoice [context args value]
(println (<-graphql args))
(defn get-invoice-page [context args value]
(let [extra-context
(cond-> {}
(executor/selects-field? context :invoice/vendor) (assoc :vendor-cache (by (vendors/get-all) :id ))
(executor/selects-field? context :invoice/company) (assoc :company-cache (by (companies/get-all) :id )))]
(executor/selects-field? context :invoice/company) (assoc :company-cache (by (companies/get-all) :id )))
invoices (map
->graphql
(invoices/get-graphql (<-graphql args)))
invoice-count (invoices/count-graphql (<-graphql args))]
(resolve/with-context
(map
->graphql
(invoices/get-graphql (<-graphql args))) extra-context)))
[{:invoices invoices
:total invoice-count
:count (count invoices)
:start (:start args 0)
:end (+ (:start args 0) (count invoices))}] extra-context)))
(defn get-vendor-for-invoice [context args value]
(->graphql
@@ -127,7 +139,7 @@
(def schema
(-> integreat-schema
(attach-resolvers {:get-invoice get-invoice
(attach-resolvers {:get-invoice-page get-invoice-page
:get-vendor-for-invoice get-vendor-for-invoice
:get-company-for-invoice get-company-for-invoice
:get-company get-company