Skip to content

Instantly share code, notes, and snippets.

@lassombra
Created August 17, 2017 15:14
Show Gist options
  • Save lassombra/0ae114acbec9238b06c95dd84239986c to your computer and use it in GitHub Desktop.
Save lassombra/0ae114acbec9238b06c95dd84239986c to your computer and use it in GitHub Desktop.
resolvers for file example
{
Query: {
file({id}) {
// connector is a dataload aware connector which has been instantiated
// with information about this domain specifically
return connector.get(id, context);
}
},
File: {
// definite candidate for memoization
filePath({filePath}) {
return '/' + filePath.split('FileManager\\')[1].replace('\\', '/');
},
// candidate for memoization
thumbnailPath({generatedSizes}) {
let size = generatedSizes.filter(size => size.imageSize.description == 'Thumbnail')[0];
// Config is an import that has environment specific information
return size && (`${Config.current.fileUrlRoot}${size.image.filePath.split(Config.current.fileRoot)[1]}`).replace(/\\/g, '/');
},
// definite candidate for memoization
downloadPath({filePath}) {
return (`${Config.current.fileUrlRoot}${filePath.split(Config.current.fileRoot)[1]}`).replace(/\\/g, '/');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment