diff --git a/.gitignore b/.gitignore index d4e6fcb..39c77d4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ node_modules queryCMD -data/*.JSON -.env \ No newline at end of file +data/*.JSON \ No newline at end of file diff --git a/API/fbAPI.js b/API/fbAPI.js new file mode 100644 index 0000000..e92cb5a --- /dev/null +++ b/API/fbAPI.js @@ -0,0 +1,52 @@ +var Promise = require('promise'); +var config = require('../config'); +var FB = require('fb'); +FB.options({version:'v2.8'}); +FB.setAccessToken(config.fb.access_token); //token need to renew every 60 days! + +function search(args,type){ + return new Promise((resolve,reject) => { + FB.api('search?q=' + args['q'] + '&type=' + type,(fb)=>{ + if(!fb || fb.error) { + reject(fb.error); + }else{ + //console.log(fb.data); + resolve(fb.data); + } + }); + }); +} + +function getField(id,field){ + // bad idea to query fields... rethink later!!!!!!!!!!! + return new Promise((resolve,reject) =>{ + FB.api(id['id'],{fields:field},(fb) =>{ + if(!fb || fb.error) { + reject(fb.error); + }else{ + //console.log(field,fb); + resolve(fb[field]); + } + }); + }); +} + +function getEdge(id,edge){ + //rethink later!!!!!!!!!!! + return new Promise((resolve,reject) =>{ + FB.api(id['id'] + "/" + edge ,(fb) =>{ + if(!fb || fb.error) { + reject(fb.error); + }else{ + //console.log(edge,fb); + resolve(fb.data); + } + }); + }); +} + +module.exports = { + search, + getField, + getEdge + }; \ No newline at end of file diff --git a/API/instagramAPI.js b/API/instagramAPI.js deleted file mode 100644 index b56b823..0000000 --- a/API/instagramAPI.js +++ /dev/null @@ -1,203 +0,0 @@ -var request = require('request'); -var config = require('../config'); - -var access_token = config.instagram.access_token_key; - -function instagram(args, fname){ - return new Promise((resolve, reject) =>{ - console.log("In Instagram API, switch functionality now"); - console.log(fname); - var queryUrl = "https://api.instagram.com/v1"; - switch(fname){ - case "usersSelf": - queryUrl = usersSelf(queryUrl); - break; - case "users": - queryUrl = users(args, queryUrl); - break; - case "usersSearch": - queryUrl = usersSearch(args, queryUrl); - break; - case "usersSelfFollows": - queryUrl = usersSelfFollows(queryUrl); - break; - case "usersSelfFollowedBy": - queryUrl = usersSelfFollowedBy(ueryUrl); - break; - case "usersSelfRequestedBy": - queryUrl = usersSelfRequestedBy(queryUrl); - break; - case "usersRelationship": - queryUrl = usersRelationship(args, queryUrl); - break; - case "mediaID": - queryUrl = mediaID(args, queryUrl); - break; - case "mediaShortCode": - queryUrl = mediaShortCode(args, queryUrl); - break; - case "mediaSearch": - queryUrl = mediaSearch(args, queryUrl); - break; - case "comments": - queryUrl = comments(args, queryUrl); - break; - case "likes": - queryUrl = likes(args, queryUrl); - break; - case "tagName": - queryUrl = tagName(args, queryUrl); - break; - case "tagMediaRecent": - queryUrl = tagMediaRecent(args, queryUrl); - break; - case "tagSearch": - queryUrl = tagSearch(args, queryUrl); - break; - case "locationID": - queryUrl = locationID(args, queryUrl); - break; - case "locationMediaRecent": - queryUrl = locationMediaRecent(args, queryUrl); - break; - case "locationSearch": - queryUrl = locationSearch(args, queryUrl); - break; - } - - var options = { - method: 'GET', - uri: queryUrl, - }; - - request(options, function(error, response){ - if(error) { - console.log("Reuqest error") - reject(error); - } - - if(response) { - console.log("send response data back") - resolve(JSON.parse(response.body)); - } - }); - }); -} - -function usersSelf(queryUrl){ - queryUrl += ('/users/self/?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function users(args, queryUrl){ - queryUrl += '/users/' + args.user_id + '/?access_token=' + access_token; - console.log(queryUrl); - return queryUrl -} - -function usersSearch(args, queryUrl){ - queryUrl += '/users/search?access_token=' + access_token; - for(var key in args){ - queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); - } - console.log(queryUrl); - return queryUrl -} - -function usersSelfFollows(queryUrl){ - queryUrl += ('/users/self/follows?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function usersSelfFollowedBy(queryUrl){ - queryUrl += ('/users/self/followed-by?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function usersSelfRequestedBy(queryUrl){ - queryUrl += ('/users/self/requested-by?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function usersRelationship(args, queryUrl){ - queryUrl += ('/users/' + args.user_id + "/relationship?access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function mediaID(args, queryUrl){ - queryUrl += ('/media/' + args.media_id + "?access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function mediaShortCode(args, queryUrl){ - queryUrl += ('/media/' + args.shortcode + "/D?access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function mediaSearch(args, queryUrl){ - queryUrl += ('/media/search?lat=' + args.lat + "&lng=" + args.lng + "&access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function comments(args, queryUrl){ - queryUrl += ('/media/' + args.media_id + "/comments?access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function likes(args, queryUrl){ - queryUrl += ('/media/' + args.media_id + "/likes?access_token=" + access_token); - console.log(queryUrl); - return queryUrl -} - -function tagName(args, queryUrl){ - queryUrl += ('/tags/' + args.tag_name + '?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function tagMediaRecent(args, queryUrl){ - queryUrl += ('/tags/' + args.tag_name + '/media/recent?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function tagSearch(args, queryUrl){ - queryUrl += ('/tags/search?q=' + args.q + '&access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function locationID(args, queryUrl){ - queryUrl += ('/locations/' + args.location_id + '?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function locationMediaRecent(args, queryUrl){ - queryUrl += ('/locations/' + args.location_id + '/media/recent?access_token=' + access_token); - console.log(queryUrl); - return queryUrl -} - -function locationSearch(args, queryUrl){ - queryUrl += ('/locations/search?access_token=' + access_token); - for(var key in args){ - queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); - } - console.log(queryUrl); - return queryUrl -} - -module.exports = { - instagram -} diff --git a/API/mediaWikiAPI.js b/API/mediaWikiAPI.js index 62f6612..0c74210 100644 --- a/API/mediaWikiAPI.js +++ b/API/mediaWikiAPI.js @@ -1,47 +1,47 @@ -var Promise = require('promise'); -var request = require('request'); - -function mediaWiki(args, fname){ - return new Promise((resolve, reject) =>{ - console.log("In MediaWiki API, switch functionality now"); - console.log(fname); - var queryUrl = 'https://en.wikipedia.org/w/api.php?'; - switch(fname){ - case "wikiPageContent": - queryUrl = wikiPageContent(args, queryUrl); - break; - } - console.log(queryUrl); - - var options = { - method: 'GET', - uri: queryUrl, - }; - - request(options, function(error, response){ - if(error) { - console.log("Reuqest error") - reject(error); - } - - if(response) { - console.log("send response data back") - resolve(JSON.parse(response.body)); - } - }); - }); -} - -function wikiPageContent(args, queryUrl){ - queryUrl += "action=query&prop=revisions&rvprop=content&format=json"; - for(var key in args){ - queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); - } - console.log(queryUrl); - return queryUrl -} - -module.exports = { - mediaWiki -} - +var Promise = require('promise'); +var request = require('request'); + +function mediaWiki(args, fname){ + return new Promise((resolve, reject) =>{ + console.log("In MediaWiki API, switch functionality now"); + console.log(fname); + var queryUrl = 'https://en.wikipedia.org/w/api.php?'; + switch(fname){ + case "wikiPageContent": + queryUrl = wikiPageContent(args, queryUrl); + break; + } + console.log(queryUrl); + + var options = { + method: 'GET', + uri: queryUrl, + }; + + request(options, function(error, response){ + if(error) { + console.log("Reuqest error") + reject(error); + } + + if(response) { + console.log("send response data back") + console.log(response.body) + resolve(JSON.parse(response.body)); + } + }); + }); +} + +function wikiPageContent(args, queryUrl){ + queryUrl += "action=query&prop=revisions&rvprop=content&format=json"; + for(var key in args){ + queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); + } + console.log(queryUrl); + return queryUrl +} + +module.exports = { + mediaWiki +} diff --git a/API/pinterestAPI.js b/API/pinterestAPI.js deleted file mode 100644 index b0106d3..0000000 --- a/API/pinterestAPI.js +++ /dev/null @@ -1,215 +0,0 @@ -var request = require('request'); -var config = require('../config'); - -var access_token = config.pinterest.access_token_key; - - -function pinterest(args, fname){ - return new Promise((resolve, reject) =>{ - console.log("In PInterest API, switch functionality now"); - console.log(fname); - var queryUrl = "https://api.pinterest.com/v1"; - switch(fname){ - case "pUserRoot": - queryUrl = pUserRoot(args, queryUrl); - break; - case "pSelfBoards": - queryUrl = pSelfBoards(args, queryUrl); - break; - case "pSelfBoardsSuggested": - queryUrl = pSelfBoardsSuggested(args, queryUrl); - break; - case "pSelfFollower": - queryUrl = pSelfFollower(args, queryUrl); - break; - case "pSelfFollowingBoards": - queryUrl = pSelfFollowingBoards(args, queryUrl); - break; - case "pSelfInterests": - queryUrl = pSelfInterests(args, queryUrl); - break; - case "pSelfFollowing": - queryUrl = pSelfFollowing(args, queryUrl); - break; - case "pSelfLikes": - queryUrl = pSelfLikes(args, queryUrl); - break; - case "pSelfPins": - queryUrl = pSelfPins(args, queryUrl); - break; - case "pSearchBoards": - queryUrl = pSearchBoards(args, queryUrl); - break; - case "pSearchPins": - queryUrl = pSearchPins(args, queryUrl); - break; - } - - var options = { - method: 'GET', - uri: queryUrl, - }; - - request(options, function(error, response){ - if(error) { - console.log("Reuqest error") - reject(error); - } - - if(response) { - console.log("send response data back") - resolve(JSON.parse(response.body)); - } - }); - }); -} - -function selfEncode(args){ - var ret = '' - - for(var key in args){ - if(args[key] && key != 'query') - ret += key + '%2C'; - } - - return ret.substring(0, ret.length-3); -} - -function queryEncode(query){ - var ret = 'query='; - query = query.split(' '); - for(i = 0; i < query.length; i++){ - ret += query[i] + '+'; - } - - return ret.substring(0, ret.length-1); -} - -function pUserRoot(args, queryUrl){ - queryUrl += ('/me/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfBoards(args, queryUrl){ - queryUrl += ('/me/boards/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfBoardsSuggested(args, queryUrl){ - queryUrl += ('/me/boards/suggested/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfFollower(args, queryUrl){ - queryUrl += ('/me/followers/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfFollowingBoards(args, queryUrl){ - queryUrl += ('/me/following/boards/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfInterests(args, queryUrl){ - queryUrl += ('/me/following/interests/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfFollowing(args, queryUrl){ - queryUrl += ('/me/following/users/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfLikes(args, queryUrl){ - queryUrl += ('/me/likes/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSelfPins(args, queryUrl){ - queryUrl += ('/me/pins/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - console.log(queryUrl); - return queryUrl -} - -function pSearchBoards(args, queryUrl){ - queryUrl += ('/me/search/boards/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - query = queryEncode(args.query); - queryUrl += '&' + query; - console.log(queryUrl); - return queryUrl -} - -function pSearchPins(args, queryUrl){ - queryUrl += ('/me/search/pins/?access_token=' + access_token ); - var para = selfEncode(args); - if(para != ''){ - queryUrl += '&fields=' - queryUrl += para - } - query = queryEncode(args.query); - queryUrl += '&' + query; - console.log(queryUrl); - return queryUrl -} - -module.exports = { - pinterest -} \ No newline at end of file diff --git a/API/stackExchangeAPI.js b/API/stackExchangeAPI.js index f96bc8b..6c407bc 100644 --- a/API/stackExchangeAPI.js +++ b/API/stackExchangeAPI.js @@ -1,67 +1,67 @@ -var Promise = require('promise'); -var zlib = require('zlib'); -var http = require("https"); - -function stackExchange(args, fname){ - return new Promise((resolve, reject) =>{ - console.log("In StackExchange API, switch functionality now"); - console.log(fname); - var queryUrl = 'https://api.stackexchange.com/2.2/'; - switch(fname){ - case "advancedSearch": - queryUrl = advancedSearch(args, queryUrl); - break; - case "questionID": - queryUrl = questionID(args, queryUrl); - break; - } - console.log(queryUrl); - // buffer to store the streamed decompression - var buffer = []; - http.get(queryUrl, function (res) { - // pipe the response into the gunzip to decompress - var gunzip = zlib.createGunzip(); - res.pipe(gunzip); - - gunzip.on('data', function (data) { - // decompression chunk ready, add it to the buffer - buffer.push(data.toString()) - }).on("end", function () { - // response and decompression complete, join the buffer and return - console.log("send response data back"); - var data = JSON.parse(buffer.join("")); - resolve(data); - }).on("error", function (e) { - console.log("1.error"); - reject(e); - }) - }).on('error', function (e) { - console.log("2.error"); - reject(e) - }); - }); -} - -function advancedSearch(args, queryUrl){ - queryUrl += "search/advanced?site=stackoverflow"; - for(var key in args){ - queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); - } - console.log(queryUrl); - return queryUrl -} - -function questionID(args, queryUrl){ - queryUrl += "questions/"+args.ids+"?site=stackoverflow"; - for(var key in args){ - if(key == "ids") - continue; - queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); - } - console.log(queryUrl); - return queryUrl -} - -module.exports = { - stackExchange -} +var Promise = require('promise'); +var zlib = require('zlib'); +var http = require("https"); + +function stackExchange(args, fname){ + return new Promise((resolve, reject) =>{ + console.log("In StackExchange API, switch functionality now"); + console.log(fname); + var queryUrl = 'https://api.stackexchange.com/2.2/'; + switch(fname){ + case "advancedSearch": + queryUrl = advancedSearch(args, queryUrl); + break; + case "questionID": + queryUrl = questionID(args, queryUrl); + break; + } + console.log(queryUrl); + // buffer to store the streamed decompression + var buffer = []; + http.get(queryUrl, function (res) { + // pipe the response into the gunzip to decompress + var gunzip = zlib.createGunzip(); + res.pipe(gunzip); + + gunzip.on('data', function (data) { + // decompression chunk ready, add it to the buffer + buffer.push(data.toString()) + }).on("end", function () { + // response and decompression complete, join the buffer and return + console.log("send response data back"); + var data = JSON.parse(buffer.join("")); + resolve(data); + }).on("error", function (e) { + console.log("1.error"); + reject(e); + }) + }).on('error', function (e) { + console.log("2.error"); + reject(e) + }); + }); +} + +function advancedSearch(args, queryUrl){ + queryUrl += "search/advanced?site=stackoverflow"; + for(var key in args){ + queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); + } + console.log(queryUrl); + return queryUrl +} + +function questionID(args, queryUrl){ + queryUrl += "questions/"+args.ids+"?site=stackoverflow"; + for(var key in args){ + if(key == "ids") + continue; + queryUrl += '&' + key + '=' + encodeURIComponent(args[key]); + } + console.log(queryUrl); + return queryUrl +} + +module.exports = { + stackExchange +} diff --git a/API/twitterAPI.js b/API/twitterAPI.js new file mode 100644 index 0000000..3d6c7f6 --- /dev/null +++ b/API/twitterAPI.js @@ -0,0 +1,103 @@ +var Twitter = require('twitter'); +var Promise = require('promise'); +var config = require('../config'); + +var client = new Twitter({ + consumer_key:config.twitter.consumer_key, + consumer_secret:config.twitter.consumer_secret, + access_token_key:config.twitter.access_token_key, + access_token_secret:config.twitter.access_token_secret + }) + +function searchUser(args){ + return new Promise((resolve,reject) =>{ + client.get('users/search',args,function(error,tweets,response){ + if (error) reject(error); + resolve(tweets); + }); + }) +} + +function searchTweet(args){ + return new Promise((resolve,reject) =>{ + client.get('search/tweets',args,function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets.statuses); + }); + }) +} + +function searchGeo(args){ + return new Promise((resolve,reject) =>{ + client.get('geo/search',args,function(error,tweets,response){ + if (error) reject(error); + resolve(tweets.result.places); + }); + }) +} + +function fetchTimeline(user,args){ + args['user_id'] = user.id_str; + //console.log(args); + return new Promise((resolve,reject) =>{ + client.get('statuses/user_timeline',args,function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets); + }); + }) +} + +function fetchRetweet(tweet,args){ + return new Promise((resolve,reject) =>{ + client.get('statuses/retweets/' + tweet.id_str, args, function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets); + }); + }) +} + +function fetchFriend(user,args){ + args['user_id'] = user.id_str; + return new Promise((resolve,reject) =>{ + client.get('friends/list',args,function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets.users); + }); + }) +} + +function fetchFollower(user,args){ + args['user_id'] = user.id_str; + return new Promise((resolve,reject) =>{ + client.get('followers/list',args,function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets.users); + }); + }) +} + +function fetchFollower(user,args){ + args['user_id'] = user.id_str; + return new Promise((resolve,reject) =>{ + client.get('followers/list',args,function(error,tweets,response){ + if (error) reject(error); + //console.log(tweets); + resolve(tweets.users); + }); + }) +} + +module.exports = { + searchUser, + searchTweet, + fetchTimeline, + fetchFriend, + fetchFollower, + fetchRetweet, + searchGeo + }; \ No newline at end of file diff --git a/app.js b/app.js index ccf3dee..1143128 100644 --- a/app.js +++ b/app.js @@ -8,7 +8,7 @@ var graphqlHTTP = require('express-graphql'); var schema = require('./data/schema/schema.js') var index = require('./routes/index'); var users = require('./routes/users'); -var instagramTest = require('./routes/instagram'); +var mongoose = require('mongoose'); var app = express(); @@ -26,7 +26,6 @@ app.use(express.static(path.join(__dirname, 'public'))); app.use('/', index); app.use('/users', users); -app.use('/instagram', instagramTest) app.use('/graphql', graphqlHTTP({ schema, graphiql: true @@ -50,8 +49,42 @@ app.use(function(err, req, res, next) { res.render('error'); }); + +//connect to the mongodb database +mongoose.connect('mongodb://localhost/graphql'); + +//check connection successful or not +var db = mongoose.connection; +db.on('error', console.error.bind(console, 'mongodb connection error:')); +db.once('open', function() { + console.log("successfully connect to mongodb"); +}); + +var kittySchema = mongoose.Schema({ + name: String +}); +var Kitten = mongoose.model('Kitten', kittySchema); +var silence = new Kitten({ name: 'Silence' }); +console.log(silence.name); // 'Silence' +var fluffy = new Kitten({ name: 'fluffy' }); +fluffy.save(function (err) { + if (err) return console.error(err); + console.log("successfully store"); +}); + +silence .save(function (err) { + if (err) return console.error(err); + console.log("successfully store"); +}); + +Kitten.find(function (err, kittens) { + if (err) return console.error(err); + console.log(kittens); +}) + module.exports = { - app + app, + mongoose }; diff --git a/bin/www b/bin/www index c973c46..4f750a8 100755 --- a/bin/www +++ b/bin/www @@ -4,9 +4,7 @@ * Module dependencies. */ -var { - app -} = require('./../app'); +var app = require('../app'); var debug = require('debug')('socialmonitorgraphql:server'); var http = require('http'); diff --git a/config.js b/config.js index 5bdef12..6745c5d 100644 --- a/config.js +++ b/config.js @@ -50,11 +50,5 @@ var config = {}; config.tumblr.comsumer_secret = process.env.TUMBLR_CONSUMER_SECRET; config.tumblr.access_token = process.env.TUMBLR_ACCESS_TOKEN; config.tumblr.access_token_secret = process.env.ACCESS_TOKEN_SECRET; - - config.instagram = {}; - config.instagram.access_token_key = process.env.INSTAGRAM_ACCESS_TOKEN_KEY; - - config.pinterest = {}; - config.pinterest.access_token_key = process.env.PINTEREST_ACCESS_TOKEN; - -module.exports = config; + +module.exports = config; \ No newline at end of file diff --git a/data/schema/facebook-type/fbAttachmentType.js b/data/schema/facebook-type/fbAttachmentType.js index 4779a08..477f73e 100644 --- a/data/schema/facebook-type/fbAttachmentType.js +++ b/data/schema/facebook-type/fbAttachmentType.js @@ -22,4 +22,4 @@ const attachmentType = module.exports = new GraphQLObjectType({ }) }); -const userType = require('./fbUserType'); +const userType = require('./fbUserType'); \ No newline at end of file diff --git a/data/schema/facebook-type/fbCoverPhotoType.js b/data/schema/facebook-type/fbCoverPhotoType.js new file mode 100644 index 0000000..314c4f2 --- /dev/null +++ b/data/schema/facebook-type/fbCoverPhotoType.js @@ -0,0 +1,15 @@ +var { + GraphQLObjectType, + GraphQLString, + GraphQLInt +} = require('graphql'); + +const coverPhotoType = module.exports = new GraphQLObjectType({ + name: 'coverPhoto', + description: 'Return a facebook user\'s cover photo.', + fields: () => ({ + id: { type: GraphQLString }, + offset_y: { type:GraphQLInt }, + source: { type: GraphQLString } + }) +}); diff --git a/data/schema/facebook-type/fbEntityAtTextRangeType.js b/data/schema/facebook-type/fbEntityAtTextRangeType.js new file mode 100644 index 0000000..8d327d9 --- /dev/null +++ b/data/schema/facebook-type/fbEntityAtTextRangeType.js @@ -0,0 +1,23 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLFloat +} = require('graphql'); + +const entityAtTextRangeType = module.exports = new GraphQLObjectType({ + name:'entityAtTextRange', + description:`An array containing an array of objects mentioned in the + name field which contain the id, name, and type of each object as well + as the offset and length which can be used to match it up with its +corresponding string in the name field`, + fields: ()=>({ + id: { type: GraphQLString }, + length: { type: GraphQLInt }, + name: { type: GraphQLString }, + offset: { type: GraphQLInt }, + type: { type: GraphQLString } + }) +}); \ No newline at end of file diff --git a/data/schema/facebook-type/fbLocationType.js b/data/schema/facebook-type/fbLocationType.js new file mode 100644 index 0000000..d864a41 --- /dev/null +++ b/data/schema/facebook-type/fbLocationType.js @@ -0,0 +1,21 @@ +var { + GraphQLList, + GraphQLObjectType, + GraphQLString, + GraphQLInt, + GraphQLFloat +} = require('graphql'); + +const locationType = module.exports = new GraphQLObjectType({ + name:'location', + description:'Location of Place', + fields: () =>({ + city: { type: GraphQLString }, + country: { type: GraphQLString }, + latitude: { type: GraphQLFloat}, + longitude: { type: GraphQLFloat}, + state: { type: GraphQLString }, + street: { type: GraphQLString }, + zip: { type: GraphQLString } + }) +}); \ No newline at end of file diff --git a/data/schema/facebook-type/fbPlaceType.js b/data/schema/facebook-type/fbPlaceType.js new file mode 100644 index 0000000..c871811 --- /dev/null +++ b/data/schema/facebook-type/fbPlaceType.js @@ -0,0 +1,24 @@ +var { + GraphQLList, + GraphQLObjectType, + GraphQLString, + GraphQLInt, + GraphQLFloat +} = require('graphql'); +var getField = require('../../../API/fbAPI').getField; +var getEdge = require('../../../API/fbAPI').getEdge; + +const placeType = module.exports = new GraphQLObjectType({ + name:'place', + description:'return a Facebook place', + fields: ()=>({ + /*---------------------------fields----------------------*/ + id: { type: GraphQLString }, + name: { type: GraphQLString }, + location: { type: locationType, + resolve: ({id}) => getField({id},'location')} + /*---------------------------no edges---------------------*/ + }) +}); + +const locationType = require('./fbLocationType'); diff --git a/data/schema/instagramSchema.js b/data/schema/instagramSchema.js deleted file mode 100644 index d120fcd..0000000 --- a/data/schema/instagramSchema.js +++ /dev/null @@ -1,231 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLFloat -} = require('graphql'); - -var { - instagram -} = require('./../../API/instagramAPI'); - -var { - usersType, - userInfoType, - usersSearchType, -} = require('./instagramSchema/usersSchema'); - -var { - usersSelfFollowsType, - usersSelfFollowedByType, - usersSelfRequestedByType, - usersRelationshipType, -} = require('./instagramSchema/relationshipsSchema'); - -var { - mediaIDType, - mediaShortCodeType, - mediaSearchType -} = require('./instagramSchema/mediaSchema.js'); - -var { - likesType -} = require('./instagramSchema/likesSchema.js'); - -var { - commentsType -} = require('./instagramSchema/commentsSchema.js'); - -var { - tagNameType, - tagMediaRecentType, - tagSearchType -} = require('./instagramSchema/tagsSchema.js'); - -var { - locationIDType, - locationMediaRecentType, - locationSearchType -} = require('./instagramSchema/locationsSchema.js'); - -const instagramQueryType = new GraphQLObjectType({ - name: 'instagramQuery', - description: 'instagram api call', - fields: () => ({ - usersSelf : { - type: usersType, - resolve:(_, args) => instagram(args, "usersSelf") - }, - users : { - type: usersType, - args:{ - user_id: { - type: GraphQLInt, - description: "User Id" - }, - }, - resolve:(_, args) => instagram(args, "users") - }, - usersSearch : { - type: usersSearchType, - args:{ - q: { - type: GraphQLString, - description: "A query string" - }, - count: { - type: GraphQLInt, - description: "Number of users to return" - } - }, - resolve:(_, args) => instagram(args, "usersSearch") - }, - usersSelfFollows: { - type: usersSelfFollowsType, - resolve:(_, args) => instagram(args, "usersSelfFollows") - }, - usersSelfFollowedBy:{ - type: usersSelfFollowedByType, - resolve:(_, args) => instagram(args, "usersSelfFollowedBy") - }, - usersSelfRequestedBy:{ - type: usersSelfRequestedByType, - resolve:(_, args) => instagram(args, "usersSelfRequestedBy") - }, - usersRelationship:{ - type: usersRelationshipType, - args:{ - user_id: { - type: GraphQLInt, - description: "User Id" - } - }, - resolve:(_, args) => instagram(args, "usersRelationship") - }, - mediaID:{ - type: mediaIDType, - args:{ - media_id: { - type: GraphQLString, - description: "Media ID" - } - }, - resolve:(_, args) => instagram(args, "mediaID") - }, - mediaShortCode:{ - type: mediaShortCodeType, - args:{ - shortcode: { - type: GraphQLString, - description: "Media Short Code" - } - }, - resolve:(_, args) => instagram(args, "mediaShortCode") - }, - mediaSearch:{ - type: mediaSearchType, - args:{ - lat: { - type: GraphQLString, - description: "Media Search Latitude" - }, - lng: { - type: GraphQLString, - description: "Media Search Longitude" - } - }, - resolve:(_, args) => instagram(args, "mediaSearch") - }, - comments:{ - type: commentsType, - args:{ - media_id: { - type: GraphQLString, - description: "comments" - } - }, - resolve:(_, args) => instagram(args, "comments") - }, - likes:{ - type: likesType, - args:{ - media_id: { - type: GraphQLString, - description: "likes" - } - }, - resolve:(_, args) => instagram(args, "likes") - }, - tagName:{ - type: tagNameType, - args:{ - tag_name: { - type: GraphQLString, - description: "tag name" - } - }, - resolve:(_, args) => instagram(args, "tagName") - }, - tagMediaRecent:{ - type: tagMediaRecentType, - args:{ - tag_name: { - type: GraphQLString, - description: "tag name" - } - }, - resolve:(_, args) => instagram(args, "tagMediaRecent") - }, - tagSearch:{ - type: tagSearchType, - args:{ - q: { - type: GraphQLString, - description: "query" - } - }, - resolve:(_, args) => instagram(args, "tagSearch") - }, - locationID:{ - type: locationIDType, - args:{ - location_id: { - type: GraphQLString, - description: "query" - } - }, - resolve:(_, args) => instagram(args, "locationID") - }, - locationMediaRecent:{ - type: locationMediaRecentType, - args:{ - location_id: { - type: GraphQLString, - description: "query" - } - }, - resolve:(_, args) => instagram(args, "locationMediaRecent") - }, - locationSearch:{ - type: locationSearchType, - args:{ - lat: { - type: GraphQLFloat, - description: "latitude" - }, - lng: { - type: GraphQLFloat, - description: "longitude" - } - }, - resolve:(_, args) => instagram(args, "locationSearch") - }, - }) -}) - -module.exports = { - instagramQueryType -} diff --git a/data/schema/instagramSchema/commentsSchema.js b/data/schema/instagramSchema/commentsSchema.js deleted file mode 100644 index 60e7170..0000000 --- a/data/schema/instagramSchema/commentsSchema.js +++ /dev/null @@ -1,39 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - followerInfoType -} = require('./relationshipsSchema'); - -const fromType = followerInfoType; - -const commentsDataType = new GraphQLObjectType({ - name: 'commentsData', - description: 'json structure for comments Type', - fields: () => ({ - created_time: {type: GraphQLString}, - text: {type: GraphQLString}, - from: {type: fromType}, - id: {type: GraphQLString} - }) -}) - -const commentsType = new GraphQLObjectType({ - name: 'comments', - description: 'Media comments', - fields: () => ({ - data: {type: new GraphQLList(commentsDataType)} - }) -}) - -module.exports = { - commentsType -} diff --git a/data/schema/instagramSchema/likesSchema.js b/data/schema/instagramSchema/likesSchema.js deleted file mode 100644 index 5cb5535..0000000 --- a/data/schema/instagramSchema/likesSchema.js +++ /dev/null @@ -1,26 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - followerInfoType -} = require('./relationshipsSchema'); - -const likesType = new GraphQLObjectType({ - name: 'likesType', - description: 'json structure for Likes Type', - fields: ()=> ({ - data: {type: new GraphQLList(followerInfoType)} - }) -}) - -module.exports = { - likesType -} diff --git a/data/schema/instagramSchema/locationsSchema.js b/data/schema/instagramSchema/locationsSchema.js deleted file mode 100644 index 1383a79..0000000 --- a/data/schema/instagramSchema/locationsSchema.js +++ /dev/null @@ -1,55 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - mediaType -} = require('./mediaSchema.js'); - -const locationDataType = new GraphQLObjectType({ - name: "locationData", - description: "json structure for Location Data Type", - fields: ()=> ({ - id: {type: GraphQLString}, - name: {type: GraphQLString}, - latitude: {type: GraphQLFloat}, - longitude: {type: GraphQLFloat} - }) -}) - -const locationIDType = new GraphQLObjectType({ - name: "locationID", - description: "json structure for Location ID Type", - fields: ()=> ({ - data: {type: locationDataType} - }) -}) - -const locationMediaRecentType = new GraphQLObjectType({ - name: "locationMediaRecent", - description: "json structure for Location Media Recent Type", - fields: ()=> ({ - data: {type: new GraphQLList(mediaType)} - }) -}) - -const locationSearchType = new GraphQLObjectType({ - name: "locationSearch", - description: "json structure for Location Search Type", - fields: ()=> ({ - data: {type: new GraphQLList(locationDataType)} - }) -}) - -module.exports = { - locationIDType, - locationMediaRecentType, - locationSearchType -} diff --git a/data/schema/instagramSchema/mediaSchema.js b/data/schema/instagramSchema/mediaSchema.js deleted file mode 100644 index f4e6451..0000000 --- a/data/schema/instagramSchema/mediaSchema.js +++ /dev/null @@ -1,203 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - followerInfoType -} = require('./relationshipsSchema'); - -const positionType = new GraphQLObjectType({ - name: 'position', - description: 'json structure for Position Type', - fields: () =>({ - x: {type: GraphQLFloat}, - y: {type: GraphQLFloat}, - }) -}) - -const lowResolutionType = new GraphQLObjectType({ - name: 'lowResolution', - description: 'json structure for lowResolution Type', - fields: () =>({ - url: {type: GraphQLString}, - width: {type: GraphQLInt}, - height: {type: GraphQLInt} - }) -}) - -const standardResolutionType = new GraphQLObjectType({ - name: 'standardResolution', - description: 'json structure for standardResolution Type', - fields: () =>({ - url: {type: GraphQLString}, - width: {type: GraphQLInt}, - height: {type: GraphQLInt} - }) -}) - -const thumbnailType = new GraphQLObjectType({ - name: 'thumbnail', - description: 'json structure for Thumbnail Type', - fields: () =>({ - url: {type: GraphQLString}, - width: {type: GraphQLInt}, - height: {type: GraphQLInt} - }) -}) - -const userPhotoType = new GraphQLObjectType({ - name: 'userPhoto', - description: 'json structure for User Photo Type', - fields: ()=>({ - user: {type: userType}, - position: {type: positionType}, - }) -}) - -const tagsType = new GraphQLObjectType({ - name: 'tag', - description: 'json structure for Tags Type', - fields: ()=>({ - tag: {type: GraphQLString} - }) -}) - -const mediaCommentsType = new GraphQLObjectType({ - name: 'mediaComments', - description: 'json structure for Media Comments Type', - fields: ()=>({ - name: {type: GraphQLString}, - media_count: {type: GraphQLInt} - }) -}) - -const likesType = new GraphQLObjectType({ - name: 'likes', - description: 'json structure for Likes Type', - fields: ()=>({ - count: {type: GraphQLInt} - }) -}) - -const userType = followerInfoType - -const imagesType = new GraphQLObjectType({ - name: 'images', - description: 'json structure for Images Type', - fields: ()=>({ - low_resolution: {type: lowResolutionType}, - thumbnail: {type: thumbnailType}, - standard_resolution: {type: standardResolutionType}, - }) -}) - -const videosType = new GraphQLObjectType({ - name: 'videos', - description: 'json structure for Videos Type', - fields: ()=>({ - low_resolution: {type: lowResolutionType}, - standard_resolution: {type: standardResolutionType}, - }) -}) - -const ImageType = new GraphQLObjectType({ - name: 'Image', - description: 'json structure for Image Data Type', - fields: ()=> ({ - distance: { - type: GraphQLFloat, - description: "Only for mediaSearch Type", - }, - type: {type: GraphQLString}, - users_in_photo: {type: new GraphQLList(userPhotoType)}, - filter: {type: GraphQLString}, - tags: {type: new GraphQLList(tagsType)}, - comments: {type: mediaCommentsType}, - caption: {type: GraphQLString}, - likes: {type: likesType}, - link: {type: GraphQLString}, - user: {type: userType}, - created_time: {type: GraphQLString}, - images: {type: imagesType}, - id: {type: GraphQLString}, - location: {type: GraphQLString}, - }) -}) - -const VideoType = new GraphQLObjectType({ - name: "Video", - description: "json structure for Video Type", - fields: ()=> ({ - distance: { - type: GraphQLFloat, - description: "Only for mediaSearch Type", - }, - type: {type: GraphQLString}, - videos: {type: videosType}, - users_in_photo: {type: new GraphQLList(userPhotoType)}, - filter: {type: GraphQLString}, - tags: {type: new GraphQLList(tagsType)}, - comments: {type: mediaCommentsType}, - caption: {type: GraphQLString}, - likes: {type: likesType}, - link: {type: GraphQLString}, - user: {type: userType}, - created_time: {type: GraphQLString}, - images: {type: imagesType}, - id: {type: GraphQLString}, - location: {type: GraphQLString}, - }) -}) - -const resolveType = (result) => { - if (result.videos){ - return VideoType; - }else{ - return ImageType; - } -}; - -const mediaType = new GraphQLUnionType({ - name: 'media', - description: 'json structure for Media Type', - types: [ImageType, VideoType], - resolveType: resolveType -}) - -const mediaIDType = new GraphQLObjectType({ - name: "mediaID", - description: "json structure for Media ID Type", - fields: ()=> ({ - data: {type: new GraphQLList(mediaType)} - }) -}) - -const mediaShortCodeType = new GraphQLObjectType({ - name: "mediaShortCode", - description: "json structure for Media Short Code Type", - fields: ()=> ({ - data: {type: new GraphQLList(mediaType)} - }) -}) - -const mediaSearchType = new GraphQLObjectType({ - name: "mediaSearch", - description: "json structure for Media Search Type", - fields: ()=> ({ - data: {type: new GraphQLList(mediaType)} - }) -}) - -module.exports = { - mediaIDType, - mediaShortCodeType, - mediaSearchType, - mediaType -} diff --git a/data/schema/instagramSchema/relationshipsSchema.js b/data/schema/instagramSchema/relationshipsSchema.js deleted file mode 100644 index a2831ca..0000000 --- a/data/schema/instagramSchema/relationshipsSchema.js +++ /dev/null @@ -1,76 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean -} = require('graphql'); - -const followerInfoType = new GraphQLObjectType({ - name: "followerInfo", - description: "json structure for follower info", - fields: () => ({ - username: {type: GraphQLString}, - profile_picture: {type: GraphQLString}, - full_name: {type: GraphQLString}, - id: {type: GraphQLString}, - - }) -}) - -const relationshipType = new GraphQLObjectType({ - name: "relationship", - description: "json structure for relationship", - fields: () => ({ - outgoing_status: { - type: GraphQLString, - description: "Your relationship to the user", - }, - incoming_status: { - type: GraphQLString, - description: "A user's relationship to you", - } - }) -}) - -const usersSelfFollowsType = new GraphQLObjectType({ - name: "usersSelfFollows", - description: "json structure for users self follows", - fields: () => ({ - data: {type: new GraphQLList(followerInfoType)} - }) -}) - -const usersSelfFollowedByType = new GraphQLObjectType({ - name: "usersSelfFollowedBy", - description: "json structure for users self followed by", - fields: () => ({ - data: {type: new GraphQLList(followerInfoType)} - }) -}) - -const usersSelfRequestedByType = new GraphQLObjectType({ - name: "usersSelfRequestedBy", - description: "json structure for users self requested by", - fields: () => ({ - data: {type: new GraphQLList(followerInfoType)} - }) -}) - -const usersRelationshipType = new GraphQLObjectType({ - name: "usersRelationship", - description: "json structure for users self requested by", - fields: () => ({ - data: {type: relationshipType} - }) -}) - -module.exports = { - usersSelfFollowsType, - usersSelfFollowedByType, - usersSelfRequestedByType, - usersRelationshipType, - followerInfoType, -} - diff --git a/data/schema/instagramSchema/tagsSchema.js b/data/schema/instagramSchema/tagsSchema.js deleted file mode 100644 index 0d2e98e..0000000 --- a/data/schema/instagramSchema/tagsSchema.js +++ /dev/null @@ -1,53 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - mediaType -} = require('./mediaSchema.js'); - -const tagDataType = new GraphQLObjectType({ - name: "tagData", - description: "json structure for Tag Data Type", - fields: ()=> ({ - media_count: {type: GraphQLInt}, - name: {type: GraphQLString} - }) -}) - -const tagNameType = new GraphQLObjectType({ - name: "tagName", - description: "json structure for Tag Name Type", - fields: ()=> ({ - data: {type: tagDataType} - }) -}) - -const tagMediaRecentType = new GraphQLObjectType({ - name: "mediaRecent", - description: "json structure for Media Recent Type", - fields: ()=> ({ - data: {type: new GraphQLList(mediaType)} - }) -}) - -const tagSearchType = new GraphQLObjectType({ - name: "tagSearch", - description: "json structure for Tag Search Type", - fields: ()=> ({ - data: {type: new GraphQLList(tagDataType)} - }) -}) - -module.exports = { - tagNameType, - tagMediaRecentType, - tagSearchType -} diff --git a/data/schema/instagramSchema/usersSchema.js b/data/schema/instagramSchema/usersSchema.js deleted file mode 100644 index f04b764..0000000 --- a/data/schema/instagramSchema/usersSchema.js +++ /dev/null @@ -1,66 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean -} = require('graphql'); - -const countsType = new GraphQLObjectType({ - name: 'counts', - description: 'instagram counts json structure', - fields: () => ({ - media: {type : GraphQLString}, - follows: {type : GraphQLString}, - followed_by: {type : GraphQLString}, - }) -}) - -const insDataType = new GraphQLObjectType({ - name: 'insData', - description: 'instagram data json structure', - fields: () => ({ - id: {type : GraphQLString}, - username: {type : GraphQLString}, - full_name: {type : GraphQLString}, - profile_picture: {type : GraphQLString}, - bio: {type : GraphQLString}, - website: {type : GraphQLString}, - counts: {type : countsType} - }) -}) - -const usersType = new GraphQLObjectType({ - name: 'users', - description: 'json structure for users type', - fields: () => ({ - data: {type : insDataType} - }) -}) - -const userInfoType = new GraphQLObjectType({ - name: 'userInfo', - description: 'json structure for users information', - fields: () => ({ - username: {type: GraphQLString}, - first_name: {type: GraphQLString}, - profile_picture: {type: GraphQLString}, - id: {type: GraphQLString}, - last_name: {type: GraphQLString} - }) -}) - -const usersSearchType = new GraphQLObjectType({ - name: 'usersSearch', - description: 'json structure for users search', - fields: () =>({ - data: {type: new GraphQLList(userInfoType)} - }) -}) - -module.exports = { - usersType, - userInfoType, - usersSearchType, -} diff --git a/data/schema/mediaWikiSchema.js b/data/schema/mediaWikiSchema.js index c1b7a67..622ff60 100644 --- a/data/schema/mediaWikiSchema.js +++ b/data/schema/mediaWikiSchema.js @@ -1,80 +1,77 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean -} = require('graphql'); - -var { - mediaWiki -} = require('./../../API/mediaWikiAPI'); - -const revisionsType = new GraphQLObjectType({ - name: "revisions", - description: 'wikiPageContent revisions structure', - fields: () => ({ - contentformat: {type: GraphQLString}, - contentmodel: {type: GraphQLString}, - html: {type: GraphQLString} - }) -}) - -const pageIDType = new GraphQLObjectType({ - name: "pageID", - description: 'wikiPageContent page id structure', - fields: () => ({ - pageid: {type: GraphQLInt}, - ns: {type: GraphQLInt}, - title: {type: GraphQLString}, - revisions: {type: new GraphQLList(revisionsType)} - }) -}) - -const pagesType = new GraphQLObjectType({ - name: "pages", - description: 'wikiPageContent pages structure', - fields: () => ({ - pageID: {type: pageIDType}, - }) -}) - -const queryType = new GraphQLObjectType({ - name: "query", - description: 'wikiPageContent query structure', - fields: () => ({ - pages: {type: pagesType}, - }) -}) - -const wikiPageContentType = new GraphQLObjectType({ - name: "wikiPageContent", - description: 'wikiPageContent structure', - fields: () => ({ - batchcomplete: {type: GraphQLString}, - query: {type: queryType} - }) -}) - -const mediaWikiQueryType = new GraphQLObjectType({ - name:'mediaWikiQuery', - description: 'media wiki query', - fields: () => ({ - wikiPageContent : { - type: wikiPageContentType, - args:{ - titles: { - type: GraphQLString, - description: "Title of the wiki page" - }, - }, - resolve:(_, args) => mediaWiki(args, "wikiPageContent") - }, - }) -}) - -module.exports = { - mediaWikiQueryType -} - +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLBoolean +} = require('graphql'); + +var { + mediaWiki +} = require('./../../API/mediaWikiAPI'); + +const revisionsType = new GraphQLObjectType({ + name: "revisions", + description: 'wikiPageContent revisions structure', + fields: () => ({ + contentformat: {type: GraphQLString}, + contentmodel: {type: GraphQLString}, + html: {type: GraphQLString} + }) +}) + +const pageIDType = new GraphQLObjectType({ + name: "pageID", + description: 'wikiPageContent page id structure', + fields: () => ({ + pageid: {type: GraphQLInt}, + ns: {type: GraphQLInt}, + title: {type: GraphQLString}, + revisions: {type: new GraphQLList(revisionsType)} + }) +}) + +const pagesType = new GraphQLObjectType({ + name: "pages", + description: 'wikiPageContent pages structure', + fields: () => ({ + pageID: {type: pageIDType}, + }) +}) + +const queryType = new GraphQLObjectType({ + name: "query", + description: 'wikiPageContent query structure', + fields: () => ({ + pages: {type: pagesType}, + }) +}) + +const wikiPageContentType = new GraphQLObjectType({ + name: "wikiPageContent", + description: 'wikiPageContent structure', + fields: () => ({ + batchcomplete: {type: GraphQLString}, + query: {type: queryType} + }) +}) + +const mediaWikiQueryType = new GraphQLObjectType({ + name:'mediaWikiQuery', + description: 'query wiki page content', + fields: () => ({ + wikiPageContent : { + type: wikiPageContentType, + args:{ + titles: { + type: GraphQLString, + description: "Title of the wiki page" + }, + }, + resolve:(_, args) => mediaWiki(args, "wikiPageContent") + }, + }) +}) + +module.exports = mediaWikiQueryType; \ No newline at end of file diff --git a/data/schema/pinterestSchema.js b/data/schema/pinterestSchema.js deleted file mode 100644 index d7cf0f8..0000000 --- a/data/schema/pinterestSchema.js +++ /dev/null @@ -1,330 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLFloat -} = require('graphql'); - -var { - pinterest -} = require('./../../API/pinterestAPI'); - -var { - pDataType -} = require('./pinterestSchema/userSchema'); - -var { - pBoardsType, - pSelfFollowerType, - pSelfInterestsType, - pSelfLikesType, - pSelfPinsType, - pSearchBoardsType, - pSearchPinsType -} = require('./pinterestSchema/selfSchema'); - -var pUserArgs = { - account_type: { - type: GraphQLBoolean, - defaultValue: true, - }, - bio: { - type: GraphQLBoolean, - defaultValue: true, - }, - counts: { - type: GraphQLBoolean, - defaultValue: true, - }, - created_at: { - type: GraphQLBoolean, - defaultValue: true, - }, - first_name: { - type: GraphQLBoolean, - defaultValue: true, - }, - last_name: { - type: GraphQLBoolean, - defaultValue: true, - }, - id: { - type: GraphQLBoolean, - defaultValue: true, - }, - url: { - type: GraphQLBoolean, - defaultValue: true, - }, - username: { - type: GraphQLBoolean, - defaultValue: true, - }, -}; - -var pBoardsArgs = { - creator: { - type: GraphQLBoolean, - defaultValue: true, - }, - description: { - type: GraphQLBoolean, - defaultValue: true, - }, - counts: { - type: GraphQLBoolean, - defaultValue: true, - }, - created_at: { - type: GraphQLBoolean, - defaultValue: true, - }, - name: { - type: GraphQLBoolean, - defaultValue: true, - }, - privacy: { - type: GraphQLBoolean, - defaultValue: true, - }, - id: { - type: GraphQLBoolean, - defaultValue: true, - }, - url: { - type: GraphQLBoolean, - defaultValue: true, - }, - reason: { - type: GraphQLBoolean, - defaultValue: true, - }, -}; - -var pLikesArgs = { - attribution: { - type: GraphQLBoolean, - defaultValue: true, - }, - board: { - type: GraphQLBoolean, - defaultValue: true, - }, - color: { - type: GraphQLBoolean, - defaultValue: true, - }, - created_at: { - type: GraphQLBoolean, - defaultValue: true, - }, - creator: { - type: GraphQLBoolean, - defaultValue: true, - }, - id: { - type: GraphQLBoolean, - defaultValue: true, - }, - link: { - type: GraphQLBoolean, - defaultValue: true, - }, - media: { - type: GraphQLBoolean, - defaultValue: true, - }, - metadata: { - type: GraphQLBoolean, - defaultValue: true, - }, - note: { - type: GraphQLBoolean, - defaultValue: true, - }, - original_link: { - type: GraphQLBoolean, - defaultValue: true, - }, - url: { - type: GraphQLBoolean, - defaultValue: true, - }, -}; - -var pPinsArgs = pLikesArgs; - -var pSearchBoardsArgs = { - creator: { - type: GraphQLBoolean, - defaultValue: true, - }, - description: { - type: GraphQLBoolean, - defaultValue: true, - }, - counts: { - type: GraphQLBoolean, - defaultValue: true, - }, - created_at: { - type: GraphQLBoolean, - defaultValue: true, - }, - name: { - type: GraphQLBoolean, - defaultValue: true, - }, - privacy: { - type: GraphQLBoolean, - defaultValue: true, - }, - id: { - type: GraphQLBoolean, - defaultValue: true, - }, - url: { - type: GraphQLBoolean, - defaultValue: true, - }, - reason: { - type: GraphQLBoolean, - defaultValue: true, - }, - query: { - type: GraphQLString, - } -}; - -var pSearchPinsArgs = { - attribution: { - type: GraphQLBoolean, - defaultValue: true, - }, - board: { - type: GraphQLBoolean, - defaultValue: true, - }, - color: { - type: GraphQLBoolean, - defaultValue: true, - }, - created_at: { - type: GraphQLBoolean, - defaultValue: true, - }, - creator: { - type: GraphQLBoolean, - defaultValue: true, - }, - id: { - type: GraphQLBoolean, - defaultValue: true, - }, - link: { - type: GraphQLBoolean, - defaultValue: true, - }, - media: { - type: GraphQLBoolean, - defaultValue: true, - }, - metadata: { - type: GraphQLBoolean, - defaultValue: true, - }, - note: { - type: GraphQLBoolean, - defaultValue: true, - }, - original_link: { - type: GraphQLBoolean, - defaultValue: true, - }, - url: { - type: GraphQLBoolean, - defaultValue: true, - }, - query: { - type: GraphQLString, - } -}; - -const pinterestQueryType = new GraphQLObjectType({ - name: 'pinterestQuery', - description: 'pinterest api call', - fields: () => ({ - pUserRoot : { - type: pDataType, - args: pUserArgs, - resolve:(_, args) => pinterest(args, "pUserRoot") - }, - pSelfBoards : { - type: pBoardsType, - args: pBoardsArgs, - resolve:(_, args) => pinterest(args, "pSelfBoards") - }, - pSelfBoardsSuggested : { - type: pBoardsType, - args: pBoardsArgs, - resolve:(_, args) => pinterest(args, "pSelfBoardsSuggested") - }, - pSelfFollower : { - type: pSelfFollowerType, - args: pUserArgs, - resolve:(_, args) => pinterest(args, "pSelfFollower") - }, - pSelfFollowingBoards : { - type: pBoardsType, - args: pBoardsArgs, - resolve:(_, args) => pinterest(args, "pSelfFollowingBoards") - }, - pSelfInterests : { - type: pSelfInterestsType, - args: { - id: { - type: GraphQLBoolean, - defaultValue: true - }, - name: { - type: GraphQLBoolean, - defaultValue: true - }, - }, - resolve:(_, args) => pinterest(args, "pSelfInterests") - }, - pSelfFollowing : { - type: pSelfFollowerType, - args: pUserArgs, - resolve:(_, args) => pinterest(args, "pSelfFollowing") - }, - pSelfLikes : { - type: pSelfLikesType, - args: pLikesArgs, - resolve:(_, args) => pinterest(args, "pSelfLikes") - }, - pSelfPins : { - type: pSelfPinsType, - args: pPinsArgs, - resolve:(_, args) => pinterest(args, "pSelfPins") - }, - pSearchBoards : { - type: pSearchBoardsType, - args: pSearchBoardsArgs, - resolve:(_, args) => pinterest(args, "pSearchBoards") - }, - pSearchPins : { - type: pSearchPinsType, - args: pSearchPinsArgs, - resolve:(_, args) => pinterest(args, "pSearchPins") - }, - }) - -}) - -module.exports = { - pinterestQueryType -} diff --git a/data/schema/pinterestSchema/selfSchema.js b/data/schema/pinterestSchema/selfSchema.js deleted file mode 100644 index 954ea5c..0000000 --- a/data/schema/pinterestSchema/selfSchema.js +++ /dev/null @@ -1,189 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -var { - pUserType -} = require('./userSchema.js') - -const pCreatorType = new GraphQLObjectType({ - name: 'creator', - description: 'json structure for PInterest Creator Type', - fields: ()=> ({ - url: {type: GraphQLString}, - first_name: {type: GraphQLString}, - last_name: {type: GraphQLString}, - id: {type: GraphQLString}, - }) -}) - -const pBoardsCountsType = new GraphQLObjectType({ - name: 'boardsCounts', - description: 'json structure for PInterest Boards Counts Type', - fields: ()=> ({ - pins: {type: GraphQLInt}, - collaborators: {type: GraphQLInt}, - followers: {type: GraphQLInt}, - }) -}) - -const pMediaType = new GraphQLObjectType({ - name: 'pMedia', - description: 'json structure for PInterest Media Type', - fields: ()=> ({ - type: {type: GraphQLString} - }) -}) - -const pMetaDataType = new GraphQLObjectType({ - name: 'pMetaData', - description: 'json structure for PInterest Meta Data Type', - fields: ()=> ({ - link: {type: pLinkType} - }) -}) - -const pLinkType = new GraphQLObjectType({ - name: 'pLink', - description: 'json structure for PInterest Link Type', - fields: ()=> ({ - locale: {type: GraphQLString}, - title: {type: GraphQLString}, - site_name: {type: GraphQLString}, - description: {type: GraphQLString}, - favicon: {type: GraphQLString} - }) -}) - -const pAttributionType = new GraphQLObjectType({ - name: 'pAttribution', - description: 'json structure for PInterest Attribution Type', - fields: ()=> ({ - url: {type: GraphQLString}, - title: {type: GraphQLString}, - provider_icon_url: {type: GraphQLString}, - author_name: {type: GraphQLString}, - provider_favicon_url: {type: GraphQLString}, - author_url: {type: GraphQLString}, - provider_name: {type: GraphQLString}, - }) -}) - -const pBoardsDataType = new GraphQLObjectType({ - name: 'boardsData', - description: 'json structure for PInterest Boards Data Type', - fields: ()=> ({ - name: {type: GraphQLString}, - creator: {type: pCreatorType}, - url: {type: GraphQLString}, - created_at: {type: GraphQLString}, - privacy: {type: GraphQLString}, - reason: {type: GraphQLString}, - // image: {type: } - counts: {type: pBoardsCountsType}, - id: {type: GraphQLString}, - description: {type: GraphQLString} - }) -}) - -const pInterestsDataType = new GraphQLObjectType({ - name: 'pInterestsData', - description: 'json structure for PInterest Self Interests Data Type', - fields: ()=> ({ - id: {type: GraphQLString}, - name: {type: GraphQLString} - }) -}) - -const pLikesDataType = new GraphQLObjectType({ - name: 'pLikesData', - description: 'json structure for PInterest Self Likes Data Type', - fields: ()=> ({ - attribution: {type: pAttributionType}, - creator: {type: pCreatorType}, - url: {type: GraphQLString}, - media: {type: pMediaType}, - created_at: {type: GraphQLString}, - original_link: {type: GraphQLString}, - note: {type: GraphQLString}, - color: {type: GraphQLString}, - link: {type: GraphQLString}, - counts: {type: pBoardsCountsType}, - id: {type: GraphQLString}, - metadata: {type: pMetaDataType} - }) -}) - -const pBoardsType = new GraphQLObjectType({ - name: 'boards', - description: 'json structure for PInterest Boards Type', - fields: ()=> ({ - data: {type: new GraphQLList(pBoardsDataType)} - }) -}) - -var pSelfFollowerType = new GraphQLObjectType({ - name: 'pSelfFollower', - description: 'json structure for PInterest Self Follower Type', - fields: ()=> ({ - data: {type: new GraphQLList(pUserType)} - }) -}) - -var pSelfInterestsType = new GraphQLObjectType({ - name: 'pSelfInterests', - description: 'json structure for PInterest Self Interests Type', - fields: ()=> ({ - data: {type: new GraphQLList(pInterestsDataType)} - }) -}) - -var pSelfLikesType = new GraphQLObjectType({ - name: 'pSelfLikes', - description: 'json structure for PInterest Self Likes Type', - fields: ()=> ({ - data: {type: new GraphQLList(pLikesDataType)}, - }) -}) - -var pSelfPinsType = new GraphQLObjectType({ - name: 'pSelfPins', - description: 'json structure for PInterest Self Pins Type', - fields: ()=> ({ - data: {type: new GraphQLList(pLikesDataType)}, - }) -}) - -var pSearchBoardsType = new GraphQLObjectType({ - name: 'pSearchBoards', - description: 'json structure for PInterest Search Boards Type', - fields: ()=> ({ - data: {type: new GraphQLList(pBoardsDataType)} - }) -}) - -var pSearchPinsType = new GraphQLObjectType({ - name: 'pSearchPins', - description: 'json structure for PInterest Search Pins Type', - fields: ()=> ({ - data: {type: new GraphQLList(pLikesDataType)} - }) -}) - -module.exports = { - pBoardsType, - pSelfFollowerType, - pSelfInterestsType, - pSelfLikesType, - pSelfPinsType, - pSearchBoardsType, - pSearchPinsType -} - diff --git a/data/schema/pinterestSchema/userSchema.js b/data/schema/pinterestSchema/userSchema.js deleted file mode 100644 index af10962..0000000 --- a/data/schema/pinterestSchema/userSchema.js +++ /dev/null @@ -1,54 +0,0 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean, - GraphQLUnionType, - GraphQLFloat -} = require('graphql'); - -const pCountsType = new GraphQLObjectType({ - name: "PInterestCounts", - description: "json structure for PInterest Counts Type", - fields: ()=> ({ - pins: {type: GraphQLInt}, - following: {type: GraphQLInt}, - followers: {type: GraphQLInt}, - boards: {type: GraphQLInt}, - likes: {type: GraphQLInt}, - }) -}) - -const pUserType = new GraphQLObjectType({ - name: "PInterestUser", - description: "json structure for PInterest User Type", - fields: ()=> ({ - username: {type: GraphQLString}, - bio: {type: GraphQLString}, - first_name: {type: GraphQLString}, - last_name: {type: GraphQLString}, - account_type: {type: GraphQLString}, - url: {type: GraphQLString}, - created: {type: GraphQLString}, - // image: {type: pImageType}, - counts: {type: pCountsType}, - id: {type: GraphQLString}, - }) -}) - -const pDataType = new GraphQLObjectType({ - name: "PInterestData", - description: "json structure for PInterest Data Type", - fields: ()=> ({ - data: {type: pUserType} - }) -}) - -module.exports = { - pDataType, - pUserType -} - - diff --git a/data/schema/schema.js b/data/schema/schema.js index b14cbf6..51d27b2 100644 --- a/data/schema/schema.js +++ b/data/schema/schema.js @@ -1,149 +1,73 @@ -var mongoose = require('mongoose'); - -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList -} = require('graphql'); - -var { - stackExchangeQueryType -} = require('./stackExchangeSchema'); - -var { - mediaWikiQueryType -} = require('./mediaWikiSchema'); - -var { - instagramQueryType -} = require('./instagramSchema'); - -var { - pinterestQueryType -} = require('./pinterestSchema'); - -function wrapper(){ - return {} -} - -const twitterQueryType = require('./twitterSchema'); -const fbQueryType = require('./fbSchema'); -const stackExchangeQueryType = require('./stackExchangeSchema'); -const mediaWikiQueryType = require('./mediaWikiSchema'); -const flickrQueryType = require('./flickrSchema'); -const spotifyQueryType = require('./spotifySchema'); -const youtubeQueryType = require('./youtubeSchema'); -const redditQueryType = require('./redditSchema'); -const weiboQueryType = require('./weiboSchema'); -const tumblrQueryType = require('./tumblrSchema'); - -//connect to the mongodb database -mongoose.connect('mongodb://localhost/graphql'); - -//check connection successful or not -var db = mongoose.connection; -db.on('error', console.error.bind(console, 'mongodb connection error:')); -db.once('open', function() { - console.log("successfully connect to mongodb"); -}); - -var kittySchema = mongoose.Schema({ - name: String -}); - -var Kitten = mongoose.model('Kitten', kittySchema); -// var silence = new Kitten({ name: 'Silence' }); -// console.log(silence.name); // 'Silence' -// var fluffy = new Kitten({ name: 'fluffy' }); -// fluffy.save(function (err) { -// if (err) return console.error(err); -// console.log("successfully store"); -// }); - -// silence .save(function (err) { -// if (err) return console.error(err); -// console.log("successfully store"); -// }); - -var promiseListAll = () => { - return new Promise((resolve, reject) => { - Kitten.find((err, kittens) => { - if (err) reject(err) - else resolve(kittens) - }) - }) -} - -const testQueryType = new GraphQLObjectType({ - name:'testQuery', - description: 'a test to fetch query from mongodb database', - fields: () => ({ - name: { - type: GraphQLString, - } - }) -}) - -const Query = new GraphQLObjectType({ - name: "Query", - description: 'all api query type', - fields: () => ({ - stackExchange: { - type: stackExchangeQueryType, - resolve:() => wrapper() - }, - mediaWiki: { - type: mediaWikiQueryType, - resolve:() => wrapper() - }, - instagram: { - type: instagramQueryType, - resolve:() => wrapper() - }, - pinterest: { - type: pinterestQueryType, - resolve:() => wrapper() - }, - dbTest: { - type: new GraphQLList(testQueryType), - resolve:() => promiseListAll() - }, - twitter:{ - type:twitterQueryType, - resolve: () => wrapper() - }, - facebook:{ - type:fbQueryType, - resolve: () => wrapper() - }, - flickr:{ - type: flickrQueryType, - resolve:() => wrapper() - }, - spotify:{ - type: spotifyQueryType, - resolve:() => wrapper() - }, - youtube:{ - type: youtubeQueryType, - resolve:() => wrapper() - }, - reddit:{ - type: redditQueryType, - resolve:() => wrapper() - }, - weibo:{ - type: weiboQueryType, - resolve:() => wrapper() - }, - tumblr:{ - type:tumblrQueryType, - resolve:() => wrapper() - }, - }) -}) - -module.exports = new GraphQLSchema({ - query:Query -}) +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString + }= require('graphql'); + +const twitterQueryType = require('./twitterSchema'); +const fbQueryType = require('./fbSchema'); +const stackExchangeQueryType = require('./stackExchangeSchema'); +const mediaWikiQueryType = require('./mediaWikiSchema'); +const flickrQueryType = require('./flickrSchema'); +const spotifyQueryType = require('./spotifySchema'); +const youtubeQueryType = require('./youtubeSchema'); +const redditQueryType = require('./redditSchema'); +const weiboQueryType = require('./weiboSchema'); +const tumblrQueryType = require('./tumblrSchema'); + +function wrapper(){ + return {} +} + +const Query = new GraphQLObjectType({ + name : 'Query', + description : 'all api query type', + fields : () =>({ + twitter:{ + type:twitterQueryType, + resolve: () => wrapper() + }, + facebook:{ + type:fbQueryType, + resolve: () => wrapper() + }, + flickr:{ + type: flickrQueryType, + resolve:() => wrapper() + }, + spotify:{ + type: spotifyQueryType, + resolve:() => wrapper() + }, + youtube:{ + type: youtubeQueryType, + resolve:() => wrapper() + }, + reddit:{ + type: redditQueryType, + resolve:() => wrapper() + }, + weibo:{ + type: weiboQueryType, + resolve:() => wrapper() + }, + tumblr:{ + type:tumblrQueryType, + resolve:() => wrapper() + }, + stackExchange: { + type: stackExchangeQueryType, + resolve:() => wrapper() + }, + mediaWiki: { + type: mediaWikiQueryType, + resolve:() => wrapper() + } + }) +}); + + +module.exports = new GraphQLSchema({ + query:Query +}); + diff --git a/data/schema/stackExchangeSchema.js b/data/schema/stackExchangeSchema.js index 473069e..05b2bbb 100644 --- a/data/schema/stackExchangeSchema.js +++ b/data/schema/stackExchangeSchema.js @@ -1,118 +1,115 @@ -var { - GraphQLSchema, - GraphQLObjectType, - GraphQLString, - GraphQLList, - GraphQLInt, - GraphQLBoolean -} = require('graphql'); - -var { - stackExchange -} = require('./../../API/stackExchangeAPI'); - -const ownerType = new GraphQLObjectType({ - name: 'owner', - description: 'owner structure return from StackExchange API', - fields: () => ({ - reputation: {type: GraphQLInt} , - user_id: {type: GraphQLInt}, - user_type: {type: GraphQLString}, - profile_image: {type: GraphQLString}, - display_name: {type: GraphQLString}, - link: {type: GraphQLString} - }) -}) - -const itemType = new GraphQLObjectType({ - name: 'item', - description: 'item structure return from StackExchange API', - fields: () => ({ - tags: {type: new GraphQLList(GraphQLString)}, - owner: {type: ownerType}, - is_answered: {type: GraphQLBoolean}, - view_count: {type: GraphQLInt}, - answer_count: {type: GraphQLInt}, - score: {type: GraphQLInt}, - last_activity_date: {type: GraphQLInt}, - creation_date: {type: GraphQLInt}, - last_edit_date: {type: GraphQLInt}, - question_id: {type: GraphQLInt}, - link: {type: GraphQLString}, - title: {type: GraphQLString} - }) -}) - -const advancedSearchType = new GraphQLObjectType({ - name: "advancedSearch", - description: 'advanced search which returns a list of answers', - fields: () => ({ - items: { type: new GraphQLList(itemType) }, - has_more: {type: GraphQLBoolean}, - quota_max: {type: GraphQLInt}, - quota_remaining: {type: GraphQLInt} - }) -}) - -const questionIDType = new GraphQLObjectType({ - name: "questionID", - description: 'search for a question by its ID', - fields: () => ({ - items: { type: new GraphQLList(itemType) }, - has_more: {type: GraphQLBoolean}, - quota_max: {type: GraphQLInt}, - quota_remaining: {type: GraphQLInt} - }) -}) - -const stackExchangeQueryType = new GraphQLObjectType({ - name:'stackExchangeQuery', - description: 'advanced search result json', - fields: () => ({ - advancedSearch : { - type: advancedSearchType, - args:{ - q: { - type: GraphQLString, - description: "The question to search" - }, - sort:{ - type: GraphQLString, - description: "How to sort the result", - defaultValue: "activity" - }, - order:{ - type: GraphQLString, - description: "Order of the result", - defaultValue: "desc" - }, - }, - resolve:(_, args) => stackExchange(args, "advancedSearch") - }, - questionID : { - type: questionIDType, - args:{ - ids: { - type: GraphQLInt, - description: "question ID" - }, - sort:{ - type: GraphQLString, - description: "How to sort the result", - defaultValue: "activity" - }, - order:{ - type: GraphQLString, - description: "Order of the result", - defaultValue: "desc" - }, - }, - resolve:(_, args) => stackExchange(args, "questionID") - } - }) -}) - -module.exports = { - stackExchangeQueryType -} - +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt, + GraphQLBoolean +} = require('graphql'); + +var { + stackExchange +} = require('./../../API/stackExchangeAPI'); + +const ownerType = new GraphQLObjectType({ + name: 'owner', + description: 'owner structure return from StackExchange API', + fields: () => ({ + reputation: {type: GraphQLInt} , + user_id: {type: GraphQLInt}, + user_type: {type: GraphQLString}, + profile_image: {type: GraphQLString}, + display_name: {type: GraphQLString}, + link: {type: GraphQLString} + }) +}) + +const itemType = new GraphQLObjectType({ + name: 'item', + description: 'item structure return from StackExchange API', + fields: () => ({ + tags: {type: new GraphQLList(GraphQLString)}, + owner: {type: ownerType}, + is_answered: {type: GraphQLBoolean}, + view_count: {type: GraphQLInt}, + answer_count: {type: GraphQLInt}, + score: {type: GraphQLInt}, + last_activity_date: {type: GraphQLInt}, + creation_date: {type: GraphQLInt}, + last_edit_date: {type: GraphQLInt}, + question_id: {type: GraphQLInt}, + link: {type: GraphQLString}, + title: {type: GraphQLString} + }) +}) + +const advancedSearchType = new GraphQLObjectType({ + name: "advancedSearch", + description: 'advanced search which returns a list of answers', + fields: () => ({ + items: { type: new GraphQLList(itemType) }, + has_more: {type: GraphQLBoolean}, + quota_max: {type: GraphQLInt}, + quota_remaining: {type: GraphQLInt} + }) +}) + +const questionIDType = new GraphQLObjectType({ + name: "questionID", + description: 'search for a question by its ID', + fields: () => ({ + items: { type: new GraphQLList(itemType) }, + has_more: {type: GraphQLBoolean}, + quota_max: {type: GraphQLInt}, + quota_remaining: {type: GraphQLInt} + }) +}) + +const stackExchangeQueryType = new GraphQLObjectType({ + name:'stackExchangeQuery', + description: 'advanced search result json', + fields: () => ({ + advancedSearch : { + type: advancedSearchType, + args:{ + q: { + type: GraphQLString, + description: "The question to search" + }, + sort:{ + type: GraphQLString, + description: "How to sort the result", + defaultValue: "activity" + }, + order:{ + type: GraphQLString, + description: "Order of the result", + defaultValue: "desc" + }, + }, + resolve:(_, args) => stackExchange(args, "advancedSearch") + }, + questionID : { + type: questionIDType, + args:{ + ids: { + type: GraphQLInt, + description: "question ID" + }, + sort:{ + type: GraphQLString, + description: "How to sort the result", + defaultValue: "activity" + }, + order:{ + type: GraphQLString, + description: "Order of the result", + defaultValue: "desc" + }, + }, + resolve:(_, args) => stackExchange(args, "questionID") + } + }) +}) + +module.exports = stackExchangeQueryType; \ No newline at end of file diff --git a/data/schema/twitter-type/twtEntityType.js b/data/schema/twitter-type/twtEntityType.js new file mode 100644 index 0000000..b637ed5 --- /dev/null +++ b/data/schema/twitter-type/twtEntityType.js @@ -0,0 +1,36 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +const entityType = module.exports = new GraphQLObjectType({ + name : 'entity', + description : 'entity of a tweet or user', + fields : () => ({ + /*--------------------------basic------------------------*/ + urls: { type: new GraphQLList(GraphQLString), + resolve: ({urls}) => { + var url_list = new Array(); + urls.forEach(function(url){ + url_list.push(url['url']); + }); + return url_list + } + }, + hashtags: { type: new GraphQLList(GraphQLString), + resolve: ({hashtags}) => { + var tag_list = new Array(); + hashtags.forEach(function(hashtag){ + tag_list.push(hashtag['text']); + }); + return tag_list + } + }, + user_mentions: { type: new GraphQLList(userType)}, + }) +}); + +const userType = require('./twtUserType'); \ No newline at end of file diff --git a/data/schema/twitter-type/twtGeoType.js b/data/schema/twitter-type/twtGeoType.js new file mode 100644 index 0000000..d9fd483 --- /dev/null +++ b/data/schema/twitter-type/twtGeoType.js @@ -0,0 +1,29 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +const geoType = module.exports = new GraphQLObjectType({ + name: 'geo', + description: `Search for places that can be attached to a statuses/update. + Given a latitude and a longitude pair, an IP address, or a name, this request + will return a list of all the valid places that can be used as the place_ + id when updating a status.`, + fields : ()=> ({ + /*--------------------------basic------------------------*/ + attributes: {type: GraphQLString }, + country: {type: GraphQLString }, + country_code: {type: GraphQLString }, + full_name: {type: GraphQLString }, + id: {type: GraphQLString }, + name: {type: GraphQLString }, + place_type: {type: GraphQLString }, + url: {type: GraphQLString }, + /*--------------------------nested------------------------*/ + contained_within: {type: new GraphQLList(geoType) } + }) +}); + diff --git a/data/schema/twitter-type/twtRetweetType.js b/data/schema/twitter-type/twtRetweetType.js new file mode 100644 index 0000000..05a477a --- /dev/null +++ b/data/schema/twitter-type/twtRetweetType.js @@ -0,0 +1,32 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +const retweetType = module.exports = new GraphQLObjectType({ + name : 'retweet', + description : 'Retweet of a tweet', + fields : () => ({ + /*--------------------------basic------------------------*/ + id: { type: GraphQLString }, + id_str: { type: GraphQLString }, + text: { type: GraphQLString }, + created_at: { type: GraphQLString }, + in_reply_to_status_id_str: { type: GraphQLString }, + in_reply_to_user_id_str: { type: GraphQLString }, + in_reply_to_screen_name: { type: GraphQLString }, + favorite_count: { type: GraphQLInt }, + retweet_count: { type: GraphQLInt }, + /*--------------------------nested------------------------*/ + entities: { type: entityType }, + retweeted_status: { type: tweetType }, + user: { type: userType } + }) +}); + +const userType = require('./twtUserType'); +const entityType = require('./twtEntityType'); +const tweetType = require('./twtTweetType'); \ No newline at end of file diff --git a/data/schema/twitter-type/twtTweetType.js b/data/schema/twitter-type/twtTweetType.js new file mode 100644 index 0000000..b018c93 --- /dev/null +++ b/data/schema/twitter-type/twtTweetType.js @@ -0,0 +1,38 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +var fetchRetweet = require('../../../API/twitterAPI').fetchRetweet; + +const tweetType = module.exports = new GraphQLObjectType({ + name: 'tweet', + description: 'Return a tweet.', + fields : ()=> ({ + /*--------------------------basic------------------------*/ + id: { type: GraphQLString }, + id_str: { type: GraphQLString }, + created_at: { type: GraphQLString }, + text: { type: GraphQLString }, + retweet_count: { type: GraphQLInt }, + in_reply_to_user_id_str: { type: GraphQLString }, + in_reply_to_status_id_str: { type: GraphQLString }, + in_reply_to_screen_name: { type: GraphQLString }, + /*--------------------------nested------------------------*/ + user: { type: userType }, + entities: { type: entityType }, + retweet: { + type: new GraphQLList(retweetType), + description: 'Get a list of retweets', + args: {count:{type:GraphQLInt,defaultValue:3}}, + resolve: (tweet,args) => fetchRetweet(tweet,args) + } + }) +}); + +const userType = require('./twtUserType'); +const entityType = require('./twtEntityType'); +const retweetType = require('./twtRetweetType'); \ No newline at end of file diff --git a/data/schema/twitter-type/twtUserType.js b/data/schema/twitter-type/twtUserType.js new file mode 100644 index 0000000..cce7b75 --- /dev/null +++ b/data/schema/twitter-type/twtUserType.js @@ -0,0 +1,61 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +var { + fetchTimeline, + fetchFollower, + fetchFriend +} = require('../../../API/twitterAPI'); + +const userType = module.exports = new GraphQLObjectType({ + name: 'user', + description: 'Return a twitter user.', + fields: () => ({ + /*--------------------------basic------------------------*/ + id: { type: GraphQLString }, + id_str: { type: GraphQLString }, + name: { type: GraphQLString }, + screen_name: { type: GraphQLString }, + description: { type: GraphQLString }, + created_at: { type: GraphQLString }, + profile_image_url: { type: GraphQLString }, + url: { type: GraphQLString }, + location: { type: GraphQLString }, + tweets_count: { + type: GraphQLInt, + resolve: ({ statuses_count}) => statuses_count + }, + followers_count : { type: GraphQLInt }, + friends_count : { type: GraphQLInt }, + listed_count: { type: GraphQLInt }, + favourites_count: { type: GraphQLInt }, + statuses_count : {type: GraphQLInt }, + time_zone: { type: GraphQLString }, + /*--------------------------nested------------------------*/ + timeline: { + type: new GraphQLList(tweetType), + args:{count:{type:GraphQLInt,defaultValue:3}}, + description: 'Get the timeline of current User', + resolve:(user,args) =>fetchTimeline(user,args) + }, + friends: { + type: new GraphQLList(userType), + args:{count:{type:GraphQLInt,defaultValue:3}}, + description: 'Get a list of followees of current User', + resolve:(user,args) => fetchFriend(user,args) + }, + followers: { + type: new GraphQLList(userType), + args:{count:{type:GraphQLInt,defaultValue:3}}, + description: 'Get a list of followers of current User', + resolve:(user,args) => fetchFollower(user,args) + } + }) +}); + +const tweetType = require('./twtTweetType'); \ No newline at end of file diff --git a/data/schema/twitterSchema.js b/data/schema/twitterSchema.js new file mode 100644 index 0000000..43ad5d7 --- /dev/null +++ b/data/schema/twitterSchema.js @@ -0,0 +1,138 @@ +var { + GraphQLSchema, + GraphQLObjectType, + GraphQLString, + GraphQLList, + GraphQLInt +} = require('graphql'); + +var { + searchTweet, + searchUser, + searchGeo +} = require('./../../API/twitterAPI'); + +// root +const twitterQueryType = module.exports = new GraphQLObjectType({ + name:'twitterQuery', + description:'Query user, tweet, geolocation by keywords.', + fields: () => ({ + queryUser:{ + type: new GraphQLList(userType), + args:{ + q: { type:GraphQLString, + description:'The search query to run against people search.' + }, + count: { type:GraphQLInt, + defaultValue:3, + description:'The number of potential user results to retrieve per page. This value has a maximum of 20.' + }, + page: { type: GraphQLInt, + defaultValue:5, + description: 'Specifies the page of results to retrieve.' + } + }, + resolve: (_,args) => searchUser(args) + }, + queryTweet:{ + type: new GraphQLList(tweetType), + args:{ + q: { + type:GraphQLString, + description:`A UTF-8, URL-encoded search query of 500 characters maximum, + including operators. Queries may additionally be limited + by complexity.` + }, + count: { + type:GraphQLInt, + defaultValue:3, + description:`The number of tweets to return per page, up to a maximum of 100. + Defaults to 15. This was formerly the “rpp” parameter in the + old Search API.` + }, + geocode:{ + type:GraphQLString, + description: '37.781157 -122.398720 1mi' + }, + result_type:{ + type:GraphQLString, + defaultValue:'mixed', + description:`Optional. Specifies what type of search results you would prefer + to receive. The current default is “mixed.” Valid values include: + * mixed : Include both popular and real time results in the response. + * recent : return only the most recent results in the response + * popular : return only the most popular results in the response.` + }, + locale: { + type:GraphQLString, + description:`Specify the language of the query you are sending + (only ja is currently effective). This is intended for + language-specific consumers and the default should work in + the majority of cases.` + }, + until: { + type:GraphQLString, + description:`Returns tweets created before the given date. Date should + be formatted as YYYY-MM-DD. Keep in mind that the search index + has a 7-day limit. In other words, no tweets will be found + for a date older than one week.` + } + }, + resolve: (_,args) => searchTweet(args) + }, + queryGeo: { + type: new GraphQLList(geoType), + args:{ + query: { + type:GraphQLString, + description:`Free-form text to match against while executing a geo-based query, + best suited for finding nearby locations by name. Remember + to URL encode the query.` + }, + ip: { + type:GraphQLString, + description:`An IP address. Used when attempting to fix geolocation based + off of the user’s IP address.` + }, + lat: { + type:GraphQLString, + description:`eg. 37.7821120598956` + }, + long:{ + type:GraphQLString, + description:`eg. -122.400612831116` + }, + granularity:{ + type:GraphQLString, + description:`This is the minimal granularity of place types to return and + must be one of: poi , neighborhood , city , admin or country . + If no granularity is provided for the request neighborhood is assumed. + Setting this to city , for example, will find places which have + a type of city , admin or country .` + }, + accuracy: { + type:GraphQLString, + description:`A hint on the “region” in which to search. If a number, then this + is a radius in meters, but it can also take a string that is suffixed with ft to + specify feet. If this is not passed in, then it is assumed to be 0m . If coming + from a device, in practice, this value is whatever accuracy the device has measuring + its location (whether it be coming from a GPS, WiFi triangulation, etc.).` + }, + max_results:{ + type:GraphQLString, + description:`A hint as to the number of results to return. This does not guarantee + that the number of results returned will equal max_results, but instead informs how + many “nearby” results to return. Ideally, only pass in the number of places you + intend to display to the user here.` + } + }, + resolve: (_,args) => searchGeo(args) + } + }) +}); + +const userType = require('./twitter-type/twtUserType'); +const tweetType = require('./twitter-type/twtTweetType'); +const geoType = require('./twitter-type/twtGeoType'); + +module.exports = twitterQueryType; \ No newline at end of file diff --git a/index.js b/index.js new file mode 100644 index 0000000..5785bd6 --- /dev/null +++ b/index.js @@ -0,0 +1,15 @@ +var express = require('express'); +var graphQLHTTP = require('express-graphql'); +var schema = require('./data/schema/schema.js'); +const cors = require('cors'); + +//console.log(schema); + +const app = express(); + +app.use('/graphql',cors(), graphQLHTTP({ + schema, + graphiql:true, +})) + +app.listen(8080); \ No newline at end of file diff --git a/package.json b/package.json index 1efde40..a40b909 100644 --- a/package.json +++ b/package.json @@ -1,31 +1,35 @@ { - "name": "socialmonitorgraphql", - "version": "0.0.0", - "private": true, + "name": "graph-ql", + "version": "1.0.0", + "description": "using graph ql to fetch data from multiple facebook and twitter endpoints", + "main": "index.js", "scripts": { - "start": "nodemon ./bin/www" + "start": "nodemon ./index.js" }, "dependencies": { - "body-parser": "~1.16.0", - "cookie-parser": "~1.4.3", - "debug": "~2.6.0", "dotenv": "^4.0.0", - "express": "~4.14.1", + "express": "^4.15.2", "express-graphql": "^0.6.3", + "fb": "^1.1.1", "form-data": "^2.1.2", "generate-schema": "^2.3.3", "graphql": "^0.9.1", - "instagram-node": "^0.5.8", "mongoose": "^4.9.2", "morgan": "~1.7.0", "node-fetch": "^1.6.3", + "nodemon": "^1.11.0", "promise": "^7.1.1", - "pug": "~2.0.0-beta10", - "request": "^2.81.0", - "serve-favicon": "~2.3.2" + "twitter": "^1.7.0" }, - "devDependencies": { - "babel-preset-node6": "^11.0.0", - "nodemon": "^1.11.0" - } + "devDependencies": {}, + "repository": { + "type": "git", + "url": "git+https://github.com/longshuicy/graphQL-fb-twt.git" + }, + "author": "chenwang.carrie@gmail.com, lunanli3@illinois.edu, dtubbs2@illinois.edu ", + "license": "ISC", + "bugs": { + "url": "https://github.com/longshuicy/graphQL-fb-twt/issues" + }, + "homepage": "https://github.com/longshuicy/graphQL-fb-twt#readme" } diff --git a/routes/instagram.js b/routes/instagram.js deleted file mode 100644 index e6bb5ae..0000000 --- a/routes/instagram.js +++ /dev/null @@ -1,31 +0,0 @@ -var express = require('express'); -var router = express.Router(); -var config = require('../config'); -var request = require('request'); - -var access_token = config.instagram.access_token_key; -var client_id = config.instagram.client_id; -var client_secret = config.instagram.client_secret; - -var queryUrl = 'https://api.pinterest.com/v1/me/search/boards/?query=kobe+bryant&access_token=AcXsKcuUy0Pcv1hcgX2IaLbqZezGFLSJHd9YFb9D7ZpX7SA_wgAAAAA&fields=id%2Cname%2Curl%2Ccounts%2Ccreated_at%2Ccreator%2Cdescription%2Cimage%2Cprivacy%2Creason' -var options = { - method: 'GET', - uri: queryUrl, -}; - -router.get('/', function(req, res, next) { - console.log(queryUrl); - request(options, function(error, response){ - if(error) { - console.log("Reuqest error") - res.send(error) - } - - if(response) { - console.log("send response data back") - res.send(JSON.parse(response.body)) - } - }); -}); - -module.exports = router;