【问题标题】:zeit-now v2 + apollo-server-express: playground error: Server cannot be reachedzeit-now v2 + apollo-server-express:操场错误:无法访问服务器
【发布时间】:2019-12-19 22:21:24
【问题描述】:

目前我正在尝试为我的 nextjs 项目工作获取 api。 对于部署,我使用的是 zeit 的 NOW v2(本地通过“now dev”)。

除了 graphql-server 之外,一切正常。

在操场上并通过客户端我收到 404 错误。 查询正在正确执行,但我得到一个错误对象(查询结果在响应字段中;404)。

在 playground-gui 中检查它:同样的问题,在显示消息“无法访问服务器”的 playground-input 字段中。

游乐场初始错误:

{
  "error": "Response not successful: Received status code 404"
}

hello-query 后的游乐场:

{
  "error": {
    "data": {
      "hello": "Hello world!"
    }
  }
}

浏览器-控制台游乐场:

Error: "Response not successful: Received status code 404"

这是我现在加载的 graphql-server:

import express from 'express';
import { ApolloServer, gql } from 'apollo-server-express';

const typeDefs = gql`
    type Query {
        hello: String
    }
`;

const resolvers = {
    Query: {
        hello: () => 'Hello world!',
    },
};

const server = new ApolloServer({ typeDefs, resolvers,
                                    introspection: true, playground: true,
                                    subscriptions: {path: '/api'},
                                });

const app = express();
server.applyMiddleware({ app, path: "/api", cors: true });

module.exports = app;

还尝试了this 示例。同样的问题。

谁能告诉我如何让它正常运行?

【问题讨论】:

    标签: express graphql apollo-server express-graphql vercel


    【解决方案1】:

    我遇到了类似的问题(无法访问服务器)。这是一个授权问题。 GraphQL Playground docs 提到了request.credentials 设置:

    const server = new ApolloServer({
        typeDefs,
        resolvers,
        introspection: true,
        playground: {
          settings: {
            // So that auth works
            // Docs: https://github.com/prisma/graphql-playground
            ['request.credentials']: 'same-origin',
          },
        },
        subscriptions: {path: '/api'}
    });
    

    【讨论】:

      猜你喜欢
      • 2021-11-01
      • 1970-01-01
      • 2020-05-24
      • 2020-12-17
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2019-08-09
      • 2018-05-26
      相关资源
      最近更新 更多