-
-
Save seit/563e32e8d49718f18f6a71e2115f7086 to your computer and use it in GitHub Desktop.
GraphqlController_2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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