Pothos GraphQL error: PothosSchemaError: Ref Query has not been implemented

1.7k Views Asked by At

I'm using Pothos GraphQL to create the schema and queries for my graphQL API. I'm using Prisma as the ORM and @pothos/plugin-prisma as the plugin. When I start the graphql-yoga server, I get the error below.

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...

This is 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 just imports the builder object and the two graphQL models:

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

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

index.ts creates and starts the server:

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');
});

I tried looking at the Pothos GraphQL Docs but would not find anything. Any help would be appreciated.

1

There are 1 best solutions below

0
On BEST ANSWER

Your schema is lacking a root query type.

Use this code to create a query type:

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

Your query type should probably also have some fields:

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",
}));