ApolloServer 2.0:游乐场设置中的奇怪条目 JSON

ApolloServer 2.0: Strange entries in playground settings JSON

我正在 运行 将 Apollo Server 2.0 与 Express 结合使用来制作 GraphQL 原型 API。这是我的 ApolloServer init 的样子(我的服务器脚本的一部分):

// GraphQL: Schema
const server = new ApolloServer({
  typeDefs,
  resolvers,
  playground: {
    endpoint: `/blog/`,
    settings: './playground.json'
  }
});

按照 Prisma Github page 上的建议,我将设置值提取到单独的 JSON 文件中,如下所示:

// playground.json
{
  "general.betaUpdates": false,
  "editor.cursorShape": "line",
  "editor.fontSize": 14,
  "editor.fontFamily": "'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace",
  "editor.theme": "dark",
  "editor.reuseHeaders": true,
  "prettier.printWidth": 80,
  "request.credentials": "omit",
  "tracing.hideTracingResponse": true
}

这个设置工作得很好。除了当我 运行 服务器并在浏览器中查看加载到 playground 的设置时,我注意到 JSON:

中的一些奇怪但无害的条目
{
  "0": ".",
  "1": "/",
  "2": "p",
  "3": "l",
  "4": "a",
  "5": "y",
  "6": "g",
  "7": "r",
  "8": "o",
  "9": "u",
  "10": "n",
  "11": "d",
  "12": ".",
  "13": "j",
  "14": "s",
  "15": "o",
  "16": "n",
  "general.betaUpdates": false,
  "editor.cursorShape": "line",
  "editor.fontSize": 14,
  "editor.fontFamily": "'Source Code Pro', 'Consolas', 'Inconsolata', 'Droid Sans Mono', 'Monaco', monospace",
  "editor.theme": "dark",
  "editor.reuseHeaders": true,
  "prettier.printWidth": 80,
  "request.credentials": "omit",
  "tracing.hideTracingResponse": true
}

知道可能出了什么问题吗?

游乐场设置应该是对象,但你提供了字符串。您可以使用 require.

修复该问题
const server = new ApolloServer({
  typeDefs,
  resolvers,
  playground: {
    endpoint: `/blog/`,
    settings: require('./playground.json')
  }
});

服务器只提供默认设置。浏览器有本地设置和作曲。