Skip to content

Instantly share code, notes, and snippets.

@seit
Created December 10, 2020 10:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seit/563e32e8d49718f18f6a71e2115f7086 to your computer and use it in GitHub Desktop.
Save seit/563e32e8d49718f18f6a71e2115f7086 to your computer and use it in GitHub Desktop.
GraphqlController_2
public String graphqlExec(){
String query = makeQuery("<商品ID>",
"<コレクションID>");
String resJsonStr = apiClient.post(query,String.class);
logger.debug(resJsonStr);
return "index";
}
private String makeQuery(String productId, String CollectionId){
SampleVariables variableJson = new SampleVariables(productId,
CollectionId);
try {
String query = getResource("SampleQuery");
ObjectMapper mapper = new ObjectMapper();
ObjectNode wrapper = mapper.createObjectNode();
wrapper.put("query", query);
wrapper.set("variables", mapper.valueToTree(variableJson));
return mapper.writeValueAsString(wrapper);
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
private String getResource(String name) throws IOException {
try (InputStream is = getClass().getResourceAsStream("/graphql/" + name + ".graphql")) {
return new String(IOUtils.toByteArray(is)).replace(System.lineSeparator(), "");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment