微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

无法向 GraphQL 服务器发送请求

如何解决无法向 GraphQL 服务器发送请求

我正在通过开发一个非常简单的全栈应用程序来学习 GraphQL。客户端正在 https://localhost:3001 运行。 GraphQL 服务器在 https:localhost:4000 运行。 GraphQL 服务器通过与 json-server 交互来获取数据(用户列表),https:localhost:3000一个Network 上运行的假 REST API。

当我启动我的应用程序时,我在客户端收到一个错误

enter image description here

当我查看{"errors":[{"message":"request to https://localhost:3000/users Failed,reason: write EPROTO 14596:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:\n","locations":[{"line":2,"column":3}],"path":["employees"],"extensions":{"code":"INTERNAL_SERVER_ERROR","exception":{"message":"request to https://localhost:3000/users Failed,"type":"system","errno":"EPROTO","code":"EPROTO","stacktrace":["FetchError: request to https://localhost:3000/users Failed,reason: write EPROTO 14596:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\\ws\\deps\\openssl\\openssl\\ssl\\record\\ssl3_record.c:332:",""," at ClientRequest.<anonymous> (C:\\Users\\Delhivery\\Desktop\\odyssey-lift-off-part1\\server\\node_modules\\node-fetch\\lib\\index.js:1461:11)"," at ClientRequest.emit (events.js:315:20)"," at TLSSocket.socketErrorListener (_http_client.js:469:9)"," at TLSSocket.emit (events.js:315:20)"," at emitErrorNT (internal/streams/destroy.js:106:8)"," at emitErrorCloseNT (internal/streams/destroy.js:74:3)"," at processticksAndRejections (internal/process/task_queues.js:80:21)"]}}}],"data":null} 标签时,错误如下:

import React from "react";
import ReactDOM from "react-dom";
import App from "./App";
import { ApolloClient,ApolloProvider,InMemoryCache } from "@apollo/client";

const client = new ApolloClient({
  uri: "http://localhost:4000",cache: new InMemoryCache(),});

ReactDOM.render(
  <ApolloProvider client={client}>
    <App />
  </ApolloProvider>,document.getElementById("root")
);

我不知道这个错误是什么意思。

代码片段如下:

client/src/index.js

const { ApolloServer } = require("apollo-server");
const typeDefs = require("./schema");
const resolvers = require("./resolvers");
const EmployeesAPI = require("../data-source/employees-api");

const server = new ApolloServer({
  typeDefs,resolvers,dataSources: () => {
    return { employeesAPI: new EmployeesAPI() };
  },});

server.listen(4000,() => {
  console.log(`
    Server is running!
    Listening on port 4000
    `);
});

server/index.js

const { RESTDataSource } = require("apollo-datasource-rest");

class EmployeesAPI extends RESTDataSource {
  constructor() {
    super();
    this.baseURL = "https://localhost:3000";
  }

  getEmployees() {
    return this.get("users");
  }
}

module.exports = EmployeesAPI;

server/data-source/employees-api.js

https:localhost:3000/users

当我访问 with open('sanfrancisco_crashes_cp.json') as json_file: json_data = json.load(json_file) accidents = json_data['accidents'] for accident in accidents: accident['Turn'] = 'right' with open('sanfrancisco_crashes_cp.json',"w") as f: json.dump(json_data,f) 时,我获得了用户列表。

enter image description here

我怎样才能摆脱错误并成功获取数据?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。