Is it possible for us to specify required fields i...
# support
b
Is there any support coming for specifying non-nullable (required) fields on GraphQL queries/mutations? Without being able to specify required fields we end up dealing with the extra complexity on our client side to handle all of these null values for every field. We are using code-generator for generating our types based on the medplum json schematic, but everything is nullable.
j
Hi @boogiecoco., thanks for bringing this issue to light. We added non-nullable fields for GraphQL queries/mutations. You can see the latest schema here https://graphiql.medplum.com/schema/schema-latest.json
b
How do we mark a field as non-nullable when making a query/mutation? The traditionally used bang operator is giving me back an error
j
Hi @boogiecoco., I don't believe the bang operator tends to be used when making a query/mutation. This tends to be used at the schema definition level
b
How do we indicate if we want a field to be required ?
If I want a document reference query to always return attachment data, how would I write the query to specify attachment data as a required (non-nullable) field?
j
In GraphQL, as far as I know you cannot make a field be required when making a query/mutation. The server will return an error if there is a requirement based on the schema. If you've seen examples with other GraphQL libraries where it's different, please send them over I'd love to look through it
Following up on this question, for the schema we have [DocumentReferenceContent]! where the array is non-nullable. Are you wanting the schema to be [DocumentReferenceContent!]! where the content is non-nullable as well?
b
So we don’t have control over which fields we want to be nullable vs non-nullable?
c
hi @boogiecoco. - that is a good question. At present, no, optional/required fields are defined by the FHIR spec. We are actively working on adding "FHIR Profiles" (https://github.com/medplum/medplum/discussions/2006), which will allow project admins to define profiles for projects. A FHIR profile is a way to specify more required fields, required value sets (i.e., required enum values), and a bunch more. When that work is complete, you will be able to specify that additional fields are non-nullable.
162 Views