var featureLoader = new DataLoader(ids => {
  var params = ids.map(id => '?' ).join();
  var query = `SELECT * FROM users WHERE id IN (${params})`;
  return queryLoader.load([query, ids]).then(
    rows => ids.map(
      id => rows.find(row => row.id === id) || new Error(`Row not found: ${id}`)
    )
  );
});
Example #2
0
export async function getObjectsByType(
  type: string,
  args?: ?Object
): Promise<ObjectsByType> {
  var objects = [];
  var totalCount = 0;
  var nextUrl = `http://anapioficeandfire.com/api/${type}/`;
  while (nextUrl && !doneFetching(objects, args)) {
    var pageData = await localUrlLoader.load(nextUrl);
    var parsedPageData = JSON.parse(pageData);
    totalCount = parsedPageData.count;
    objects = objects.concat(parsedPageData.results.map(objectWithId));
    nextUrl = parsedPageData.next;
  }
  return {objects, totalCount};
}
Example #3
0
export async function getObjectFromUrl(url: string): Promise<Object> {
  var dataString = await localUrlLoader.load(url);
  var data = JSON.parse(dataString);
  return objectWithId(data);
}
var userbyUsernameLoader = new DataLoader(username => {
  var query = `SELECT * FROM users WHERE username=${username}`;
  return queryLoader.load([query]).then(
    row => row[0] || new Error(`Row not found`)
  );
});
var userbyExternalLoginLoader = new DataLoader((loginProvider, login) => {
  var query = `SELECT * FROM login_providers LEFT JOIN users ON users.id=login_providers.user_id WHERE provider=${loginProvider} AND provider_login=${login}`;
  return queryLoader.load([query]).then(
    row => row[0] || new Error(`Row not found`)
  );
});
 return id => trackedEntityLoader.load(id)
Example #7
0
 load(query) {
   return this.dataLoader.load(query.toString())
 }