Lambda函数查询GraphQL端点? [英] Lambda functions to query the GraphQL endpoint?
问题描述
如何使用Lambda函数在Node.js中查询GraphQL端点(AppSync)?我应该使用哪个GraphQL客户端?
How can I use Lambda functions to query the GraphQL endpoint (AppSync) in Node.js? Which GraphQL Client should I use?
我看过 AWS AppSync JavaScript SDK似乎是用于移动应用程序或React/Frontend.
I have seen AWS AppSync JavaScript SDK which seems to be for mobile app or react/frontend.
PS:我不是在谈论AWS Lambda解析器.
PS: I am not talking about AWS Lambda Resolvers.
推荐答案
如果您使用AWS_IAM或AMAZON_COGNITO_USER_POOLS作为身份验证类型,我认为AWS AppSync JavaScript SDK是一个很大的帮助,您只需按照以下说明设置代码即可此处:
If you use AWS_IAM or AMAZON_COGNITO_USER_POOLS as the authentication type, I think AWS AppSync JavaScript SDK is a big help, you just need to set up your code as explained here:
"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的权限).
or just retrieve Lambda session credentials (don't forget to give permission to Lambda execute GraphQL API).
这篇关于Lambda函数查询GraphQL端点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!