gpt4 book ai didi

javascript - 在 javascript 中使用 Public 关键字时出现意外标记

转载 作者:行者123 更新时间:2023-12-01 00:39:15 24 4
gpt4 key购买 nike

根据 Apollo 文档添加自定义指令如下:

class isAuth extends SchemaDirectiveVisitor {
// field defination for resolving
// directive.
public visitFieldDefinition(field) {
// overspreading.
const { resolve = defaultFieldResolver } = field;

// resolve field.
field.resolve = async function(__, Context) {
// check if Context
// contain's user object
// which was resolved by jwt.
if(!Context.user){
throw new Error('User not authenticated');
}

// resolve return awaited resolve call.
return await resolve.apply(this, __);
};
}
}

但是使用它会导致意外的 token 错误。

class isAuth extends SchemaDirectiveVisitor {
// field defination for resolving
// directive.
visitFieldDefinition(field) { <---- Removed Public keyword
// overspreading.
const { resolve = defaultFieldResolver } = field;

// resolve field.
field.resolve = async function(__, Context) {
// check if Context
// contain's user object
// which was resolved by jwt.
if(!Context.user){
throw new Error('User not authenticated');
}

// resolve return awaited resolve call.
return await resolve.apply(this, __);
};
}
}

这可以工作,但不适用于 apollo 包。

请注意:Apollo 是 graphql 库

最佳答案

public 关键字存在于 JavaScript 中,但它是 reserved for future use

因此,从 2019 年开始,任何 JavaScript 解析器总会给您带来意外的 token 错误。

关于javascript - 在 javascript 中使用 Public 关键字时出现意外标记,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57836514/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com