Skip to content

Commit

Permalink
add types for virtual-field examples
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens committed Mar 24, 2022
1 parent 5a43deb commit 3751084
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/virtual-field/schema.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { list, graphql } from '@keystone-6/core';
import { select, relationship, text, timestamp, virtual } from '@keystone-6/core/fields';
import { BaseItem } from '@keystone-6/core/types';
import { Lists } from '.keystone/types';

export const lists = {
export const lists: Lists = {
Post: list({
fields: {
title: text({ validation: { isRequired: true } }),
Expand Down Expand Up @@ -42,7 +42,7 @@ export const lists = {
paragraphs: graphql.field({ type: graphql.Int }),
},
}),
resolve(item: any) {
resolve(item) {
const content = item.content || '';
return {
words: content.split(' ').length,
Expand All @@ -59,7 +59,7 @@ export const lists = {
args: {
length: graphql.arg({ type: graphql.nonNull(graphql.Int), defaultValue: 200 }),
},
resolve(item: BaseItem, { length }) {
resolve(item, { length }) {
if (!item.content) {
return null;
}
Expand All @@ -79,7 +79,7 @@ export const lists = {
authorName: virtual({
field: graphql.field({
type: graphql.String,
async resolve(item: BaseItem, args, context) {
async resolve(item, args, context) {
const { author } = await context.query.Post.findOne({
where: { id: item.id.toString() },
query: 'author { name }',
Expand All @@ -100,7 +100,7 @@ export const lists = {
field: lists =>
graphql.field({
type: lists.Post.types.output,
async resolve(item: BaseItem, args, context) {
async resolve(item, args, context) {
const { posts } = await context.query.Author.findOne({
where: { id: item.id.toString() },
query: `posts(
Expand Down

0 comments on commit 3751084

Please sign in to comment.