如何在 graphql 中公开两个 api 端点,一个是私有的,另一个是公共的,其中公共不需要身份验证,只需从任何地方访问,或者如何使一些查询公开,其他查询公开,我当前的实现所有查询和突变都是私人意味着他们不想进行身份验证,我正在使用 Netflix dgs,如果有任何帮助朝着正确的方向发展,我将不胜感激。
SpringBoot 安全性是处理私有和公共查询使用的一种选项。与 REST 查询不同 |突变|订阅定义了授权流程。不是 URI。
import com.netflix.graphql.dgs.DgsComponent;
import com.netflix.graphql.dgs.DgsQuery;
import org.springframework.security.access.prepost.PreAuthorize;
@DgsComponent
public class UserDataFetcher {
@DgsQuery
public User publicUser() {
// This query is public
return new User("publicUser", "[email protected]");
}
@DgsQuery
@PreAuthorize("isAuthenticated()") // This query requires authentication
public User privateUser() {
return new User("privateUser", "[email protected]");
}
}