Created
January 19, 2017 17:06
-
-
Save Cal30/aa50db7379a2f20c972877a2b5a7f318 to your computer and use it in GitHub Desktop.
GraphQL Post - Connection DataFetcher
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
@Override | |
public Object get(DataFetchingEnvironment environment) { | |
List<Object> list = new ArrayList<>(); | |
Map page = (Map) restService.restRequest(getURI(), true); | |
while (page != null){ | |
List results = (List) page.get("results"); | |
String next = (String) page.get("next"); | |
for (Object r : results){ | |
list.add(r); | |
} | |
page = null; | |
if (next != null) { | |
page = (Map) restService.restRequest(next, false); | |
} | |
} | |
if (list != null) { | |
// Return a Connection object | |
return new SimpleListConnection(list).get(environment); | |
} | |
return null; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment