简体   繁体   中英

Error: Body must be a string. Received: { resolvers: [[function HelloResolver]], validate: false } when using Type-graphql and apollo-server-express

I have been following this full-stack tutorial by Ben Awad and when he added a resolver to the schema, everything went well, but when I tried the exact same code I get the error above. I am using graphql 15.5.1 and type-graphql 1.1.1 with apollo-server-express version 2.25.2. My code looks like this:

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

import { buildSchema } from "graphql";

should be

import { buildSchema } from "type-graphql";

You can see that in the same code linked in the video description .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM