【问题标题】:ApolloServer 2.0: Strange entries in playground settings JSONApolloServer 2.0:游乐场设置 JSON 中的奇怪条目
【发布时间】:2019-07-14 02:08:00
【问题描述】:

我正在使用 Express 运行 Apollo Server 2.0 来构建 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
}

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

【问题讨论】:

    标签: graphql apollo-server


    【解决方案1】:

    游乐场设置应该是对象,但您提供字符串。您可以使用 require 解决此问题。

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

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

    【讨论】:

      猜你喜欢
      • 2015-12-20
      • 2021-04-06
      • 2021-10-18
      • 2017-01-07
      • 1970-01-01
      • 2017-12-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多