Skip to content

Commit

Permalink
drop casts
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Aug 9, 2022
1 parent 53d5bdb commit 112a8f8
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions examples/extend-graphql-schema-graphql-ts/schema.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { list } from '@keystone-6/core';
import { select, relationship, text, timestamp } from '@keystone-6/core/fields';
import { Context, Lists, graphql } from '.keystone';
import { Lists, graphql } from '.keystone';

export const lists: Lists = {
Post: list({
Expand Down Expand Up @@ -33,26 +33,23 @@ export const extendGraphqlSchema = graphql.extend(base => {
fields: {
draft: graphql.field({
type: graphql.Int,
resolve({ authorId }, args, _context) {
const context = _context as Context;
resolve({ authorId }, args, context) {
return context.query.Post.count({
where: { author: { id: { equals: authorId } }, status: { equals: 'draft' } },
});
},
}),
published: graphql.field({
type: graphql.Int,
resolve({ authorId }, args, _context) {
const context = _context as Context;
resolve({ authorId }, args, context) {
return context.query.Post.count({
where: { author: { id: { equals: authorId } }, status: { equals: 'published' } },
});
},
}),
latest: graphql.field({
type: base.object('Post'),
async resolve({ authorId }, args, _context) {
const context = _context as Context;
async resolve({ authorId }, args, context) {
const [post] = await context.db.Post.findMany({
take: 1,
orderBy: { publishDate: 'desc' },
Expand All @@ -70,8 +67,7 @@ export const extendGraphqlSchema = graphql.extend(base => {
// with the name provided or throw if it doesn't exist
type: base.object('Post'),
args: { id: graphql.arg({ type: graphql.nonNull(graphql.ID) }) },
resolve(source, { id }, _context) {
const context = _context as Context;
resolve(source, { id }, context) {
// Note we use `context.db.Post` here as we have a return type
// of Post, and this API provides results in the correct format.
// If you accidentally use `context.query.Post` here you can expect problems
Expand All @@ -90,8 +86,7 @@ export const extendGraphqlSchema = graphql.extend(base => {
id: graphql.arg({ type: graphql.nonNull(graphql.ID) }),
days: graphql.arg({ type: graphql.nonNull(graphql.Int), defaultValue: 7 }),
},
resolve(source, { id, days }, _context) {
const context = _context as Context;
resolve(source, { id, days }, context) {
// Create a date string <days> in the past from now()
const cutoff = new Date(
new Date().setUTCDate(new Date().getUTCDate() - days)
Expand Down

0 comments on commit 112a8f8

Please sign in to comment.