Skip to content

Instantly share code, notes, and snippets.

@jschmidtnj
Created October 15, 2020 19:38
Show Gist options
  • Select an option

  • Save jschmidtnj/f069dba80d525d328b4f1d7931bb663f to your computer and use it in GitHub Desktop.

Select an option

Save jschmidtnj/f069dba80d525d328b4f1d7931bb663f to your computer and use it in GitHub Desktop.
media download resolver with type graphql
import { ObjectId } from 'mongodb';
import { Resolver, FieldResolver, ResolverInterface, Root } from 'type-graphql';
import { DownloadLinks } from '../schema/structure/baseFile';
import Media from '../schema/structure/media';
import { fileBucket, getMediaKey, getS3DownloadSignedURL } from '../utils/aws';
@Resolver(_of => Media)
class DownloadLinksResolver implements ResolverInterface<Media> {
@FieldResolver(_returns => DownloadLinks)
async downloadLinks(@Root() media: Media): Promise<DownloadLinks> {
return {
original: await getS3DownloadSignedURL(getMediaKey(media._id as ObjectId), fileBucket),
blurred: await getS3DownloadSignedURL(getMediaKey(media._id as ObjectId), fileBucket)
};
}
}
export default DownloadLinksResolver;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment