PothosSchemaError: Ref ObjectRef<Profile> has not been implemented
mike-j-gibson opened this issue · comments
I am following the example:
https://github.com/prisma/prisma-examples/tree/latest/typescript/graphql#using-the-graphql-api.
At the following step (section 2.1) the code breaks.
Update the User object type to include the `profile field:
// ./src/schema/user.ts
builder.prismaObject('User', {
fields: (t) => ({
id: t.exposeInt('id'),
name: t.exposeString('name', { nullable: true }),
email: t.exposeString('email'),
posts: t.relation('posts'),
profile: t.relation('profile'),
}),
})
Also, I did complete the next step: 2.2. Add a createProfile GraphQL mutation. If I remove the line for the profile for the user then everything works.
The error is
[INFO] 13:55:20 Restarting: C:\prisma_postgresql_api\typescript_graphql\src\schema\user.ts has been modified
PothosSchemaError: Ref ObjectRef has not been implemented
at new PothosError (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\errors.ts:7:5)
at new PothosSchemaError (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\errors.ts:14:5)
at ConfigStore.getTypeConfig (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\config-store.ts:289:13)
at BuildCache.getType (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:444:41)
at BuildCache.getOutputType (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:458:23)
at BuildCache.buildOutputTypeParam (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:283:36)
at BuildCache.buildFields (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:345:20)
at BuildCache.getObjectFields (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:410:31)
at BuildCache.getFields (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:425:19)
at fields (C:\prisma_postgresql_api\typescript_graphql\node_modules@pothos\core\src\build-cache.ts:558:26)
[ERROR] 13:55:21 PothosSchemaError: Ref ObjectRef has not been implemented
Here is what I have for the profile.ts
import { builder } from "../builder";
import { prisma } from '../db'
import { UserUniqueInput } from './user';
builder.prismaObject('Profile', {
fields: (t) => ({
id: t.exposeInt('id'),
bio: t.exposeString('bio', { nullable: true }),
user: t.relation('user'),
}),
})
builder.mutationField('createProfile', (t) =>
t.prismaField({
type: 'Profile',
args: {
bio: t.arg.string({ required: true }),
data: t.arg({ type: UserUniqueInput })
},
resolve: async (query, _parent, args, _context) =>
prisma.profile.create({
...query,
data: {
bio: args.bio,
user: {
connect: {
id: args.data?.id || undefined,
email: args.data?.email || undefined
}
}
}
})
})
)
Here is what I have for the user.ts
import { builder } from '../builder'
import { prisma } from '../db'
import { PostCreateInput } from './post'
builder.prismaObject('User', {
fields: (t) => ({
id: t.exposeInt('id'),
name: t.exposeString('name', { nullable: true }),
email: t.exposeString('email'),
posts: t.relation('posts'),
profile: t.relation('profile'),
}),
})
export const UserUniqueInput = builder.inputType('UserUniqueInput', {
fields: (t) => ({
id: t.int(),
email: t.string(),
}),
})
const UserCreateInput = builder.inputType('UserCreateInput', {
fields: (t) => ({
email: t.string({ required: true }),
name: t.string(),
posts: t.field({ type: [PostCreateInput] }),
}),
})
builder.queryFields((t) => ({
allUsers: t.prismaField({
type: ['User'],
resolve: (query) => prisma.user.findMany({ ...query }),
}),
}))
builder.mutationFields((t) => ({
signupUser: t.prismaField({
type: 'User',
args: {
data: t.arg({
type: UserCreateInput,
required: true,
}),
},
resolve: (query, parent, args) => {
return prisma.user.create({
...query,
data: {
email: args.data.email,
name: args.data.name,
posts: {
create: (args.data.posts ?? []).map((post) => ({
title: post.title,
content: post.content ?? undefined,
})),
},
},
})
},
}),
}))
Instructions need to add the line "import './profile'" to the ./src/schema/index.ts