Skip to content

Commit

Permalink
reddit done
Browse files Browse the repository at this point in the history
need some testing though
  • Loading branch information
longshuicy authored Apr 20, 2017
1 parent 62cddf5 commit 7b94a5a
Show file tree
Hide file tree
Showing 8 changed files with 534 additions and 1 deletion.
67 changes: 67 additions & 0 deletions data/schema/reddit-type/redditCommentType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean
} = require('graphql');

const redditCommentType = module.exports = new GraphQLObjectType({
name:'redditComment',
description:'',
fields: () => ({
author_name: {type:GraphQLString,
resolve:({author})=>{return author.name}},
author_flair_css_class: {type:GraphQLString},
author_flair_text: {type:GraphQLString},
archived: {type:GraphQLBoolean},
approved_by: {type:GraphQLString},
banned_by: {type:GraphQLString},
body: {type:GraphQLString},
body_html: {type:GraphQLString},
created_utc: {type:GraphQLString},
created: {type:GraphQLString},
controversiality: {type:GraphQLInt},
distinguished: {type:GraphQLBoolean},
downs: {type:GraphQLInt},
edited: {type:GraphQLBoolean},
gilded: {type:GraphQLInt},
id: {type:GraphQLString},
link_id: {type:GraphQLString},
link_author: {type:GraphQLString},
link_title: {type:GraphQLString},
link_permalink: {type:GraphQLString},
link_url: {type:GraphQLString},
likes: {type:GraphQLInt},
mod_reports: {type:new GraphQLList(GraphQLString)},
name: {type:GraphQLString},
num_comments: {type:GraphQLInt},
num_reports: {type:GraphQLInt},
over_18: {type:GraphQLBoolean},
parent_id: {type:GraphQLString},
quarantine: {type:GraphQLBoolean},
//replies:
report_reasons: {type:new GraphQLList(GraphQLString)},
removal_reason: {type:GraphQLString},
saved: {type:GraphQLBoolean},
score: {type:GraphQLInt},
subreddit_id: {type:GraphQLString},
subreddit_display_name: {type:GraphQLString,
resolve:({subreddit})=>{return subreddit.display_name}},
subreddit_name_prefixed:{type:GraphQLString},
score_hidden: {type:GraphQLBoolean},
stickied: {type:GraphQLBoolean},
subreddit_type: {type:GraphQLString},
ups: {type:GraphQLInt},
user_reports: {type:new GraphQLList(GraphQLString)},
/*-------------------------------nested----------------------------------*/
/*expand_replies: {type:new GraphQLList(redditCommentType),
args:{
limit: {type:GraphQLInt},
depth: {type:GraphQLInt},
},
resolve: ({id},args) => redditAPI(resolveName='expansion',id=id,args=args)},*/
})
});
21 changes: 21 additions & 0 deletions data/schema/reddit-type/redditFlairType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean
} = require('graphql');

const redditFlairType = module.exports = new GraphQLObjectType({
name:'redditFlair',
description:'',
fields: () => ({
flair_css_class: {type:GraphQLString},
flair_template_id: {type:GraphQLString},
flair_text_editable: {type:GraphQLBoolean},
flair_position: {type:GraphQLString},
flair_text: {type:GraphQLString},
})
});
107 changes: 107 additions & 0 deletions data/schema/reddit-type/redditLinkType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean
} = require('graphql');
var redditAPI = require('../../../API/redditAPI');

const redditLinkType = module.exports = new GraphQLObjectType({
name:'redditLink',
description:'',
fields: () => ({
approved_by: {type:GraphQLString},
archived: {type:GraphQLBoolean},
author_name: {type:GraphQLString,
resolve: ({author})=>{return author.name}},
author_flair_css_class: {type:GraphQLString},
author_flair_text: {type:GraphQLString},
banned_by: {type:GraphQLString},
brand_safe: {type:GraphQLBoolean},
contest_mode: {type:GraphQLBoolean},
clicked: {type:GraphQLBoolean},
created: {type:GraphQLString},
created_utc: {type:GraphQLString},
domain: {type:GraphQLString},
downs: {type:GraphQLInt},
distinguished: {type:GraphQLString},
edited: {type:GraphQLInt},
gilded: {type:GraphQLInt},
hidden: {type:GraphQLBoolean},
hide_score: {type:GraphQLBoolean},
id: {type:GraphQLString},
is_self: {type:GraphQLBoolean},
likes: {type:GraphQLBoolean},
link_flair_css_class: {type:GraphQLString},
link_flair_text: {type:GraphQLString},
locked: {type:GraphQLBoolean},
media: {type:GraphQLString},
//media_embed: {type:GraphQLString},
mod_reports: {type:new GraphQLList(GraphQLString)},
name: {type:GraphQLString},
num_comments: {type:GraphQLInt},
num_reports: {type:GraphQLInt},
over_18: {type:GraphQLBoolean},
post_hint: {type:GraphQLString},
/*preview_enabled: {type:GraphQLBoolean,
resolve:({preview}) =>{return preview.enabled}},
preview_images: {type:new GraphQLList(GraphQLString),
resolve:({preview}) =>{return preview.images;
console.log(preview.images);}},*/
permalink: {type:GraphQLString},
quarantine: {type:GraphQLBoolean},
report_reasons: {type:GraphQLString},
removal_reason: {type:GraphQLString},
saved: {type:GraphQLBoolean},
score: {type:GraphQLInt},
selftext: {type:GraphQLString},
selftext_html: {type:GraphQLString},
secure_media: {type:GraphQLString},
secure_media_embed: {type:GraphQLString},
stickied: {type:GraphQLBoolean},
spoiler: {type:GraphQLBoolean},
subreddit_display_name: {type:GraphQLString,
resolve: ({subreddit})=>{return subreddit.display_name}},
suggested_sort: {type:GraphQLString},
subreddit_id: {type:GraphQLString},
subreddit_type: {type:GraphQLString},
subreddit_name_prefixed:{type:GraphQLString},
thumbnail: {type:GraphQLString},
title: {type:GraphQLString},
url: {type:GraphQLString},
ups: {type:GraphQLInt},
user_reports: {type:new GraphQLList(GraphQLString)},
visited: {type:GraphQLBoolean},
/*--------------------------nested------------------------*/
author_trophy: {type:new GraphQLList(redditTrophyType),
resolve: ({author}) => redditAPI(resolveName='trophy', id=author.name, args={})},
author_overview: {type:new GraphQLList(redditOverviewType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({author},args) => redditAPI(resolveName='overview', id=author.name, args=args)},
author_submission: {type:new GraphQLList(redditLinkType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({author},args) => redditAPI(resolveName='submission', id=author.name, args=args)},
author_comment: {type:new GraphQLList(redditCommentType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({author},args) => redditAPI(resolveName='comment', id=author.name, args=args)},
author_upvote: {type:new GraphQLList(redditOverviewType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({author},args) => redditAPI(resolveName='upvote', id=author.name, args=args)},
author_downvote: {type:new GraphQLList(redditOverviewType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({author},args) => redditAPI(resolveName='downvote', id=author.name, args=args)},
/*expand_replies: {type:new GraphQLList(redditCommentType),
args:{
limit: {type:GraphQLInt},
depth: {type:GraphQLInt},
},
resolve: ({id},args) => redditAPI(resolveName='expansion',id=id,args=args)},*/
})
});

const redditTrophyType = require('./redditTrophyType');
const redditCommentType = require('./redditCommentType');
const redditOverviewType = require('./redditOverviewType');
28 changes: 28 additions & 0 deletions data/schema/reddit-type/redditOverviewType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLBoolean,
GraphQLUnionType
} = require('graphql');


const redditCommentType = require('./redditCommentType');
const redditLinkType = require('./redditLinkType');

const resolveType = (data) => {
if (data.body){
return redditCommentType;
}else{
return redditLinkType;
}
};

const redditOverviewType = module.exports = new GraphQLUnionType({
name: 'redditOverview',
description: `comment | link`,
types: [redditCommentType, redditLinkType],
resolveType: resolveType
});
23 changes: 23 additions & 0 deletions data/schema/reddit-type/redditTrophyType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean
} = require('graphql');

const redditTrophyType = module.exports = new GraphQLObjectType({
name:'redditTrophy',
description:'',
fields: () => ({
icon_70: {type:GraphQLString},
name: {type:GraphQLString},
url: {type:GraphQLString},
icon_40: {type:GraphQLString},
award_id: {type:GraphQLString},
id: {type:GraphQLString},
description: {type:GraphQLString},
})
});
78 changes: 78 additions & 0 deletions data/schema/reddit-type/subredditType.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
var {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLFloat,
GraphQLBoolean
} = require('graphql');
var redditAPI = require('../../../API/redditAPI');

const subredditType = module.exports = new GraphQLObjectType({
name:'subreddit',
description:'',
fields: () => ({
accounts_active: {type:GraphQLInt},
accounts_active_is_fuzzed: {type:GraphQLBoolean},
advertiser_category: {type:GraphQLString},
allow_images: {type:GraphQLBoolean},
banner_img: {type:GraphQLString},
banner_size: {type:GraphQLString},
created: {type:GraphQLString},
created_utc: {type:GraphQLString},
comment_score_hide_mins: {type:GraphQLInt},
collapse_deleted_comments: {type:GraphQLBoolean},
description: {type:GraphQLString},
description_html: {type:GraphQLString},
display_name: {type:GraphQLString},
display_name_prefixed: {type:GraphQLString},
header_img: {type:GraphQLString},
header_size: {type:new GraphQLList(GraphQLInt)},
header_title: {type:GraphQLString},
hide_ads: {type:GraphQLBoolean},
id: {type:GraphQLString},
icon_size: {type:GraphQLString},
lang: {type:GraphQLString},
key_color: {type:GraphQLString},
name: {type:GraphQLString},
over18: {type:GraphQLBoolean},
public_description: {type:GraphQLString},
public_description_html: {type:GraphQLString},
public_traffic: {type:GraphQLBoolean},
quarantine: {type:GraphQLBoolean},
show_media: {type:GraphQLBoolean},
show_media_preview: {type:GraphQLBoolean},
subscribers: {type:GraphQLInt},
spoilers_enabled: {type:GraphQLBoolean},
suggested_comment_sort: {type:GraphQLString},
submission_type: {type:GraphQLString},
submit_text: {type:GraphQLString},
submit_link_label: {type:GraphQLString},
submit_text_label: {type:GraphQLString},
submit_text_html: {type:GraphQLString},
subreddit_type: {type:GraphQLString},
title: {type:GraphQLString},
url: {type:GraphQLString},
user_sr_theme_enabled: {type:GraphQLBoolean},
user_is_banned: {type:GraphQLBoolean},
user_is_contributor: {type:GraphQLBoolean},
user_is_moderator: {type:GraphQLBoolean},
user_is_subscriber: {type:GraphQLBoolean},
user_is_muted: {type:GraphQLBoolean},
wiki_enabled: {type:GraphQLBoolean},
whitelist_status: {type:GraphQLString},
/*-----------------------------------nested--------------------------------*/
/*user_flair: {type:new GraphQLList(redditFlairType),
resolve: ({display_name})=>redditAPI(resolveName='getUserFlairTemplates',id=display_name, args={})},
hot: {type:new GraphQLList(redditLinkType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({display_name},args)=>redditAPI(resolveName='subreddit_hot',id=display_name, args=args)},
new: {type:new GraphQLList(redditLinkType),
args:{extra:{type:GraphQLInt, defaultValue:0}},
resolve: ({display_name},args)=>redditAPI(resolveName='subreddit_new',id=display_name, args=args)},*/
})
});

const redditFlairType = require('./redditFlairType');
const redditLinkType = require('./redditLinkType');
Loading

0 comments on commit 7b94a5a

Please sign in to comment.