Tag: graphql graphql js

返回函数外的值

我正在寻找使用graphQL来查询docker机api,并获得反应dockerpipe理员风格项目的容器列表。 我正在使用dockerode一个NPM模块来提出请求。 第一个函数getCOntainerById是我通常会从rethinkdb返回一些项目。 我似乎无法弄清楚如何返回docker.listContainers函数中的容器数组,因为它只在范围内定义,在fetchContainers函数返回结束时未定义。 import Docker from 'dockerode' var docker = new Docker({host: 'http://127.0.0.1', port: 52376}); export default { getContainerById: { type: Container, args: { id: {type: new GraphQLNonNull(GraphQLID)} }, async resolve(source, {id}, {rootValue}) { isLoggedIn(rootValue); const container = await r.table('containers').get(id); if (!container) { throw errorObj({_error: 'Container not found'}); } return container; } }, fetchContainers: […]