首页 > 解决方案 > 从 google drive api 获取所有驱动器并将其与 graphQl 一起使用

问题描述

我一辈子都想不出如何解决这个问题……我有一个 util.js 来设置谷歌驱动器常量。它需要一个回调。这是我使用的代码。

我让它与rest api一起工作,因为我只是在这个里面返回它......但是现在我需要在它作为GraphQL中的一个字段完成时返回它......我知道这段代码看起来很乱,但我很乐意帮助,并尝试了解如何修复它。第一行“驱动器”是graphql。

      drives: {
    type: GraphQLList(GraphQLString),
    resolve: async () =>
      drive(async (drive) => {
        let drives = [];
        function getDrives(nextPageToken) {
          drive.drives
            .list({
              pageSize: 99,
              useDomainAdminAccess: true,
              // eslint-disable-next-line quotes
              q: "name contains ''",
              pageToken: nextPageToken,
              supportsAllDrives: true,
              fields: 'nextPageToken,drives',
            })
            .then((result) => {
              drives.push(...result.data.drives);
              // console.log('PAGE TOKEN: ' + result.data.nextPageToken);
              if (result.data.nextPageToken) {
                console.log('INSIDE PROMISE');
                // return drives;
                getDrives(result.data.nextPageToken);
              }
            })
            .then((result) => {
              // console.log(result.length);
              if (result) {
                console.log(drives.length);
                return drives;
              }
            })
            .then(() => {
              console.log('Ferdig');
            })
            .catch();
        }
        
        return drives;
      }),
  },
}),

标签: javascriptnode.jsgraphql

解决方案


推荐阅读