Keystone 6: Server-Side Query APIs #388
Unanswered
molomby
asked this question in
Upgrading to Keystone 6
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
In Keystone 5, if you wanted to query the database from in server-side code, you'd probably reach for either:
keystone.executeQuery()
context.executeGraphQL()
keystone.adapters['KnexAdapter'].knex
Keystone 6 replaces these with several new APIs:
context.query
– A typed programmatic API for running CRUD operations against your GraphQL API.context.db
– This looks superficially similar to the query API but deals with the internal item objects. This is what you should use if the result is to be returned via a GraphQL resolvers.context.graphql.run
andcontext.graphql.raw
– These are more similar to how you'd use the GraphQL API remotely, that is, you supply the full GraphQL query as a string, rather than dealing with a JavaScript API.context.prisma
– The raw Prisma Client object used internally by Keystone.For example, consider this server-side Keystone 5 code that uses
keystone.executeQuery()
to loads a set of users, based on a partial name match, and retrieves their published posts:In Keystone 6 you'd likely use the query API instead:
Note that the GraphQL API itself has also been updated. These changes are described in detail on the Docs site; see also the discussion here on GitHub.
Beta Was this translation helpful? Give feedback.
All reactions