Express 阿波罗GraphQL游乐场:401

Express 阿波罗GraphQL游乐场:401,express,graphql,apollo-server,Express,Graphql,Apollo Server,我能够用Express设置Apollo GraphQL服务器 然而,操场不工作。页面加载,但我尝试从操场上进行的所有查询都会失败,HTTP 401未经授权 我的代码: const server = new ApolloServer({ schema: MySchema, context: ({ req }) => ({ connection: req.context.db, auth: req.context.auth, }), playground: tr

我能够用Express设置Apollo GraphQL服务器

然而,操场不工作。页面加载,但我尝试从操场上进行的所有查询都会失败,HTTP 401未经授权

我的代码:

const server = new ApolloServer({
  schema: MySchema,
  context: ({ req }) => ({
    connection: req.context.db,
    auth: req.context.auth,
  }),
  playground: true,
});

// Add to Express
app.use(server.getMiddleware({ path: '/graphql' }));
游乐场正在localhost:4000/graphql上运行,但是我所做的所有查询都会失败,HTTP 401未经授权。

您需要启用同源策略。看

在制作Prisma游乐场的公司的网页上,正确的文档有点让人困惑。警察不提这件事

const server = new ApolloServer({
  schema: MySchema,
  context: ({ req }) => ({
    connection: req.context.db,
    auth: req.context.auth,
  }),
  playground: {
    settings: {
      // Needed for auth
      // Docs: https://github.com/prisma/graphql-playground
      ['request.credentials']: 'same-origin',
    },
  },
});