Apollo-server-express 自省已禁用,但仍然可以通过 websocket 连接

Apollo-server-express introspection disabled but still possible over websocket connections

我们使用 apollo-server-express 公开一个 graphql 服务器。

对于此服务器,我们已将内省变量设置为 false 以向外部世界隐藏我们的模式,这对于通过 rest 调用的 Graphql 调用工作正常。

然而,当我们与同一台服务器建立 websocket 连接时,我们设法执行自省查询,即使在 apollo 服务器实例化期间,自省被显式设置为 false

启动 Apollo 服务器的配置如下所示:

{
   schema: <schema>,
   context: <context_function>,
   formatError: <format_error_function>,
   debug: false,
   tracing: false,
   subscriptions: {
       path: <graphQl_path>,
       keepAlive: <keep_alive_param>,
       onConnect: <connect_function>,
       onDisconnect: <disconnect_function>
   },
   introspection: false,
   playground: false
};

有人遇到过类似的问题吗?如果是,你能解决它吗?如何解决?

apollo-server-express 版本 = 2.1.0

npm 版本 = 6.4.1

节点版本 = 10.13.0

什么 ApolloServer does internally 阻止您使用 __schema__type 解析器。我假设你可以做同样的事情:

export const resolvers = {
  Query: {
    __type() {
      throw new Error('You cannot make introspection');
    },
    __schema() {
      throw new Error('You cannot make introspection');
    }
  }
}