Ошибка типа с Pothos Graphql и плагином prisma

Я создаю социальное приложение с nextjs для внешнего интерфейса и SSR, сервером Graphql-yoga и Pothos для типобезопасного GraphQL и Prisma для моей базы данных. Я следовал всем примерам, приведенным во всей их документации по интеграции. Однако я получаю запутанную ошибку.

      ERR Error: Type Post must define one or more fields.

Type User must define one or more fields.

и в моем интерфейсе графического йоги я вижу это сообщение об ошибке

      "message": "Type Post must define one or more fields.\n\nType User must define one or more fields.",

В моем определении типа я четко определил все поля вPostиUserтипа, поэтому я очень запутался и не знаю, о чем идет речь в этой ошибке.

Вот моя структура папок для каталога моего приложения:

      api
 ┣ auth
 ┃ ┗ [...nextauth]
 ┃ ┃ ┣ authorization.ts
 ┃ ┃ ┣ options.ts
 ┃ ┃ ┗ route.ts
 ┗ graphql
 ┃ ┣ types
 ┃ ┃ ┣ Post.ts
 ┃ ┃ ┣ Profile.ts
 ┃ ┃ ┗ User.ts
 ┃ ┣ builder.ts
 ┃ ┣ route.ts
 ┃ ┗ schema.ts

и вот мойPost.tsпапка:

      //./api/graphql/types/Post.ts

import prisma from "@/prisma/database";
import { builder } from "../builder";

export const Post = builder.prismaObject("Post", {
    fields: (t) => ({
        id: t.exposeString("id"),
        visibleTo: t.exposeString("visibleTo"),
        published: t.exposeBoolean("published"),
        hasImage: t.exposeBoolean("hasImage"),
        hasVideo: t.exposeBoolean("hasVideo"),
        createdAt: t.expose("createdAt", { type: Date }),
        updatedAt: t.expose("updatedAt", { type: Date }),
        title: t.exposeString("title", { nullable: true }),
        content: t.exposeString("content", { nullable: true }),
        likes: t.relation("likes"),
        comments: t.relation("comments"),
        media: t.relation("media"),
        category: t.relation("category"),
        viewCount: t.exposeInt("viewCount"),
        author: t.relation("author"),
    }),
});

builder.queryField("posts", (t) =>
    t.prismaField({
        type: ["Post"],
        resolve: async (query, root, args, ctx, info) => {
            return prisma.post.findMany({ ...query });
        },
    })
);

builder.queryFields((t) => ({
    post: t.prismaField({
        type: "Post",
        args: {
            id: t.arg.string({ required: true }),
        },
        resolve: async (query, root, args, ctx, info) => {
            return prisma.post.findUniqueOrThrow({
                where: {
                    id: args.id,
                },
            });
        },
    }),
}));

Вот мойroute.ts:

      // pages/api/graphql/route.ts

import { createYoga } from "graphql-yoga";
import type { NextApiRequest, NextApiResponse } from "next";
import { schema } from "./schema";

const { handleRequest } = createYoga<{
    req: NextApiRequest;
    res: NextApiResponse;
}>({
    schema,
    // While using Next.js file convention for routing, we need to configure Yoga to use the correct endpoint
    graphqlEndpoint: "/api/graphql",

    // Yoga needs to know how to create a valid Next response
    fetchAPI: { Response: Response },
});

export {
    handleRequest as GET,
    handleRequest as POST,
    handleRequest as OPTIONS,
};

0 ответов

Другие вопросы по тегам