Comments (2)
@dzzzzzy 谢谢大神!我统一了我 graphql 接口返回结构{ code: xxx, message: xxx, data: xxx } ,异常也按这样结构返回了,十分感谢!
from nestjs-learning.
@pujianjun 这个是因为在拦截器里把返回值修改成了 { code: xxx, message: xxx }
这种结构,而 sayHello
接口只是返回了 String
类型,所以不是预期的结果,你想要把异常信息修改成你预期的,那你所有的 graphql 接口都必须是统一的结构,类似:{ code: xxx, message: xxx, data: xxx }
这种。
GraphQL 也有格式化返回值和异常的方法(formatResponse
和 formatError
),但是我觉得这种不太好用,你可以根据你的情况看看要不要使用:
GraphQLModule.forRoot({
typePaths: ['./**/*.graphql'],
installSubscriptionHandlers: true,
formatResponse: (res, req) => {
return res;
},
formatError: err => {
return err;
}
})
from nestjs-learning.
Related Issues (20)
- Dependency Dashboard
- postgres在windows下安装失败,无法使用
- async findAll(): Cat[] { return this.cats; }
- 嵌套的module应该怎么使用啊? HOT 3
- @nestjs/passport 抛出异常错误无法拦截的吗? HOT 4
- guard中怎么注入service? HOT 2
- 启动 unable connect database HOT 2
- 可否来一发typeorm事务demo? HOT 7
- 老板讲讲nest cloud? HOT 1
- 上传文件时的异常
- graphql-api demo能完善auth 验证部分? HOT 1
- 学的人还是太少,都没人提问 HOT 1
- TypeORM createQueryBuilder groupBy FORMAT YYYY-MM-DD HOT 2
- 数据库更换为Sqlite3的简单方法
- 楼主有没有考虑出一个供多个端使用的 nestjs + mysql 的服务demo? HOT 1
- 遇到了单元测试的问题
- 使用nestjs/config,class在启动时获取不到process.env,如何解决 HOT 1
- typeorm连接数据库时,ormconfig.json entities的路径配置问题
- 继续更新吗?
- nestJS 中graphql 对bigint怎么处理
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nestjs-learning.