@iccas/fhir-graphql-tools v1.0.2
FHIR GraphQL Tools
A tool for generating GraphQL types from FHIR StructureDefinitions. The tool supports both FHIR R4 base resources and custom profiles.
Currently, the command line tool only generates type definitions. It does not generate a any queries or mutations as defined in https://www.hl7.org/fhir/graphql.html.
FHIR.js is used for parsing.
Usage
Specify the folder containing your custom structure definitions. FHIR R4 resources are always loaded by default.
fhir-graphql generate-types [strucuture/definition/folder] --output [output/folder/or/SchemaName.graphql]
Limitations
GraphQL does not support polymorphic input types.
To circumvent this and still be able to use resources such as FHIR Bundle
, polymorphic resources can be modeled using the InputResource
scalar.
The InputResource
scalar should resolve the received value to the underlying correct resource or profile, based on meta.profile
and its resourceType
.
Runtime Support
Disclaimer: Runtime support is experimental and not battle-tested.
This package provides some scalars that help implementing FHIR GraphQL schemas.
This works with all server-side frameworks that use graphql-tools
like e.g. Apollo.
import { makeExecutableSchema } from '@graphql-tools/schema'
import { primitiveScalars, createGraphQLInputResourceScalar } from 'fhir-graphql-tools'
// load the generated schema
const fhirTypes = fs.read('./FHIRResources.graphql')
const schema: GraphQLSchema = makeExecutableSchema({
typeDefs: [
fhirTypes,
// supply your own Query and Mutation definitions
`
type Query {
Patient: PatientResource
}
type Mutation {
...
}
`
],
resolvers: {
// Supply FHIR GraphQL primitive scalars
...primitiveScalars,
// Supply scalar for polymorphic resource
...createGraphQLInputResourceScalar(() => schema),
// Define your own resolvers
Query: {
Patient () {
return {
name: [
{ text: 'TestPatient' }
]
}
}
}
}
})
Todos
- Include FHIR documentation strings