This file contains hidden or 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 final class ExtractorFactory<B> { | |
| /* ... */ | |
| public <T> ExtractorFactory<B> add(BiConsumer<B, T> setter, | |
| ThrowingBiFunction<ResultSet, Integer, T> getter, | |
| Integer index) { /* ... */ } | |
| public <T> ExtractorFactory<B> add(BiConsumer<B, T> setter, | |
| ThrowingBiFunction<ResultSet, String, T> getter, | |
| String column) { /* ... */ } | |
| } |
This file contains hidden or 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
| final Extractor<Bean> extractor = factory | |
| .add(Bean::setSomeLong, ResultSet::getLong, 1) | |
| .add(Been::setFName, ResultSet::getString, "fname") | |
| .factory(Bean::new) | |
| .getExtractor(); |
This file contains hidden or 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
| private Map<String, Object> graphql(Request request, Response response) { | |
| Map<String, Object> payload; | |
| payload = getMapper().readValue(request.body(), Map.class); | |
| Map<String,Object> variables = (Map<String, Object>) payload.get("variables"); | |
| ExecutionResult executionResult = graphql.execute(payload.get("query").toString(), null, null, variables); | |
| Map<String, Object> result = new LinkedHashMap<>(); | |
| if (executionResult.getErrors().size() > 0) { | |
| result.put("errors", executionResult.getErrors()); | |
| } | |
| result.put("data", executionResult.getData()); |
This file contains hidden or 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
| private Map<String, Object> graphql(Request request, | |
| Response response) { | |
| Map<String, Object> payload; | |
| payload = getMapper().readValue(request.body(), Map.class); | |
| Map<String,Object> variables = | |
| (Map<String, Object>) payload.get("variables"); | |
| ExecutionResult executionResult = | |
| graphql.execute(payload.get("query").toString(), null, null, variables); | |
| Map<String, Object> result = new LinkedHashMap<>(); | |
| if (executionResult.getErrors().size() > 0) { |
This file contains hidden or 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
| { | |
| "query": "{ categories{ key name }}", | |
| "variables": {} | |
| } |
This file contains hidden or 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 class Category { | |
| private String name; | |
| private String key; | |
| /* Constructors, Gettters, Setters */ | |
| } |
This file contains hidden or 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
| GraphQLObjectType category = newObject() | |
| .name("category") | |
| .field(newFieldDefinition() | |
| .name("key") | |
| .type(GraphQLString) | |
| .build()) | |
| .field(newFieldDefinition() | |
| .name("name") | |
| .type(GraphQLString) | |
| .build()) |
This file contains hidden or 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
| return newObject() | |
| .name("query") | |
| .field(newFieldDefinition() | |
| .name("category") | |
| .type(category) | |
| .argument(newArgument() | |
| .name("key") | |
| .type(new GraphQLNonNull(GraphQLString)) | |
| .build()) | |
| .dataFetcher(environment -> categoryDao.findOne(environment.getArgument("key")).orElse(null)) |
This file contains hidden or 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
| return newObject() | |
| .name("mutation") | |
| .field(newFieldDefinition() | |
| .name("category") | |
| .type(new GraphQLTypeReference("category")) | |
| .argument(newArgument() | |
| .name("key") | |
| .type(new GraphQLNonNull(GraphQLString)) | |
| .build()) | |
| .argument(newArgument() |
This file contains hidden or 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
| var Graphql = function (url, query) { | |
| "use strict"; | |
| var _this = this; | |
| this.url = url; | |
| this.query = query; | |
| this.variables = {}; | |
| this.toString = function () { | |
| return JSON.stringify(_this); | |
| }; |