我尝试在我看到的文档中对 graphql 进行 axios 调用:
curl -X POST https://<PROJECT_REF>.supabase.co/graphql/v1 \
-H 'apiKey: <API_KEY>'\
-H 'Content-Type: application/json' \
--data-raw '
{
"query":"{ accountCollection(first: 3) { edges { node { id } } } }"
}'
我正在将其转换为这样的 axios 调用:
var callObject = {
url:https://<PROJECT_REF>.supabase.co/graphql/v1,
method:"POST",
headers:{
"Authorization" : "Bearer " + apiKey,
"apikey": apiKey,
"Content-Type": "application/json"
}
}
var response = await axios(callObject)
现在我尝试了很多方法来将 --data-raw 有效负载添加到调用中。但我找不到解决方案。它总是显示 404
如何处理?
对我一直有帮助的是将 cURL 请求导入 Postman。从那里转换为 Fetch 或 Axios 相当简单。
将cURL导入Postman:
https://learning.postman.com/docs/getting-started/importing-and-exporting/importing-curl-commands/
导出到 Axios(或其他)片段:
https://learning.postman.com/docs/sending-requests/create-requests/generate-code-snippets/
我认为 Insomnia 也有类似的功能。