简体   繁体   中英

GraphQL Query with two parameters

I'm new to GraphQL and I'm working with an appointments app. This is the data that I'm getting from the API

[
  {
    "appointmentID": "xza120",
    "patient": {
      "firstName": "John",
      "lastName": "Black"
    }
  }
]

Querying appointment by id was relatively easy.

query GetAppointmentById {
  appointment(appointmentCode: "xza120") {
    appointmentID
    firstName
    lastName
  }
}

My question is: What about if I want to look for the combination of appointmentID and lastName? (Eg: A patient might have multiple appointments, so I just want to retrieve the appointment code that matches with the last name.). Is it possible to do it with GraphQL? Should I prefer to do it in the code rather than in the query?

Thanks a lot in advance,

Guillermo.

Since GraphQL is a spec and each server determines the arguments it accepts and their behavior it's hard to generalize and still provide accurate information; this said, you can provide multiple arguments to a query and typically servers will support this. For example:

query GetAppointmentById {
  appointment(appointmentCode: "xza120", lastName: "Black") {
    appointmentID
    firstName
    lastName
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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