GraphQL Variables

I have a question about how to use variables in a fhir graphql request. I’ve gotten the below request to work if I hardcode the patient id, but I’m not sure how to get it working with a variable.

This is what I have so far.

This is the query.
query($patient: ID){
CoverageList(patient: $patient) {
subscriberId
period {
start
end
}
extension @flatten{
valueReference @flatten{
resource {
…on InsurancePlan {
name
}
}
}
}
}
}

This is the variable I’m trying to get working.
{
“patient”: “10b8ed43-fa0a-4a3c-87bc-f1bd032309af”
}

I haven’t found anything in the graphql schema or the HL7 FHIR documentation that answers how to do this.

I guess you’re using either test.fhir.org or happy.fhir.org. Both run my graphql engine, and it doesn’t know anything about variables (is that a new feature?)

1 Like

We made a custom fhir server using Smilecdr that’s based on the hapi fhir server. I was wanting a frontend web app to directly access this server with graphql. I read through these docs Graphql - FHIR v4.0.1 and it doesn’t mention anything about graphql variables being able to be used, but I can get the other example queries that are in these docs to work. This could be functionality that isn’t added yet.

Yes I haven’t added it yet. I’ll put it on the todo list, but it won’t be quick (pretty long todo list). Or you can make a PR against org.hl7.fhir.r4.utils.GraphQLEngine

1 Like

Thanks for the info and adding it to the todo list I can imagine that’s lengthy. I’ll look into the graphql engine and see what I can do.