From efd8e07b9de123486ab0cde3dd298e34564faf26 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Wed, 5 Oct 2022 21:17:52 +1100 Subject: [PATCH] fix bugs in graphql generation --- .../fhir/r5/utils/GraphQLSchemaGenerator.java | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java index a637231dd..ee0a1f6e2 100644 --- a/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java +++ b/org.hl7.fhir.r5/src/main/java/org/hl7/fhir/r5/utils/GraphQLSchemaGenerator.java @@ -103,6 +103,9 @@ public class GraphQLSchemaGenerator { if (sd.getKind() == StructureDefinitionKind.COMPLEXTYPE && sd.getDerivation() == TypeDerivationRule.SPECIALIZATION) { tl.put(sd.getName(), sd); } + if (sd.getKind() == StructureDefinitionKind.RESOURCE && sd.getDerivation() != TypeDerivationRule.CONSTRAINT && sd.getAbstract()) { + tl.put(sd.getName(), sd); + } } writer.write("# FHIR GraphQL Schema. Version " + version + "\r\n\r\n"); writer.write("# FHIR Defined Primitive types\r\n"); @@ -290,16 +293,17 @@ public class GraphQLSchemaGenerator { } private void generateType(Map existingTypeNames, Writer writer, StructureDefinition sd, EnumSet operations) throws IOException { - if (sd.getAbstract()) { - return; - } - if (operations.contains(FHIROperationType.READ) || operations.contains(FHIROperationType.SEARCH)) { List list = new ArrayList<>(); StringBuilder b = new StringBuilder(); list.add(b); b.append("type "); b.append(sd.getName()); + StructureDefinition sdp = context.fetchResource(StructureDefinition.class, sd.getBaseDefinition()); + if (sdp != null) { + b.append(" implements "); + b.append(sdp.getType()); + } b.append(" {\r\n"); ElementDefinition ed = sd.getSnapshot().getElementFirstRep(); generateProperties(existingTypeNames, list, b, sd.getName(), sd, ed, "type", ""); @@ -370,7 +374,13 @@ public class GraphQLSchemaGenerator { if (suffix) b.append(Utilities.capitalize(typeDetails.getWorkingCode())); b.append(": "); - b.append(n); + if (!child.getMax().equals("1")) { + b.append("["); + b.append(n); + b.append("]"); + } else { + b.append(n); + } if (!child.getPath().endsWith(".id")) { b.append(" _"); b.append(tail(child.getPath(), suffix));