0

我不知道如何在 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"
            }
        ]
    }
}
4

1 回答 1

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==`
};
于 2019-05-21T04:36:40.823 回答