我在Nuxt项目上使用Apollo Client查询GraphQL端点,并且效果很好。但是现在,我需要查询AWS上的Elasticsearch端点。如何使用现有的Apollo客户端查询此端点?
const resolvers = {
Query: {
user(parent, args, context, info) {
let bar = args.id;
return queryElasticSearch(bar)
}
}
}
(供参考:https://www.apollographql.com/docs/apollo-server/data/resolvers/]
ElasticSearch具有此客户端,您可以连接该客户端来查询端点:https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/client-usage.html
并且在queryElasticSearch中,您可以有类似以下内容:
async function queryElasticSearch(bar){ const result = await client.search({ index: 'my-index', body: { foo: bar } }) return result; }