简体   繁体   English

Apollo 解析器 - 等待另一个解析器的结果

[英]Apollo resolvers - await result from another resolver

I have a question.我有个问题。 I am using apollo -GraphQL and i have issue which i cant seem to solver correctly.我正在使用 apollo -GraphQL,但我遇到了似乎无法正确求解的问题。 So i have type lie this:所以我有类型谎言:

    Price {
  PriceBefore {
    value
    
  }
  PriceAfter {
    value
  }
  PriceSave {
    value
  }
}

And i index.ts i have:我 index.ts 我有:

 PriceBefore: async (data: SomeData, source: any, { dataSources }: any, context: any) => {
return someCalculation:
}

PriceAfter : async (data: SomeData, source: any, { dataSources }: any, context: any) => {
return someCalculation:
}

PriceSave : async (data: SomeData, source: any, { dataSources }: any, context: any) => {
return someCalculation:
}

My problem is that i don't know how to wait with PriceAfter to PriceBefore is finished and how could i transfer result from PriceBefore to PriceAfter.我的问题是我不知道如何等待 PriceAfter 到 PriceBefore 完成,以及如何将结果从 PriceBefore 转移到 PriceAfter。 Same thin with PriceSave who should wait for PriceBefore and Price After to end and get data from them.与 PriceSave 一样瘦,他们应该等待 PriceBefore 和 Price After 结束并从他们那里获取数据。

Is that possible does anybody knows?有人知道吗?

Thank in advance预先感谢

So in your case its not really doable.所以在你的情况下它不是真的可行。

You will have to split it into 2 calls and handle that from client.您必须将其拆分为 2 个调用并从客户端处理它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我们如何通过apollo-server模块在ApolloServer中传递数据源以及合并的graphql模式和解析器? - How can we pass datasource and merged graphql schema and resolvers in ApolloServer from apollo-server module? Graphql apollo 服务器解析器 arguments 类型 - Graphql apollo server resolvers arguments types 如何为 Apollo 解析器上下文设置类型? - How to set type for Apollo resolver context? Apollo GraphQL Schema使用Typescript时解析器的拼接问题 - Apollo GraphQL Schema Stitching issue with Resolvers when using Typescript 使用 TypeGraphQL 在浏览器中为 Apollo 本地状态生成 typedef 和解析器 - Using TypeGraphQL to generate typedefs and resolvers for Apollo local state in browser 如何在 Apollo Server 中将类型定义和解析器拆分为单独的文件 - How to split type definitions and resolvers into separate files in Apollo Server 使用 Typescript 将 Apollo/Hasura GraphQL 查询的结果展平 - Flattening Result from Apollo/Hasura GraphQL Query using Typescript 我如何在我的服务中等待我的方法的结果? - How can i await the result from my method in my service? 从 fetch 重构到 await 可以产生相同的结果 - Refactor from fetch to await that can yield same result 如何在解析器中使用 Apollo-Server Graphql 的枚举? - How to use enum of Apollo-Server Graphql in resolver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM