question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How does one actually query db data in KS5?

See original GitHub issue

This is probably a dumb question, but… what’s the API for actually executing a query in KS5? In KS4 there was keystone.list("foo").model.find (mongoose queries). I can’t figure out what functions actually accepts the new GraphQL strings 😬 The TODO demo in this repo doesn’t enlighten me either… and the GraphQL API page in the docs is blank… Do you use keystone.executeQuery?

I can’t figure out the whole business with Apollo either. Is that only necessary with the Next integration, but not static?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:6 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
jesstelfordcommented, Sep 8, 2019

This is a great question! One we need to do a better job of answering in the docs.

  1. keystone.executeQuery is what you’ll use 99% of the time - it accepts a GraphQL query string and does all the heavy lifting for you in terms of optimising queries for the particular database adapter in use and resolving relationships, etc. I highly recommend trying this method first. Except when;
  2. You can use the query action which is passed to hooks in the last argument. This is the same as keystone.executeQuery except it executes the query as the currently authenticated user (if your provide the skipAccessControl: true option to the second argument of query, it will behave identically to keystone.executeQuery.
  3. To get access directly to the adapter and construct your own queries, there’s no “official” API (really you should be using keystone.executeQuery wherever possible), but the escape hatch for now is the keystone.adapters object which you can play around with to do raw mongoose or SQL queries.

Apollo comes in two halves;

  1. A GraphQL server implementation. We use this to power the app-graphql server. The fact that it’s Apollo should be treated as an implementation detail.
  2. A client library for making complex cached requests to any GraphQL API. While we use this in the Admin UI, it is 100% not necessary.

In fact, the simplest was to query a GraphQL API is by sending a string in the body of a fetch(). The next simplest way is using the graphql-request npm library which has no caching or any other smarts. Then you get up into the kind-of smart query builders such as urql and draqula, and finally into the really complex caching mechanisms as used by apollo & relay.

0reactions
MadeByMikecommented, Sep 10, 2019

BTW if you are after a SPA - the StaticApp is probably what you want. https://v5.keystonejs.com/keystone-alpha/app-static/ Set the fallback route to your SPA index file and all routes will be redirected there.

Read more comments on GitHub >

github_iconTop Results From Across the Web

What is a database query? - TechTarget
A database query is either an action query or a select query. A select query is one that retrieves data from a database....
Read more >
Best practices when working with Power Query - Microsoft Learn
By default, Power Query offers an automatic data type detection for unstructured data sources. You can read more about this feature and how ......
Read more >
mysql - What is faster, one big query or many small queries?
So the question is, what is faster going from a server side (php, java, asp, ruby, python...) to the database and running one...
Read more >
Query optimization techniques in SQL Server: the basics
In this blog pos we will talk about the basics of Query optimization techniques in SQL Server, and list some of them to...
Read more >
Hierarchical Data in SQL: The Ultimate Guide - Database Star
This will result in a list of all employees with their level from the top level, or root node. The actual query looks...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found