Ошибка Pothos GraphQL: PothosSchemaError: Ref Query не реализован

Я использую Pothos GraphQL для создания схемы и запросов для моего API GraphQL. Я использую Prisma в качестве ORM и@pothos/plugin-prismaкак плагин. Когда я начинаюgraphql-yogaсервер, я получаю сообщение об ошибке ниже.

      file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/config-store.ts:391
    }
     ^
PothosSchemaError: Ref Query has not been implemented
    at ConfigStore.onTypeConfig (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/config-store.ts:391:6)
    at cb (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/config-store.ts:474:3)
    at pendingActions (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/config-store.ts:446:32)
    at Array.forEach (<anonymous>)
    at ConfigStore.typeConfigs [as prepareForBuild] (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/config-store.ts:446:12)
    at BuildCache.builtTypes [as buildAll] (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/build-cache.ts:172:22)
    at SchemaBuilder.toSchema (file:///C:/Users/user/Documents/Projects/project1/node_modules/@pothos/core/src/builder.ts:597:11)
    at file:///C:/Users/user/Documents/Projects/project1/server/schema.ts:5:31
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
[nodemon] app crashed - waiting for file changes before starting...

Этоbuilder.ts:

      import PrismaPlugin from "@pothos/plugin-prisma";
import type PrismaTypes from '@pothos/plugin-prisma/generated';
import { prisma } from "./db.js";
import SchemaBuilder from "@pothos/core";
import {DateResolver} from "graphql-scalars";

export const builder = new SchemaBuilder<{
    Scalars: {
        Date: { Input: Date; Output: Date };
    };
    PrismaTypes: PrismaTypes;
}>({
    plugins: [PrismaPlugin],
    prisma: {
        client: prisma,
    },
});

builder.addScalarType("Date",DateResolver,{});

The schema.tsпросто импортирует объект-строитель и две модели GraphQL:

      import { builder } from "./builder.js";
import "./models/Job.js";
import "./models/JobCostCode.js";

export const schema = builder.toSchema({});

index.tsсоздает и запускает сервер:

      import { createYoga } from 'graphql-yoga'
import { createServer } from 'node:http'
import { schema } from "./schema.js";

const yoga = createYoga({ schema });

const server = createServer(yoga);

server.listen(4000, () => {
    console.log('  Server is running on http://localhost:4000');
});

Я попытался просмотреть документацию Pothos GraphQL, но ничего не нашел. Любая помощь будет оценена по достоинству.

1 ответ

В вашей схеме отсутствует корневой тип запроса.

Используйте этот код для создания типа запроса:

      builder.queryType({
  description: 'The query root type.',
});

Ваш тип запроса, вероятно, также должен иметь несколько полей:

      builder.queryType({
  description: 'The query root type.',
  fields: t => ({
    helloWorld: t.field({ resolve: () => "Hello World" }),
  }),
});

// Or somewhere else

builder.queryField('helloWorld', t => t.field({
  resolve: () => "Hello World",
}));
Другие вопросы по тегам