从Apollo插件访问graphql解析器参数

时间:2020-06-13 16:40:47

标签: typescript graphql apollo apollo-server

我正尝试使用传入的参数作为键,将插件添加到ApolloServer graphql API中,以记录端点的输出。

但是,当进行查询时,它看起来就像

query($x: String!, $y: String!, $z: String!) {
  foo(user: { a: $x, b: $y, c: $z }) {
    bar
  }
}

插件看起来像

{
  requestDidStart() {
    return {
      willSendResponse({ response }: {response: GraphQLResponse }) {
        console.log(`user ${ARGS.A} has made a request`);
        console.log('response sent to user': response);
      },
    }
  }
}

我已经尝试从请求中访问变量,但是鉴于变量可以使用客户端想要的任何名称,这似乎是一个死胡同。有没有更好的方法可以在插件内部访问args

0 个答案:

没有答案