Skip to content

Instantly share code, notes, and snippets.

@Cal30
Created January 19, 2017 17:06
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 Cal30/aa50db7379a2f20c972877a2b5a7f318 to your computer and use it in GitHub Desktop.
Save Cal30/aa50db7379a2f20c972877a2b5a7f318 to your computer and use it in GitHub Desktop.
GraphQL Post - Connection DataFetcher
@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