Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
package com.nulpointerexception.cabdetailsgraphQLdemo;
import graphql.schema.DataFetcher;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
public class GraphQLDataFetchers {
private static List<Map<String, String>> cars = Arrays.asList(
ImmutableMap.of("id", "car1",
"carNumber", "KA01H",
"driverId", "12"),
ImmutableMap.of("id", "car2",
"carNumber", "BR01H",
"driverId", "13")
private static List<Map<String, String>> drivers = Arrays.asList(
ImmutableMap.of("id", "12",
"firstName", "Harsh",
"lastName", "Vardhan"),
ImmutableMap.of("id", "13",
"firstName", "Rohit",
"lastName", "Singh")
public DataFetcher getCabByIdDateFetcher(){
return dataFetchingEnvironment -> {
String carId = dataFetchingEnvironment.getArgument("id");
Map<String, String> carInStore =
.filter(car -> car.get("id").equals(carId))
return carInStore;
public DataFetcher getDriverDataFetcher(){
return dataFetchingEnvironment -> {
Map<String, String> carInStore = dataFetchingEnvironment.getSource();
String driverId = carInStore.get("driverId");
.filter(driver -> driver.get("id").equals(driverId))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment