import { GitHub , SurveyConfig , Entity , RequestContext } from '../types' ; import projects from '../data/bestofjs.yml' ; import { fetchMdnResource , fetchTwitterUser } from '../external_apis' ; import { useCache } from '../caching' ; const getSimulatedGithub = ( id ) : GitHub | null => { const project = projects . find ( ( p ) => p . id === id ) ; if ( project !== undefined ) { const { name , description , github , stars , homepage } = project ; return { id , name , description , url : `https://github.com/${ github }` , stars , homepage } ; } else { return null ; } } ; export default { Entity : { github : async ( { id } ) => { return getSimulatedGithub ( id ) ; } , mdn : async ( entity ) => { if ( ! entity || ! entity . mdn ) { return ; } const mdn = await fetchMdnResource ( entity . mdn ) ; if ( mdn ) { return mdn . find ( ( t ) => t . locale === 'en-US' ) ; } else { return ; } } , twitter : async ( entity , args , { db } ) => { const twitter = entity . twitterName && useCache ( fetchTwitterUser , db , [ entity . twitterName ] ) ; return twitter ; } } } ;