1

我在 graphql 中有使用 apollo 库构建的父模式,apollo-server并将graphql-tools子查询委托给远程 graphql 模式。

例如,下面的查询将 User.booking 的子查询委托给远程模式,并且运行良好。

const resolvers = {
User: {
        bookings: (parent, args, context, info) => {
        return info.mergeInfo.delegateToSchema({
               schema: subschema,
               operation: 'query',
               fieldName: 'bookingsByUser',
               args: {
                 userId: parent.id,
               },
               context,
               info,
              });
          },
       },
    };

我的问题是如何将 User.books 的子查询从另一个解析器(在我的情况下是他的父母解析器之一 - 库)发送到远程模式。

从 apollo 的文档中,该函数使用 info 对象来提取想要的子查询:

信息:GraphQLResolveInfo

GraphQL 解析当前解析器的信息。提供对从当前解析器开始的子查询的访问。

4

0 回答 0