![](/img/trans.png)
[英]How do I query a GraphQl endpoint from node js without clunky string manipulation?
[英]Lambda functions to query the GraphQL endpoint?
如何使用Lambda函數查詢Node.js中的GraphQL端點(AppSync)? 我應該使用哪個GraphQL客戶端?
我見過AWS AppSync JavaScript SDK,它似乎適用於移動應用或反應/前端。
PS:我不是在談論AWS Lambda Resolvers。
我們使用一個簡單的https包來查詢graphql。 在這種情況下,您可能需要手動形成所有graphql查詢。 如果您想使用自動發現和查詢對象,您可以使用apollo-fetch客戶端。 簡單的CURL也適用。
這里詳細提到了所有方法。
https://blog.apollographql.com/4-simple-ways-to-call-a-graphql-api-a6807bcdb355
希望能幫助到你。
如果您使用AWS_IAM或AMAZON_COGNITO_USER_POOLS作為身份驗證類型,我認為AWS AppSync JavaScript SDK是一個很大的幫助,您只需按照此處的說明設置代碼:
"use strict";
/**
* This shows how to use standard Apollo client on Node.js
*/
global.WebSocket = require('ws');
require('es6-promise').polyfill();
require('isomorphic-fetch');
// Require exports file with endpoint and auth info
const aws_exports = require('./aws-exports').default;
// Require AppSync module
const AUTH_TYPE = require('aws-appsync/lib/link/auth-link').AUTH_TYPE;
const AWSAppSyncClient = require('aws-appsync').default;
...
此外,您必須提供憑據
const AWS = require('aws-sdk');
AWS.config.update({
region: aws_exports.REGION,
credentials: new AWS.Credentials({
accessKeyId: aws_exports.AWS_ACCESS_KEY_ID,
secretAccessKey: aws_exports.AWS_SECRET_ACCESS_KEY
})
});
const credentials = AWS.config.credentials;
或者只是檢索Lambda會話憑證(不要忘記授予Lambda執行GraphQL API的權限)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.