Nexus resolve() returns PrismaPromise but gives error

I am trying to build an apollo server with Nexus.js, Prisma and Typescript for a to-do app.

I created the Todo nexus type, and I wanted to create the query, but I'm having an error.
The definition:

import { extendType, objectType } from "nexus"; export const Todo = objectType({ name: "Todo", definition(t) { t.id("id"); t.nonNull.string("title"); t.string("detail"); }, }); export const TodoQuery = extendType({ type: "Query", definition(t) { t.list.field("todos", { type: "Todo", resolve(_root, _args, ctx) { return ctx.db.todo.findMany(); // db is an instance of PrismaClient() }, }); }, }); 

The error:

Type '(_root: {}, _args: {}, ctx: Context) => PrismaPromise<Todo[]>' is not assignable to type 'FieldResolver<"Query", "todos">'. Type 'PrismaPromise<Todo[]>' is not assignable to type 'MaybePromise<({ detail?: string | null | undefined; id?: string | null | undefined; title: string; } | null)[] | null>'. Type 'PrismaPromise<Todo[]>' is not assignable to type 'PromiseLike<({ detail?: string | null | undefined; id?: string | null | undefined; title: string; } | null)[] | null>'. Types of property 'then' are incompatible. Type '<TResult1 = Todo[], TResult2 = never>(onfulfilled?: ((value: Todo[]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | null | undefined) => Promise<...>' is not assignable to type '<TResult1 = ({ detail?: string | null | undefined; id?: string | null | undefined; title: string; } | null)[] | null, TResult2 = never>(onfulfilled?: ((value: ({ detail?: string | null | undefined; id?: string | null | undefined; title: string; } | null)[] | null) => TResult1 | PromiseLike<...>) | null | undefined, ...'. Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible. Types of parameters 'value' and 'value' are incompatible. Type 'Todo[]' is not assignable to type '({ detail?: string | null | undefined; id?: string | null | undefined; title: string; } | null)[]'. Type 'Todo' is not assignable to type '{ detail?: string | null | undefined; id?: string | null | undefined; title: string; }'. Types of property 'id' are incompatible. Type 'number' is not assignable to type 'string'. 

1 Answer

ID types in GraphQL are handled as String.
Probably, you are using number as the ID of the todo, so the type does not match, resulting in an error.

const SpecifiedScalars = { ID: 'string', String: 'string', Float: 'number', Int: 'number', Boolean: 'boolean', } 

from

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like