diff --git a/data/schema/schema.js b/data/schema/schema.js index e23b4c6..7b5defe 100644 --- a/data/schema/schema.js +++ b/data/schema/schema.js @@ -10,6 +10,7 @@ const stackExchangeQueryType = require('./stackExchangeSchema'); const mediaWikiQueryType = require('./mediaWikiSchema'); const flickrQueryType = require('./flickrSchema'); const spotifyQueryType = require('./spotifySchema'); +const youtubeQueryType = require('./youtubeSchema'); function wrapper(){ return {} @@ -35,6 +36,11 @@ const Query = new GraphQLObjectType({ type: spotifyQueryType, resolve:() => wrapper() }, + youtube:{ + type: youtubeQueryType, + resolve:() => wrapper() + }, + // reddit stackExchange: { type: stackExchangeQueryType, resolve:() => wrapper() diff --git a/data/schema/youtube-type/youtubeChannelType.js b/data/schema/youtube-type/youtubeChannelType.js new file mode 100644 index 0000000..a753465 --- /dev/null +++ b/data/schema/youtube-type/youtubeChannelType.js @@ -0,0 +1,216 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean +} = require('graphql'); + +const youtubeChannelType = module.exports = new GraphQLObjectType({ + name:'youtubeChannel', + description:'', + fields:() => ({ + kind: {type:GraphQLString}, + etag: {type:GraphQLString}, + id: {type:GraphQLString}, + snippet: {type:channelSnippetType}, + contentDetails: {type:channelContentType, + resolve: ({contentDetails})=>{return contentDetails.relatedPlaylists}}, + statistics: {type:channelStatisticsType}, + topicDetails: {type:channelTopicType}, + status: {type:channelStatusType}, + brandingSettings: {type:channelBrandingType}, + invideoPromotion: {type:new GraphQLList(channelPromotionType), + resolve: ({invideoPromotion}) => {return invideoPromotion.items}}, + auditDetails: {type:channelAuditType}, + contentOwnerDetails:{type:channelOwnerType}, + }) +}); + +const channelSnippetType = new GraphQLObjectType({ + name:'channelSnippet', + fields:() =>({ + title: {type:GraphQLString}, + description: {type:GraphQLString}, + customUrl: {type:GraphQLString}, + publishedAt: {type:GraphQLString}, + default_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.default}}, + medium_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.medium}}, + high_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.high}}, + defaultLanguage: {type:GraphQLString}, + localized_title: {type:GraphQLString, + resolve:({localized})=>{return localized.title}}, + localized_description: {type:GraphQLString, + resolve:({localized})=>{return localized.description}}, + country: {type:GraphQLString}, + }) +}); + +const channelContentType = new GraphQLObjectType({ + name:'channelContent', + fields:() =>({ + likes: {type:GraphQLString}, + favorites: {type:GraphQLString}, + uploads: {type:GraphQLString}, + watchHistory: {type:GraphQLString}, + watchLater: {type:GraphQLString}, + }) +}); + +const channelStatisticsType = new GraphQLObjectType({ + name:'channelStatistics', + fields:() =>({ + viewCount: {type:GraphQLInt}, + commentCount: {type:GraphQLInt}, + subscriberCount: {type:GraphQLInt}, + hiddenSubscriberCount: {type:GraphQLBoolean}, + videoCount: {type:GraphQLInt}, + }) +}); + +const channelTopicType = new GraphQLObjectType({ + name:'channelTopic', + fields:() =>({ + topicIds: {type:new GraphQLList(GraphQLString)}, + topicCategories: {type:new GraphQLList(GraphQLString)}, + }) +}); + +const channelStatusType = new GraphQLObjectType({ + name:'channelStatus', + fields: () =>({ + privacyStatus: {type:GraphQLString}, + isLinked: {type:GraphQLBoolean}, + longUploadsStatus: {type:GraphQLString}, + }) +}); + +const channelBrandingType = new GraphQLObjectType({ + name:'channelBranding', + fields: () =>({ + channel_title: {type:GraphQLString, + resolve:({channel}) => {return channel.title}}, + channel_description: {type:GraphQLString, + resolve:({channel}) => {return channel.description}}, + channel_keywords: {type:GraphQLString, + resolve:({channel}) => {return channel.keywords}}, + channel_defaultTab: {type:GraphQLString, + resolve:({channel}) => {return channel.defaultTab}}, + channel_trackingAnalyticsAccountId: {type:GraphQLString, + resolve:({channel}) => {return channel.trackingAnalyticsAccountId}}, + channel_moderateComments: {type:GraphQLBoolean, + resolve:({channel}) => {return channel.moderateComments}}, + channel_showRelatedChannels: {type:GraphQLBoolean, + resolve:({channel}) => {return channel.showRelatedChannels}}, + channel_showBrowseView: {type:GraphQLBoolean, + resolve:({channel}) => {return channel.showBrowseView}}, + channel_featuredChannelsTitle: {type:GraphQLString, + resolve:({channel}) => {return channel.featuredChannelsTitle}}, + channel_featuredChannelsUrls: {type:new GraphQLList(GraphQLString), + resolve:({channel}) => {return channel.featuredChannelsUrls}}, + channel_unsubscribedTrailer: {type:GraphQLString, + resolve:({channel}) => {return channel.unsubscribedTrailer}}, + channel_profileColor: {type:GraphQLString, + resolve:({channel}) => {return channel.profileColor}}, + channel_defaultLanguage: {type:GraphQLString, + resolve:({channel}) => {return channel.defaultLanguage}}, + channel_country: {type:GraphQLString, + resolve:({channel}) => {return channel.country}}, + watch_textColor: {type:GraphQLString, + resolve:({watch}) => {return watch.textColor}}, + watch_backgroundColor: {type:GraphQLString, + resolve:({watch}) => {return watch.backgroundColor}}, + watch_featuredPlaylistId: {type:GraphQLString, + resolve:({watch}) => {return watch.featuredPlaylistId}}, + image_bannerImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerImageUrl}}, + image_bannerMobileImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerMobileImageUrl}}, + image_watchIconImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.watchIconImageUrl}}, + image_trackingImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.trackingImageUrl}}, + image_bannerTabletLowImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTabletLowImageUrl}}, + image_bannerTabletImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTabletImageUrl}}, + image_bannerTabletHdImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTabletHdImageUrl}}, + image_bannerTabletExtraHdImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTabletExtraHdImageUrl}}, + image_bannerMobileLowImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerMobileLowImageUrl}}, + image_bannerMobileMediumHdImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerMobileMediumHdImageUrl}}, + image_bannerMobileHdImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerMobileHdImageUrl}}, + image_bannerMobileExtraHdImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerMobileExtraHdImageUrl}}, + image_bannerTvImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTvImageUrl}}, + image_bannerTvLowImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTvLowImageUrl}}, + image_bannerTvMediumImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTvMediumImageUrl}}, + image_bannerTvHighImageUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerTvHighImageUrl}}, + image_bannerExternalUrl: {type:GraphQLString, + resolve:({image}) => {return image.bannerExternalUrl}}, + hints: {type:new GraphQLList(hintType)}, + }) +}); + +const hintType = new GraphQLObjectType({ + name:'hint', + fields: ()=>({ + property: {type:GraphQLString}, + value: {type:GraphQLString}, + }) +}); + +const channelPromotionType = new GraphQLObjectType({ + name:'channelPromotion', + fields: () => ({ + id_type: {type:GraphQLString, + resolve:({id}) => {return id.type}}, + id_videoId: {type:GraphQLString, + resolve:({id}) => {return id.videoId}}, + id_websiteUrl: {type:GraphQLString, + resolve:({id}) => {return id.websiteUrl}}, + id_recentlyUploadedBy: {type:GraphQLString, + resolve:({id}) => {return id.recentlyUploadedBy}}, + timing_type: {type:GraphQLString, + resolve:({timing}) => {return timing.type}}, + timing_offsetMs: {type:GraphQLInt, + resolve:({timing}) => {return timing.offsetMs}}, + timing_durationMs: {type:GraphQLInt, + resolve:({timing}) => {return timing.durationMs}}, + customMessage: {type:GraphQLString}, + promotedByContentOwner: {type:GraphQLBoolean}, + }) +}); + +const channelAuditType = new GraphQLObjectType({ + name:'channelAudit', + fields: () => ({ + overallGoodStanding: {type:GraphQLBoolean}, + communityGuidelinesGoodStanding: {type:GraphQLBoolean}, + copyrightStrikesGoodStanding: {type:GraphQLBoolean}, + contentIdClaimsGoodStanding: {type:GraphQLBoolean}, + }) +}); + +const channelOwnerType = new GraphQLObjectType({ + name:'channelOwner', + fields:() => ({ + contentOwner: {type:GraphQLString}, + timeLinked: {type:GraphQLString}, + }) +}); + +const youtubeThumbnailType = require('./youtubeThumbnailType'); \ No newline at end of file diff --git a/data/schema/youtube-type/youtubeListType.js b/data/schema/youtube-type/youtubeListType.js new file mode 100644 index 0000000..58bb3d1 --- /dev/null +++ b/data/schema/youtube-type/youtubeListType.js @@ -0,0 +1,59 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean +} = require('graphql'); +var youtubeAPI = require('../../../API/youtubeAPI'); + +const youtubeListType = module.exports = new GraphQLObjectType({ + name:'youtubeList', + description:'', + fields:() => ({ + kind: {type:GraphQLString}, + etag: {type:GraphQLString}, + info: {type:youtubeInfoType, + resolve: ({id})=>{return id}}, + snippet: {type:youtubeSnippetType}, + }) +}); + +const youtubeInfoType = new GraphQLObjectType({ + name:'youtubeId', + fields:() =>({ + kind: {type:GraphQLString}, + videoId: {type:GraphQLString}, + //channelId: {type:GraphQLString}, + //playlistId: {type:GraphQLString}, + /*---------------nested--------------*/ + channelInfo: {type:new GraphQLList(youtubeChannelType), + resolve:({channelId}) => youtubeAPI(resolveName='channel',id=channelId, args={})}, + playlistInfo: {type:new GraphQLList(youtubePlaylistType), + resolve: ({playlistId}) => youtubeAPI(resolveName='playlist',id=playlistId, args={})}, + }) +}); + +const youtubeSnippetType = new GraphQLObjectType({ + name:'youtubeSnippet', + fields: ()=> ({ + publishedAt: {type:GraphQLString}, + channelId: {type:GraphQLString}, + title: {type:GraphQLString}, + description: {type:GraphQLString}, + default_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.default}}, + medium_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.medium}}, + high_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.high}}, + channelTitle: {type:GraphQLString}, + liveBroadcastContent: {type:GraphQLString}, + }) +}); + +const youtubeThumbnailType = require('./youtubeThumbnailType'); +const youtubePlaylistType = require('./youtubePlaylistType'); +const youtubeChannelType = require('./youtubeChannelType'); \ No newline at end of file diff --git a/data/schema/youtube-type/youtubePlaylistType.js b/data/schema/youtube-type/youtubePlaylistType.js new file mode 100644 index 0000000..fba9597 --- /dev/null +++ b/data/schema/youtube-type/youtubePlaylistType.js @@ -0,0 +1,53 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean +} = require('graphql'); + +const youtubePlaylistType = module.exports = new GraphQLObjectType({ + name:'youtubePlaylist', + description:'', + fields:() => ({ + kind: {type:GraphQLString}, + etag: {type:GraphQLString}, + id: {type:GraphQLString}, + snippet: {type:playlistSnippetType}, + status: {type:GraphQLString, + resolve:({status}) => {return (status.privacyStatus)}}, + contentDetails: {type:GraphQLString, + resolve:({contentDetails}) => {return (contentDetails.itemCount)}}, + player: {type:GraphQLString, + resolve:({player}) => {return (player.embedHtml)}}, + //localizations: {type:GraphQLString, + // resolve:({localizations})=>{console.log(localizations)}}, + }) +}); + +const playlistSnippetType = new GraphQLObjectType({ + name:'playlistSnippet', + fields:() => ({ + publishedAt: {type:GraphQLString}, + channelId: {type:GraphQLString}, + title: {type:GraphQLString}, + description: {type:GraphQLString}, + default_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.default}}, + medium_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.medium}}, + high_thumbnails: {type:youtubeThumbnailType, + resolve:({thumbnails})=>{return thumbnails.high}}, + channelTitle: {type:GraphQLString}, + tags: {type:new GraphQLList(GraphQLString)}, + defaultLanguage: {type:GraphQLString}, + localized_title: {type:GraphQLString, + resolve:({localized})=>{return localized.title}}, + localized_description: {type:GraphQLString, + resolve:({localized})=>{return localized.description}}, + }) +}); + +const youtubeThumbnailType = require('./youtubeThumbnailType'); \ No newline at end of file diff --git a/data/schema/youtube-type/youtubeThumbnailType.js b/data/schema/youtube-type/youtubeThumbnailType.js new file mode 100644 index 0000000..79458cb --- /dev/null +++ b/data/schema/youtube-type/youtubeThumbnailType.js @@ -0,0 +1,18 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean +} = require('graphql'); + +const youtubeThumbnailType = module.exports = new GraphQLObjectType({ + name:'youtubeThumbnailType', + fields:()=>({ + url: {type:GraphQLString}, + width: {type:GraphQLInt}, + height: {type:GraphQLInt}, + }) +}); \ No newline at end of file diff --git a/data/schema/youtubeSchema.js b/data/schema/youtubeSchema.js new file mode 100644 index 0000000..3d1b00e --- /dev/null +++ b/data/schema/youtubeSchema.js @@ -0,0 +1,52 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat, + GraphQLBoolean +} = require('graphql'); +var youtubeAPI = require('../../API/youtubeAPI'); + +const youtubeQueryType = module.exports = new GraphQLObjectType({ + name:'youtubeQuery', + description:`A search result contains information about a YouTube video, channel, +or playlist that matches the search parameters specified in an API +request. While a search result points to a uniquely identifiable resource, +like a video, it does not have its own persistent data.`, + fields: () => ({ + search:{ + type:new GraphQLList(youtubeListType), + args:{ + location: {type:GraphQLString, + description:'e.g.(37.42307,-122.08427)'}, + locationRadius: {type:GraphQLString, + description:`Valid measurement units are m, km, ft, + and mi. For example, valid parameter values include + 1500m, 5km, 10000ft, and 0.75mi. The API does not support + locationRadius parameter values larger than 1000 kilometers.`}, + maxResults: {type:GraphQLInt, + defaultValue:5, + description:'Acceptable values are 0 to 50, inclusive. The default value is 5.'}, + order: {type:GraphQLString, + defaultValue:'relevance', + description:'date, rating, relevance, title, videoCount, viewCount'}, + publishedAfter: {type:GraphQLString, + defaultValue:'1970-01-01T00:00:00Z'}, + publishedBefore: {type:GraphQLString, + defaultValue:'1970-01-01T00:00:00Z'}, + q: {type:GraphQLString, + description:`The q parameter specifies the query term to search for.Your request can + also use the Boolean NOT (-) and OR (|) operators to exclude videos or to find + videos that are associated with one of several search terms.`}, + type: {type:GraphQLString, + defaultValue:'playlist', + description:'channel, playlist,video'} + }, + resolve:(_, args) => youtubeAPI(resolveName='search',id='', args=args) + } + }) +}); + +const youtubeListType = require('./youtube-type/youtubeListType'); \ No newline at end of file