操作
拦截任何 GraphQL 操作。
你可以通过定义一个 graphql.operation()
处理程序并通过操作名称匹配来拦截任何 GraphQL 操作,无论其类型如何。与查询和突变处理程序不同,操作处理程序不需要你指定操作类型或名称,只需指定响应解析器即可。
¥You can intercept any GraphQL operation regardless of its kind by defining a graphql.operation()
handler. Unlike query and mutation handlers, the operation handler does not require you to specify the operation kind or name, only the response resolver.
graphql.operation(() => {})
你仍然可以访问被拦截的 GraphQL 操作的所有 响应解析器参数,例如
operationName
、variables
等。¥You can still access all the Response resolver arguments of the intercepted GraphQL operation, like
operationName
,variables
, etc.
当你想将请求处理委托给外部源(例如模拟的 GraphQL 模式)时,这种类型的拦截非常方便。有关详情,请参阅 Schema 优先模拟。
¥This type of interception is handy when you want to delegate the request handling to an external source, like a mocked GraphQL schema. For that, see Schema-first mocking.