Git Product home page Git Product logo

Comments (2)

pujianjun avatar pujianjun commented on August 21, 2024 2

@dzzzzzy 谢谢大神!我统一了我 graphql 接口返回结构{ code: xxx, message: xxx, data: xxx } ,异常也按这样结构返回了,十分感谢!

from nestjs-learning.

dzzzzzy avatar dzzzzzy commented on August 21, 2024 1

@pujianjun 这个是因为在拦截器里把返回值修改成了 { code: xxx, message: xxx } 这种结构,而 sayHello 接口只是返回了 String 类型,所以不是预期的结果,你想要把异常信息修改成你预期的,那你所有的 graphql 接口都必须是统一的结构,类似:{ code: xxx, message: xxx, data: xxx } 这种。


GraphQL 也有格式化返回值和异常的方法(formatResponseformatError),但是我觉得这种不太好用,你可以根据你的情况看看要不要使用:

GraphQLModule.forRoot({
    typePaths: ['./**/*.graphql'],
    installSubscriptionHandlers: true,
    formatResponse: (res, req) => {
        return res;
    },
    formatError: err => {
        return err;
    }
})

from nestjs-learning.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.