graphql-dataloader-boilerplate icon indicating copy to clipboard operation
graphql-dataloader-boilerplate copied to clipboard

Improve loaders return

Open felippepuhle opened this issue 7 years ago • 1 comments

https://github.com/facebook/dataloader/blob/master/src/index.js#L13

DataLoader originally returns a Promise of an Array of values or Errors, while we return the value or null.

felippepuhle avatar Jun 18 '17 19:06 felippepuhle

Code that can solve this:

const load = async (context: GraphQLContext, id: string): Promise<?User> => {
    if (!id) {
      return null;
    }

	let data;
	try {
        data = await context.dataloaders.UserLoader.load(id);
	} catch (err) {
		return null;
	}

    return viewerCanSee(context, data) ? new User(data, context) : null;
  }

sibelius avatar Jun 29 '17 15:06 sibelius