Search in sources :

Example 6 with EGraphEngine

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);
}
Also used : Package(org.hl7.fhir.utilities.graphql.Package) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 7 with EGraphEngine

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, String operation) throws IOException, EGraphEngine, EGraphQLException {
    GraphQLEngine gql = new GraphQLEngine(TestingUtilities.getSharedWorkerContext());
    gql.setServices(this);
    if (resource != null)
        gql.setFocus(resource);
    gql.setGraphQL(Parser.parse(TestingUtilities.loadTestResource("r5", "graphql", source)));
    gql.getGraphQL().setOperationName(operation);
    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);
        IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", source), new FileOutputStream(CompareUtilities.tempFile("graphql", source)));
        IOUtils.copy(CompareUtilities.loadTestResourceStream("r5", "graphql", output), new FileOutputStream(CompareUtilities.tempFile("graphql", output)));
        TextFile.stringToFile(str.toString(), CompareUtilities.tempFile("graphql", output + ".out"));
        msg = CompareUtilities.checkJsonIsSame(CompareUtilities.tempFile("graphql", output), CompareUtilities.tempFile("graphql", output + ".out"));
        Assertions.assertTrue(Utilities.noString(msg), msg);
    } else
        Assertions.assertTrue(output.equals("$error"), "Error, but proper output was expected (" + msg + ")");
}
Also used : GraphQLEngine(org.hl7.fhir.r5.utils.GraphQLEngine) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException) FHIRException(org.hl7.fhir.exceptions.FHIRException)

Example 8 with EGraphEngine

use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method execute.

public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
    assert services != null;
    assert start != null;
    assert bundle != null;
    assert baseURL != null;
    assert graphDefinition != null;
    graphDefinition.checkNoModifiers("definition", "Building graph from GraphDefinition");
    check(!start.fhirType().equals(graphDefinition.getStart()), "The Graph definition requires that the start (focus reosource) is " + graphDefinition.getStart() + ", but instead found " + start.fhirType());
    if (!isInBundle(start)) {
        addToBundle(start);
    }
    for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
        processLink(start.fhirType(), start, l, 1);
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r4b.model.GraphDefinition.GraphDefinitionLinkComponent)

Example 9 with EGraphEngine

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, "");
}
Also used : EGraphEngine(org.hl7.fhir.utilities.graphql.EGraphEngine) GraphQLResponse(org.hl7.fhir.utilities.graphql.GraphQLResponse) Operation(org.hl7.fhir.utilities.graphql.Operation) EGraphQLException(org.hl7.fhir.utilities.graphql.EGraphQLException)

Example 10 with EGraphEngine

use of org.hl7.fhir.utilities.graphql.EGraphEngine in project org.hl7.fhir.core by hapifhir.

the class GraphDefinitionEngine method execute.

public void execute() throws EGraphEngine, EGraphQLException, FHIRException {
    assert services != null;
    assert start != null;
    assert bundle != null;
    assert baseURL != null;
    assert graphDefinition != null;
    graphDefinition.checkNoModifiers("definition", "Building graph from GraphDefinition");
    check(!start.fhirType().equals(graphDefinition.getStart()), "The Graph definition requires that the start (focus reosource) is " + graphDefinition.getStart() + ", but instead found " + start.fhirType());
    if (!isInBundle(start)) {
        addToBundle(start);
    }
    for (GraphDefinitionLinkComponent l : graphDefinition.getLink()) {
        processLink(start.fhirType(), start, l, 1);
    }
}
Also used : GraphDefinitionLinkComponent(org.hl7.fhir.r5.model.GraphDefinition.GraphDefinitionLinkComponent)

Aggregations

ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)4 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 FHIRException (org.hl7.fhir.exceptions.FHIRException)3 Package (org.hl7.fhir.utilities.graphql.Package)3 MethodSource (org.junit.jupiter.params.provider.MethodSource)3 SAXException (org.xml.sax.SAXException)3 FileOutputStream (java.io.FileOutputStream)2 EGraphEngine (org.hl7.fhir.utilities.graphql.EGraphEngine)2 EGraphQLException (org.hl7.fhir.utilities.graphql.EGraphQLException)2 GraphQLResponse (org.hl7.fhir.utilities.graphql.GraphQLResponse)2 Operation (org.hl7.fhir.utilities.graphql.Operation)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IBaseResource (org.hl7.fhir.instance.model.api.IBaseResource)1 XmlParser (org.hl7.fhir.r4.formats.XmlParser)1 DomainResource (org.hl7.fhir.r4.model.DomainResource)1 Resource (org.hl7.fhir.r4.model.Resource)1 GraphQLEngine (org.hl7.fhir.r4.utils.GraphQLEngine)1 ExpressionNode (org.hl7.fhir.r4b.model.ExpressionNode)1