简体   繁体   English

我可以将 graphql 操场中的变量分配给突变的结果吗

[英]can I assign a variable in a graphql playground to the result of a mutation

If I have a mutation with 2 fields:如果我有 2 个字段的突变:

type Mutation {
  createSimulation(
    name: String
    simulators: [AvailableSimulators!]!
    timeToLiveInMS: Int
  ): Simulation!
  create(
    simulationID: ID!
    simulator: AvailableSimulators!
    type: String!
    attributes: KeyValuePair
  ): CreateResult!
}

When I run the mutation in the graphql applo server playground, I need a value from the return of createSimulation in a call to create :当我在 graphql applo 服务器游乐场中运行突变时,我需要一个来自createSimulation调用中返回的值来create

在此处输入图像描述

Can I somehow assign a variable that I can use in create ?我可以以某种方式分配一个可以在create中使用的变量吗?

Not part of the GraphQL standard.不属于 GraphQL 标准。 Should handle this in the resolver in the backend.应该在后端的解析器中处理这个问题。 It will depend on the technology used, but in most of the technologies you can use results from previous resolvers or call resolvers manually.这取决于所使用的技术,但在大多数技术中,您可以使用以前解析器的结果或手动调用解析器。

No, you should send 2 requests to handle it.不,您应该发送 2 个请求来处理它。 The client-side should request createSimulation first to get a response then request another request to create mutation with that UUID.客户端应首先请求createSimulation以获得响应,然后请求另一个请求以使用该 UUID create突变。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM