【问题标题】:How to disable Graphql Introspection for Public in Nestjs如何在 Nestjs 中为 Public 禁用 Graphql Introspection
【发布时间】:2022-11-11 23:46:41
【问题描述】:

我想让我的 Graphql API 更安全,我正在寻找一种方法来禁用 Nestjs for Public 中的 Graphql Introspection 或排除某些私有 API 但无法在 Nestjs 文档中找到任何参考的方法,

我有 AuthGuards 设置,但它们不会起到阻止模式访问的目的。

【问题讨论】:

    标签: security graphql nestjs production


    【解决方案1】:

    如果您使用的是 Apollo,答案就在那里in the docs

    const server = new ApolloServer({
      typeDefs,
      resolvers,
      introspection: process.env.NODE_ENV !== 'production'
    });
    

    这会禁用生产中的自省。

    如果您想始终禁用它(不推荐,因为它更难开发):

    introspection: false
    

    【讨论】:

      猜你喜欢
      • 2021-03-01
      • 2020-12-17
      • 2017-11-16
      • 2020-08-10
      • 2020-10-28
      • 2020-03-21
      • 2020-12-14
      • 2021-11-17
      • 1970-01-01
      相关资源
      最近更新 更多