Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 991
Guillermo Avatar asked Sep 18 '25 16:09

Guillermo


1 Answers

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
  }
}
like image 53
coreyward Avatar answered Sep 21 '25 08:09

coreyward