use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngineTests method testResource.
private void testResource(Resource resource, String output, String source) throws IOException, EGraphEngine, EGraphQLException {
GraphQLEngine gql = new GraphQLEngine(TestingUtilities.context());
gql.setServices(this);
if (resource != null) {
gql.setFocus(resource);
}
gql.setGraphQL(Parser.parseFile(TestingUtilities.resourceNameToFile("graphql", source)));
gql.getGraphQL().setOperationName(null);
gql.getGraphQL().getVariables().add(new Argument("var", new NameValue("true")));
boolean ok = false;
String msg = null;
try {
gql.execute();
ok = true;
} catch (Exception e) {
if (!output.equals("$error"))
e.printStackTrace();
ok = false;
msg = e.getMessage();
}
if (ok) {
Assertions.assertTrue(!output.equals("$error"), "Expected to fail, but didn't");
StringBuilder str = new StringBuilder();
gql.getOutput().setWriteWrapper(false);
gql.getOutput().write(str, 0);
TextFile.stringToFile(str.toString(), TestingUtilities.resourceNameToFile("graphql", output + ".out"));
msg = TestingUtilities.checkJsonIsSame(TestingUtilities.resourceNameToFile("graphql", output + ".out"), TestingUtilities.resourceNameToFile("graphql", output));
Assertions.assertTrue(Utilities.noString(msg), msg);
} else
Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngineTests method testReferenceReverseHistory.
@Test
public void testReferenceReverseHistory() throws IOException, EGraphEngine, EGraphQLException {
String context = "Patient/example/$graphql";
String source = "reference-reverse.gql";
String output = "reference-reverse-history.json";
String[] parts = context.split("/");
String filename = TestingUtilities.resourceNameToFile(parts[0].toLowerCase() + "-" + parts[1].toLowerCase() + ".xml");
Resource parsedResource = new XmlParser().parse(new FileInputStream(filename));
parsedResource.setId("example/_history/1");
testResource(parsedResource, output, source);
}
use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertTrue(doc != null);
}
use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.
the class GraphQLEngine method execute.
@Override
public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
if (graphQL == null)
throw new EGraphEngine("Unable to process graphql - graphql document missing");
fpe = new FHIRPathEngine(this.context);
magicExpression = new ExpressionNode(0);
output = new GraphQLResponse();
Operation op = null;
// todo: initial conditions
if (!Utilities.noString(graphQL.getOperationName())) {
op = graphQL.getDocument().operation(graphQL.getOperationName());
if (op == null)
throw new EGraphEngine("Unable to find operation \"" + graphQL.getOperationName() + "\"");
} else if ((graphQL.getDocument().getOperations().size() == 1))
op = graphQL.getDocument().getOperations().get(0);
else
throw new EGraphQLException("No operation name provided, so expected to find a single operation");
if (op.getOperationType() == OperationType.qglotMutation)
throw new EGraphQLException("Mutation operations are not supported (yet)");
checkNoDirectives(op.getDirectives());
processVariables(op);
if (focus == null)
processSearch(output, op.getSelectionSet(), false, "");
else
processObject(focus, focus, output, op.getSelectionSet(), false, "");
}
use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.
the class GraphQLParserTests method test.
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
public void test(String name, String test) throws IOException, EGraphQLException, EGraphEngine {
Package doc = Parser.parse(test);
Assertions.assertNotNull(doc);
}
Aggregations