小编Orb*_*bit的帖子

无法读取未定义的属性“fetch”

我正在尝试将 REST 数据源添加到我的 Apollo 服务器。我创建了一个扩展 RESTDataSource 的类,其中包含所有 API 请求。当尝试从我的 GraphQL 解析器代码调用登录方法时,会抛出错误

我怎样才能解决这个问题?

我已经尝试过:在 API 类构造函数中绑定登录和获取方法

this.login = this.login.bind(this); this.fetch = this.fetch.bind(this);

从构造函数调用登录方法

REST数据源类

class API extends RESTDataSource {
        constructor() {
            super();
            this.baseURL = URL;

            this.login = this.login.bind(this);
            this.fetch = this.fetch.bind(this);
            console.log(this.fetch);
            console.log(this.login);

        }
        initialize(config) {
            //config can store different information
            //the current user can be stored in config.context for easy  access
            this.context = config.context;

        }

        async login(username, password) {
            return this.post(`/`, {
                "id": 1
            }, {
                "method": "authenticate"
            }, { …
Run Code Online (Sandbox Code Playgroud)

javascript node.js graphql apollo-server

3
推荐指数
1
解决办法
7872
查看次数

标签 统计

apollo-server ×1

graphql ×1

javascript ×1

node.js ×1