I've been closely following Ben Awad's full-stack tutorial, and everything was going smoothly until I encountered an error while adding a resolver to the schema. Despite using graphql 15.5.1, type-graphql 1.1.1, and apollo-server-express version 2.25.2, my code resulted in the error mentioned above. Here is a snippet of my code:
import {Query, Resolver} from "type-graphql";
@Resolver()
export class HelloResolver {
@Query(() => Number)
hello() {
return 5;
}
}
import { ApolloServer } from "apollo-server-express";
import { buildSchema } from "graphql";
import {HelloResolver} from "./resolvers/hello";
const express = require('express');
const PORT : number = Number(process.env.PORT) || 3000;
const main = async () => {
const apollo = new ApolloServer({
schema: await buildSchema({
// ERROR DUE TO LINE BELOW
resolvers: [HelloResolver],
validate: false,
}),
});
apollo.applyMiddleware({ app });
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}...`);
});
}
main().catch((e) => {
console.error(e);
});