Include the wrapper element when writing GraphQL responses
This commit is contained in:
parent
cb9a2552c5
commit
215fdae37f
|
@ -198,7 +198,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
/**
|
||||
* where the output from executing the query instanceof going to go
|
||||
*/
|
||||
private ObjectValue output;
|
||||
private GraphQLResponse output;
|
||||
|
||||
/**
|
||||
* Application provided reference resolution services
|
||||
|
@ -218,7 +218,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
fpe = new FHIRPathEngine(this.context);
|
||||
magicExpression = new ExpressionNode(0);
|
||||
|
||||
output = new ObjectValue();
|
||||
output = new GraphQLResponse();
|
||||
|
||||
Operation op = null;
|
||||
// todo: initial conditions
|
||||
|
@ -801,7 +801,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
this.graphQL = graphQL;
|
||||
}
|
||||
|
||||
public ObjectValue getOutput() {
|
||||
public GraphQLResponse getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -441,12 +441,12 @@ public class TestingUtilities {
|
|||
|
||||
|
||||
public static String resourceNameToFile(String name) throws IOException {
|
||||
return Utilities.path(System.getProperty("user.dir"), "src", "main", "resources", name);
|
||||
return Utilities.path(System.getProperty("user.dir"), "src", "test", "resources", name);
|
||||
}
|
||||
|
||||
|
||||
public static String resourceNameToFile(String subFolder, String name) throws IOException {
|
||||
return Utilities.path(System.getProperty("user.dir"), "src", "main", "resources", subFolder, name);
|
||||
return Utilities.path(System.getProperty("user.dir"), "src", "test", "resources", subFolder, name);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
/**
|
||||
* where the output from executing the query instanceof going to go
|
||||
*/
|
||||
private ObjectValue output;
|
||||
private GraphQLResponse output;
|
||||
/**
|
||||
* Application provided reference resolution services
|
||||
*/
|
||||
|
@ -81,7 +81,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
fpe = new FHIRPathEngine(this.context);
|
||||
magicExpression = new ExpressionNode(0);
|
||||
|
||||
output = new ObjectValue();
|
||||
output = new GraphQLResponse();
|
||||
|
||||
Operation op = null;
|
||||
// todo: initial conditions
|
||||
|
@ -662,7 +662,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
this.graphQL = graphQL;
|
||||
}
|
||||
|
||||
public ObjectValue getOutput() {
|
||||
public GraphQLResponse getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
if (ok) {
|
||||
assertTrue("Expected to fail, but didn't", !output.equals("$error"));
|
||||
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));
|
||||
|
|
|
@ -198,7 +198,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
/**
|
||||
* where the output from executing the query instanceof going to go
|
||||
*/
|
||||
private ObjectValue output;
|
||||
private GraphQLResponse output;
|
||||
|
||||
/**
|
||||
* Application provided reference resolution services
|
||||
|
@ -219,7 +219,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
fpe = new FHIRPathEngine(this.context);
|
||||
magicExpression = new ExpressionNode(0);
|
||||
|
||||
output = new ObjectValue();
|
||||
output = new GraphQLResponse();
|
||||
|
||||
Operation op = null;
|
||||
// todo: initial conditions
|
||||
|
@ -806,7 +806,7 @@ public class GraphQLEngine implements IGraphQLEngine {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ObjectValue getOutput() {
|
||||
public GraphQLResponse getOutput() {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
|
|
@ -103,6 +103,7 @@ public class GraphQLEngineTests implements IGraphQLStorageServices {
|
|||
if (ok) {
|
||||
assertTrue("Expected to fail, but didn't", !output.equals("$error"));
|
||||
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));
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
package org.hl7.fhir.utilities.graphql;
|
||||
|
||||
public class GraphQLResponse extends ObjectValue {
|
||||
private boolean writeWrapper = true;
|
||||
|
||||
/**
|
||||
* Should the "data" wrapper br written along with the output
|
||||
*/
|
||||
public void setWriteWrapper(boolean theWriteWrapper) {
|
||||
writeWrapper = theWriteWrapper;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(StringBuilder b, Integer indent, String lineSeparator) throws EGraphQLException, EGraphEngine {
|
||||
|
||||
if (writeWrapper) {
|
||||
// Write the wrapper
|
||||
b.append("{ \"data\": ");
|
||||
}
|
||||
|
||||
super.write(b, indent, lineSeparator);
|
||||
|
||||
if (writeWrapper) {
|
||||
// Terminate the wrapper
|
||||
b.append("}");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -86,6 +86,8 @@ public class ObjectValue extends Value {
|
|||
* @param lineSeparator The line separator
|
||||
*/
|
||||
public void write(StringBuilder b, Integer indent, String lineSeparator) throws EGraphQLException, EGraphEngine {
|
||||
|
||||
// Write the GraphQL output
|
||||
b.append("{");
|
||||
String s = "";
|
||||
String se = "";
|
||||
|
@ -103,6 +105,5 @@ public class ObjectValue extends Value {
|
|||
}
|
||||
b.append(se);
|
||||
b.append("}");
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue