我不知道如何在vue-apollo中传递此curl请求的--user字段
curl -v \
--user 'user@domain.com:password' \
-X POST \
-H "Content-Type: application/json" \
--data '{ "query": "{ companies{ uid name url }}" }' \
http://localhost:4000/graphql
我可以在vue-apollo中设置--user吗?
我在vue-apollo选项对象中尝试了以下
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic user@domain.com:password`
};
但这不起作用
我期望公司取得成果
{
"data": {
"companies": [
{
"id": "someId",
"name": "Facebook",
"url": "facebook.com"
},
{
"id": "someId",
"name": "Twitter",
"url": "twitter.com"
}
]
}
}
答案 0 :(得分:0)
defaultOptions中的getAuth方法应返回编码的基本身份验证
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
const defaultOptions = {
// You can use `https` for secure connection (recommended in production)
httpEndpoint,
wsEndpoint: null,
persisting: false,
websocketsOnly: false,
ssr: false,
getAuth: () => `Basic ZrT2mWt3gJKHRJ33tf20hJrq==`
};