4

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.

1 Answer 1

4

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
  }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot for your answer! My only doubt is: How do I know if it will take the first or second argument for the first lookup? As you can see according to the data the most reasonable way of querying it would be to use the appointmentCode first and then the lastName.
@Guillermo it will work the way you implement the apropriate resolver - if generated check docs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.