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

时间:2019-02-20 11:36:41

标签: graphql apollo-server

我正在运行带有Express的Apollo Server 2.0,以制作GraphQL API的原型。这是我的ApolloServer初始化的样子(服务器脚本的一部分):

// 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
}

此设置工作正常。除了我运行服务器并在浏览器中查看加载到操场上的设置之外,我注意到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
}

任何想法可能出什么问题吗?

1 个答案:

答案 0 :(得分:1)

操场设置应该是对象,但是您要提供字符串。您可以使用require进行修复。

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

服务器仅提供默认设置。浏览器具有本地设置并进行排版。