简体   繁体   English

错误:正文必须是字符串。 收到:{ resolvers: [[function HelloResolver]], validate: false } 使用 Type-graphql 和 apollo-server-express 时

[英]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.我一直在关注Ben Awad 的这个全栈教程,当他向架构添加解析器时,一切顺利,但是当我尝试完全相同的代码时,我得到了上面的错误。 I am using graphql 15.5.1 and type-graphql 1.1.1 with apollo-server-express version 2.25.2.我正在使用带有 apollo-server-express 2.25.2 版的 graphql 15.5.1 和 type-graphql 1.1.1。 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 .您可以在视频描述中链接的相同代码中看到这一点。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在GraphQL解析器中访问请求对象(使用Apollo-Server-Express) - How to access the request object inside a GraphQL resolver (using Apollo-Server-Express) NodeError:“文件”参数必须为字符串类型。 使用噩梦时收到的类型对象 - NodeError: The “file” argument must be of type string. Received type object when using nightmare Nextjs -Express App.render“path”参数必须是string类型。 收到类型对象 - Nextjs -Express App.render The “path” argument must be of type string. Received type object gulp Iconify任务引发错误TypeError:路径必须是字符串。 收到假 - gulp Iconify task throws error TypeError: Path must be a string. Received false 为什么会出现错误“必须提供查询字符串”。express-graphql? - Why I'm getting the error “Must provide query string.” express-graphql? Apollo Server,Graphql-必须提供查询字符串 - Apollo Server, Graphql - Must provide query string axios “url”参数必须是字符串类型。 收到类型未定义错误 - axios The "url" argument must be of type string. Received type undefined error ytdl:“url”参数必须是字符串类型。 接收类型未定义 - ytdl: The "url" argument must be of type string. Received type undefined 错误:“路径”参数必须是字符串类型。 收到未定义。 firebase deploy --only 功能 - Error: The “path” argument must be of type string. Received undefined. firebase deploy --only functions 无法从 apollo-server-express 获取函数 - Cannot get functions from apollo-server-express
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM