Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TheBrotherFromASouthernMother/4878d12d668414177c4a37852f01d1f8 to your computer and use it in GitHub Desktop.
Save TheBrotherFromASouthernMother/4878d12d668414177c4a37852f01d1f8 to your computer and use it in GitHub Desktop.
The Green Book Project: Example Newsfeed GraphQL Schema
const {
GraphQLObjectType,
GraphQLString,
GraphQLInt,
GraphQLBoolean,
GraphQLList,
} = require('graphql');
const { DateType } = require('app/schema/shared/types.js');
const { LikeType } = require('app/schema/likes/type.js');
const { UserType } = require('app/schema/user/type.js');
const { IntersectionType } = require('app/schema/intersections/type.js');
const { PlaceType } = require('app/schema/places/type.js');
const { MediaListType } = require('app/schema/media/type.js');
const { UserResolvers } = require('app/schema/user/resolvers');
const { PlaceResolvers } = require('app/schema/places/resolvers.js');
const { IntersectionListResolvers } = require('app/schema/intersections/resolvers.js');
const { MediaListResolvers } = require('app/schema/media/resolver.js');
const ReviewType = new GraphQLObjectType({
name: 'Review',
fields: () => ({
id: { type: GraphQLInt },
placeId: { type: GraphQLInt },
description: { type: GraphQLString },
isAnonymous: { type: GraphQLBoolean },
isFlagged: { type: GraphQLBoolean },
photos: { type: new GraphQLList(GraphQLString) },
color: { type: GraphQLString },
likeCount: { type: GraphQLInt },
userId: { type: GraphQLInt },
createdAt: { type: DateType },
place_name: { type: GraphQLString },
media: {
type: MediaListType,
resolve: parent =>
MediaListResolvers.subQueryResolver({ reviewId: parent.id }),
},
intersections: {
type: new GraphQLList(IntersectionType),
resolve: parent =>
IntersectionListResolvers.subQueryResolver({ reviewId: parent.id }),
},
user: {
type: UserType,
resolve: parent =>
userResolvers.subQueryResolver(parent),
},
likes: { type: new GraphQLList(LikeType) },
place: {
type: PlaceType,
args: {
shouldGetFullData: { type: GraphQLBoolean }
},
resolve: (parent, args) => PlaceResolvers.subQueryResolver(parent, args),
},
}),
});
const ReviewListType = new GraphQLObjectType({
name: 'Reviews',
fields: () => ({
items: { type: new GraphQLList(ReviewType) },
hasMore: { type: GraphQLBoolean },
cursor: { type: GraphQLInt },
}),
});
module.exports = {
ReviewType,
ReviewListType,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment