diff --git a/server/app.js b/server/app.js index 61f7755d..ed53b3a6 100644 --- a/server/app.js +++ b/server/app.js @@ -81,10 +81,10 @@ const PORT = process.env.PORT || DEFAULT_PORT; const CORS_OPTIONS = { origin: !process.env.NODE_ENV || process.env.NODE_ENV === 'development' - ? 'http://localhost:3000' + ? ['http://localhost:3000', 'http://localhost:8080', 'http://localhost:5000'] : process.env.NODE_ENV === 'staging' - ? 'http://mm.server1.dashnet.in' - : 'https://mondaymorning.nitrkl.ac.in', + ? ['http://localhost:3000', 'http://localhost:8080', 'http://localhost:5000', 'https://mm.server1.dashnet.in'] + : ['https://mondaymorning.nitrkl.ac.in', 'https://mondaymorning.nitrkl.in'], }; app.use(CORS(CORS_OPTIONS)); @@ -168,6 +168,7 @@ const apolloServer = new ApolloServer({ cors: CORS_OPTIONS, playground: !process.env.NODE_ENV || process.env.NODE_ENV !== 'production', debug: !process.env.NODE_ENV || process.env.NODE_ENV === 'development', + tracing: !process.env.NODE_ENV || process.env.NODE_ENV !== 'production', }); /** Attach Express Server with Apollo Server */ diff --git a/server/schema/article/article.model.js b/server/schema/article/article.model.js index d80adb7c..41cc7cb5 100644 --- a/server/schema/article/article.model.js +++ b/server/schema/article/article.model.js @@ -89,17 +89,24 @@ const ArticleSchema = new Schema( /** * Only for list types * - * For type 6 - ordered list - * [0 - Uppercase Alphabets, 1 - Lowercase Alphabaets, 2 - Uppercase Roman Numbers, 3 - Lowercase Roman Numbers, 4 - Standards Numbers] - * - * For type 7 - unordered list - * [0 - Bullet/Filled Circle, 1 - Hollow Circle, 2 - Dash, 3 - Filled Square, 4 - Hollow Square] + * [ + * 0 - Uppercase Alphabets + * 1 - Lowercase Alphabaets + * 2 - Uppercase Roman Numbers + * 3 - Lowercase Roman Numbers + * 4 - Standards Numbers + * 5 - Bullet/Filled Circle + * 6 - Hollow Circle + * 7 - Dash + * 8 - Filled Square + * 9 - Hollow Square + * ] */ listStyle: { type: Number, required: false, min: 0, - max: 4, + max: 9, }, }, textFormatting: [ diff --git a/server/schema/article/article.mutation.js b/server/schema/article/article.mutation.js index 61f09d0d..f723dc6e 100644 --- a/server/schema/article/article.mutation.js +++ b/server/schema/article/article.mutation.js @@ -1,4 +1,3 @@ -const ContentType = require('../common/content.type'); const { GraphQLObjectType, // GraphQLScalarType, @@ -19,7 +18,7 @@ const { // GraphQLTime, // GraphQLDateTime, // GraphQLJSON, - // GraphQLJSONObject, + GraphQLJSONObject, } = require('../scalars'); const { ArticleTypeEnumType, StatusEnumType } = require('./article.enum.types'); const { @@ -74,7 +73,7 @@ module.exports = new GraphQLObjectType({ type: ArticleType, args: { id: { type: new GraphQLNonNull(GraphQLID) }, - content: { type: new GraphQLNonNull(ContentType) }, + content: { type: new GraphQLNonNull(new GraphQLList(GraphQLJSONObject)) }, }, resolve: updateArticleContent, }, diff --git a/server/schema/article/article.schema.js b/server/schema/article/article.schema.js new file mode 100644 index 00000000..c9a8e056 --- /dev/null +++ b/server/schema/article/article.schema.js @@ -0,0 +1,20 @@ +/** + * @module app.schema.User + * @description User Schema + * + * @requires module:app.schema.scalars + * @requires module:app.schema.UserQuery + * @requires module:app.schema.UserMutation + * + * @version v1 + * @since 0.1.0 + */ + +const { GraphQLSchema } = require('../scalars'); +const ArticleQuery = require('./article.query'); +const ArticleMutation = require('./article.mutation'); + +module.exports = new GraphQLSchema({ + query: ArticleQuery, + mutation: ArticleMutation, +}); diff --git a/server/schema/article/article.type.js b/server/schema/article/article.type.js index 17350ff9..25830136 100644 --- a/server/schema/article/article.type.js +++ b/server/schema/article/article.type.js @@ -1,6 +1,6 @@ const UserDetailType = require('../common/userDetail.type'); -const UserType = require('../user/user.type'); -const { getUser } = require('../user/user.resolver'); +// const UserType = require('../user/user.type'); +// const { getUser } = require('../user/user.resolver'); const ContentType = require('../common/content.type'); const { GraphQLObjectType, @@ -25,36 +25,39 @@ const { // GraphQLJSONObject, } = require('../scalars'); const { ArticleTypeEnumType, StatusEnumType } = require('./article.enum.types'); +const CategoryMapType = require('../categoryMap/categoryMap.type'); +const { getCategory } = require('../categoryMap/categoryMap.resolver'); +const TagType = require('../tag/tag.type'); +const { getTag } = require('../tag/tag.resolver'); +const MediaType = require('../media/media.type'); +const { getMedia } = require('../media/media.resolver'); -const CategoryType = new GraphQLObjectType({ - name: 'Category', +const ArticleCategoryType = new GraphQLObjectType({ + name: 'ArticleCategory', fields: () => ({ category: { type: new GraphQLNonNull(GraphQLInt) }, subcategory: { type: GraphQLBoolean }, - referenceID: { type: GraphQLID }, - // TODO: Resolve to CategoryMapType - /* + referenceID: { + type: GraphQLID, + resolve: (parent) => parent.reference, + }, reference: { type: CategoryMapType, - resolve: async (parent, args, context, info) => {}, + resolve: (parent) => getCategory(null, { id: parent.reference }), }, - */ }), }); -const TagType = new GraphQLObjectType({ - name: 'Tag', +const ArticleTagType = new GraphQLObjectType({ + name: 'ArticleTag', fields: () => ({ name: { type: GraphQLString }, admin: { type: GraphQLBoolean }, referenceID: { type: GraphQLID }, - // TODO: Resolve to TagType - /* reference: { type: TagType, - resolve: async (parent, args, context, info) => {}, + resolve: (parent) => getTag(null, { id: parent.reference }), }, - */ }), }); @@ -62,21 +65,15 @@ const CoverMediaType = new GraphQLObjectType({ name: 'CoverMedia', fields: () => ({ squareID: { type: GraphQLID }, - // TODO: Resolve to MediaType - /* - square: { - type: MediaType, - resolve: async (parent, args, context, info) => {}, - } - */ + square: { + type: MediaType, + resolve: (parent) => getMedia(null, parent.square), + }, rectangleID: { type: GraphQLID }, - // TODO: Resolve to MediaType - /* - rectangle: { - type: MediaType, - resolve: async (parent, args, context, info) => {}, - } - */ + rectangle: { + type: MediaType, + resolve: (parent) => getMedia(null, parent.rectangle), + }, }), }); @@ -101,8 +98,8 @@ const ArticleType = new GraphQLObjectType({ inshort: { type: GraphQLString }, authors: { type: new GraphQLList(UserDetailType) }, tech: { type: new GraphQLList(UserDetailType) }, - category: { type: new GraphQLList(CategoryType) }, - tags: { type: GraphQLList(TagType) }, + category: { type: new GraphQLList(ArticleCategoryType) }, + tags: { type: GraphQLList(ArticleTagType) }, coverMedia: { type: CoverMediaType }, status: { type: StatusEnumType }, isInstituteRestricted: { type: GraphQLBoolean }, @@ -112,16 +109,16 @@ const ArticleType = new GraphQLObjectType({ createdAt: { type: GraphQLDateTime }, createdBy: { type: GraphQLID }, - createdByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), - }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, updatedAt: { type: GraphQLDateTime }, updatedBy: { type: GraphQLID }, - updatedByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), - }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, schemaVersion: { type: GraphQLInt }, }), }); diff --git a/server/schema/categoryMap/categoryMap.resolver.js b/server/schema/categoryMap/categoryMap.resolver.js index e69de29b..293df4cc 100644 --- a/server/schema/categoryMap/categoryMap.resolver.js +++ b/server/schema/categoryMap/categoryMap.resolver.js @@ -0,0 +1,21 @@ +const CategoryMapModel = require('./categoryMap.model'); +const { APIError } = require('../../helpers/errorHandler'); + +module.exports = { + getCategory: async (_parent, { id, number }, _) => { + try { + if (!id && (!number || number instanceof Number)) { + return APIError('BAD_REQUEST'); + } + + const _category = !id ? await CategoryMapModel.findOne({ number }) : await CategoryMapModel.findById(id); + if (!_category) { + return APIError('NOT_FOUND'); + } + + return _category; + } catch (error) { + return APIError(null, error); + } + }, +}; diff --git a/server/schema/categoryMap/categoryMap.type.js b/server/schema/categoryMap/categoryMap.type.js index e69de29b..e9358a85 100644 --- a/server/schema/categoryMap/categoryMap.type.js +++ b/server/schema/categoryMap/categoryMap.type.js @@ -0,0 +1,58 @@ +const { + GraphQLObjectType, + // GraphQLScalarType, + // GraphQLUnionType, + // GraphQLInputObjectType, + // GraphQLEnumType, + // GraphQLInterfaceType, + // GraphQLSchema, + // GraphQLNonNull, + // GraphQLError, + // GraphQLList, + GraphQLString, + GraphQLID, + // GraphQLBoolean, + GraphQLInt, + // GraphQLFloat, + // GraphQLDate, + // GraphQLTime, + GraphQLDateTime, + // GraphQLJSON, + // GraphQLJSONObject, +} = require('../scalars'); +// const { getUser } = require('../user/user.resolver'); +// const UserType = require('../user/user.type'); + +const CategoryMapType = new GraphQLObjectType({ + name: 'CategoryMap', + fields: () => ({ + id: { type: GraphQLID }, + number: { type: GraphQLInt }, + name: { type: GraphQLString }, + parent: { + type: new GraphQLObjectType({ + name: 'ParentCategoryMap', + fields: () => ({ + number: { type: GraphQLInt }, + referenceID: { type: CategoryMapType }, + }), + }), + }, + }), + + createdAt: { type: GraphQLDateTime }, + createdBy: { type: GraphQLID }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, + updatedAt: { type: GraphQLDateTime }, + updatedBy: { type: GraphQLID }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, + schemaVersion: { type: GraphQLInt }, +}); + +module.exports = CategoryMapType; diff --git a/server/schema/common/content.enum.types.js b/server/schema/common/content.enum.types.js index 9f9ae220..a1552394 100644 --- a/server/schema/common/content.enum.types.js +++ b/server/schema/common/content.enum.types.js @@ -29,24 +29,19 @@ module.exports = { JUSTIFY: { value: 3 }, }, }), - OrderedListStyleEnumType: new GraphQLEnumType({ - name: 'OrderedListStyleEnum', + ListStyleEnumType: new GraphQLEnumType({ + name: 'ListStyleEnum', values: { UPPER_ALPHA: { value: 0 }, LOWER_ALPHA: { value: 1 }, UPPER_ROMAN: { value: 2 }, LOWER_ROMAN: { value: 3 }, NUMERICAL: { value: 4 }, - }, - }), - UnorderedListStyleEnumType: new GraphQLEnumType({ - name: 'UnorderedListStyleEnum', - values: { - FILLED_CIRCLE: { value: 0 }, - HOLLOW_CIRCLE: { value: 1 }, - DASH: { value: 2 }, - FILLED_SQUARE: { value: 3 }, - HOLLOW_SQUARE: { value: 4 }, + FILLED_CIRCLE: { value: 5 }, + HOLLOW_CIRCLE: { value: 6 }, + DASH: { value: 7 }, + FILLED_SQUARE: { value: 8 }, + HOLLOW_SQUARE: { value: 9 }, }, }), }; diff --git a/server/schema/common/content.type.js b/server/schema/common/content.type.js index edf49282..8420adfe 100644 --- a/server/schema/common/content.type.js +++ b/server/schema/common/content.type.js @@ -1,7 +1,7 @@ const { GraphQLObjectType, // GraphQLScalarType, - GraphQLUnionType, + // GraphQLUnionType, // GraphQLInputObjectType, // GraphQLEnumType, // GraphQLInterfaceType, @@ -20,24 +20,14 @@ const { // GraphQLJSON, GraphQLJSONObject, } = require('../scalars'); -const { - ContentTypeEnumType, - OrderedListStyleEnumType, - UnorderedListStyleEnumType, - AlignEnumType, -} = require('./content.enum.types'); +const { ContentTypeEnumType, ListStyleEnumType, AlignEnumType } = require('./content.enum.types'); const BlockFormattingType = new GraphQLObjectType({ name: 'BlockFormatting', fields: () => ({ align: { type: AlignEnumType }, hasHeaderRow: { type: GraphQLBoolean }, - listStyle: { - type: new GraphQLUnionType({ - name: 'ListStyleUnion', - types: [OrderedListStyleEnumType, UnorderedListStyleEnumType], - }), - }, + listStyle: { type: ListStyleEnumType }, }), }); diff --git a/server/schema/index.js b/server/schema/index.js index 2d843742..f8707bca 100644 --- a/server/schema/index.js +++ b/server/schema/index.js @@ -11,10 +11,16 @@ * @since 0.1.0 */ -const { mergeSchemas } = require('graphql-tools'); +const { stitchSchemas } = require('graphql-tools'); const UserSchema = require('./user/user.schema'); +const ArticleSchema = require('./article/article.schema'); const IssueSchema = require('./issue/issue.schema'); +const CategoryMapType = require('./categoryMap/categoryMap.type'); +const TagType = require('./tag/tag.type'); +const MediaType = require('./media/media.type'); -module.exports = mergeSchemas({ - schemas: [UserSchema, IssueSchema], +module.exports = stitchSchemas({ + subschemas: [UserSchema, ArticleSchema, IssueSchema], + types: [CategoryMapType, TagType, MediaType], + mergeTypes: true, }); diff --git a/server/schema/issue/issue.type.js b/server/schema/issue/issue.type.js index 8dd3342b..50fc04df 100644 --- a/server/schema/issue/issue.type.js +++ b/server/schema/issue/issue.type.js @@ -13,7 +13,7 @@ const { GraphQLString, // GraphQLSchema, GraphQLID, - //GraphQLList, + GraphQLList, // GraphQLBoolean, GraphQLInt, // GraphQLNonNull, @@ -24,8 +24,12 @@ const { // GraphQLJSONObject, } = require('../scalars'); -const UserType = require('../user/user.type'); -const { getUser } = require('../user/user.resolver'); +// const UserType = require('../user/user.type'); +// const { getUser } = require('../user/user.resolver'); +const MediaType = require('../media/media.type'); +const { getMedia } = require('../media/media.resolver'); +const ArticleType = require('../article/article.type'); +const { getArticle } = require('../article/article.resolver'); const IssueType = new GraphQLObjectType({ name: 'Issue', @@ -33,30 +37,44 @@ const IssueType = new GraphQLObjectType({ id: { type: GraphQLID }, name: { type: GraphQLString }, publishedAt: { type: GraphQLDateTime }, - //TODO: Resolve to their respective types. - //articles: { - // type: GraphQLList(ArticleType), - // resolve: async (parent, _args, context) => getArticle(null, { id: parent.id }, context), - //}, - //featured: { - // type: GraphQLList(ArticleType), - // resolve: async (parent, _args, context) => getArticle(null, { id: parent.id }, context), - //}, + articleIDs: { + type: new GraphQLList(GraphQLID), + resolve: (parent) => parent.articles, + }, + articles: { + type: new GraphQLList(ArticleType), + resolve: (parent, _args, context) => getArticle(null, { id: parent.articles }, context), + }, + featuredIDs: { + type: new GraphQLList(GraphQLID), + resolve: (parent) => parent.featured, + }, + featured: { + type: new GraphQLList(ArticleType), + resolve: (parent, _args, context) => getArticle(null, { id: parent.featured }, context), + }, // polls: { type: GraphQLList(PollType) }, - // thumbnail: { type: MediaType }, + thumbnailID: { + type: GraphQLID, + resolve: (parent) => parent.thumbnail, + }, + thumbnail: { + type: MediaType, + resolve: (parent) => getMedia(null, { id: parent.thumbnail }), + }, description: { type: GraphQLString }, createdAt: { type: GraphQLDateTime }, createdBy: { type: GraphQLID }, - createdByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), - }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, updatedAt: { type: GraphQLDateTime }, updatedBy: { type: GraphQLID }, - updatedByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), - }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, schemaVersion: { type: GraphQLInt }, }), }); diff --git a/server/schema/media/media.enum.type.js b/server/schema/media/media.enum.type.js new file mode 100644 index 00000000..e9ce387d --- /dev/null +++ b/server/schema/media/media.enum.type.js @@ -0,0 +1,9 @@ +const { GraphQLEnumType } = require('../scalars'); + +module.exports = new GraphQLEnumType({ + name: 'MediaTypeEnum', + values: { + IMAGE: { value: 0 }, + VIDEO: { value: 1 }, + }, +}); diff --git a/server/schema/media/media.model.js b/server/schema/media/media.model.js index 2fd2d8d5..0ca268bb 100644 --- a/server/schema/media/media.model.js +++ b/server/schema/media/media.model.js @@ -39,7 +39,7 @@ const MediaSchema = new Schema( trim: true, }, /** [0 - Image, 1 - Video] */ - type: { + mediaType: { type: Number, required: false, min: 0, diff --git a/server/schema/media/media.resolver.js b/server/schema/media/media.resolver.js index e69de29b..93733330 100644 --- a/server/schema/media/media.resolver.js +++ b/server/schema/media/media.resolver.js @@ -0,0 +1,17 @@ +const MediaModel = require('./media.model'); +const { APIError } = require('../../helpers/errorHandler'); + +module.exports = { + getMedia: async (_parent, { id }, _) => { + try { + const _media = await MediaModel.findById(id); + if (!_media) { + return APIError('NOT_FOUND'); + } + + return _media; + } catch (error) { + return APIError(null, error); + } + }, +}; diff --git a/server/schema/media/media.type.js b/server/schema/media/media.type.js index e69de29b..1f5a7ec0 100644 --- a/server/schema/media/media.type.js +++ b/server/schema/media/media.type.js @@ -0,0 +1,53 @@ +const UserDetailType = require('../common/userDetail.type'); +const { + GraphQLObjectType, + // GraphQLScalarType, + // GraphQLUnionType, + // GraphQLInputObjectType, + // GraphQLEnumType, + // GraphQLInterfaceType, + // GraphQLSchema, + // GraphQLNonNull, + // GraphQLError, + GraphQLList, + GraphQLString, + GraphQLID, + // GraphQLBoolean, + GraphQLInt, + // GraphQLFloat, + // GraphQLDate, + // GraphQLTime, + GraphQLDateTime, + // GraphQLJSON, + // GraphQLJSONObject, +} = require('../scalars'); +// const { getUser } = require('../user/user.resolver'); +// const UserType = require('../user/user.type'); +const MediaEnumType = require('./media.enum.type'); + +const MediaType = new GraphQLObjectType({ + name: 'Media', + fields: () => ({ + id: { type: GraphQLID }, + authors: { type: new GraphQLList(UserDetailType) }, + storePath: { type: GraphQLString }, + mediaType: { type: MediaEnumType }, + blurhash: { type: GraphQLString }, + + createdAt: { type: GraphQLDateTime }, + createdBy: { type: GraphQLID }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, + updatedAt: { type: GraphQLDateTime }, + updatedBy: { type: GraphQLID }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, + schemaVersion: { type: GraphQLInt }, + }), +}); + +module.exports = MediaType; diff --git a/server/schema/tag/tag.resolver.js b/server/schema/tag/tag.resolver.js index e69de29b..ea162085 100644 --- a/server/schema/tag/tag.resolver.js +++ b/server/schema/tag/tag.resolver.js @@ -0,0 +1,17 @@ +const TagModel = require('./tag.model'); +const { APIError } = require('../../helpers/errorHandler'); + +module.exports = { + getTag: async (_parent, { id }, _) => { + try { + const _tag = await TagModel.findById(id); + if (!_tag) { + return APIError('NOT_FOUND'); + } + + return _tag; + } catch (error) { + return APIError(null, error); + } + }, +}; diff --git a/server/schema/tag/tag.type.js b/server/schema/tag/tag.type.js index e69de29b..d07b6cda 100644 --- a/server/schema/tag/tag.type.js +++ b/server/schema/tag/tag.type.js @@ -0,0 +1,48 @@ +const { + GraphQLObjectType, + // GraphQLScalarType, + // GraphQLUnionType, + // GraphQLInputObjectType, + // GraphQLEnumType, + // GraphQLInterfaceType, + // GraphQLSchema, + // GraphQLNonNull, + // GraphQLError, + // GraphQLList, + GraphQLString, + GraphQLID, + GraphQLBoolean, + GraphQLInt, + // GraphQLFloat, + // GraphQLDate, + // GraphQLTime, + GraphQLDateTime, + // GraphQLJSON, + // GraphQLJSONObject, +} = require('../scalars'); +// const { getUser } = require('../user/user.resolver'); +// const UserType = require('../user/user.type'); + +const TagType = new GraphQLObjectType({ + name: 'Tag', + fields: () => ({ + name: { type: GraphQLString }, + isAdmin: { type: GraphQLBoolean }, + + createdAt: { type: GraphQLDateTime }, + createdBy: { type: GraphQLID }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, + updatedAt: { type: GraphQLDateTime }, + updatedBy: { type: GraphQLID }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, + schemaVersion: { type: GraphQLInt }, + }), +}); + +module.exports = TagType; diff --git a/server/schema/user/user.type.js b/server/schema/user/user.type.js index 8db30bd3..f9df0441 100644 --- a/server/schema/user/user.type.js +++ b/server/schema/user/user.type.js @@ -12,7 +12,7 @@ const { GraphQLObjectType, // GraphQLScalarType, - // GraphQLUnionType, + GraphQLUnionType, // GraphQLInputObjectType, // GraphQLEnumType, // GraphQLInterfaceType, @@ -32,7 +32,10 @@ const { // GraphQLJSONObject, } = require('../scalars'); -const { getUser } = require('./user.resolver'); +const ArticleType = require('../article/article.type'); +const MediaType = require('../media/media.type'); +// const { getUser } = require('./user.resolver'); +const { getMedia } = require('../media/media.resolver'); const { AccountTypeEnumType, PositionEnumType, TeamEnumType } = require('./user.enum.types'); @@ -55,21 +58,18 @@ const UserProfileType = new GraphQLObjectType({ }), }); -// TODO: Resolve to ArticleType or MediaType -/* const ContributionUnionType = new GraphQLUnionType({ - name: 'ContributionUnion', - types: [ArticleType, MediaType], -}) + name: 'ContributionUnion', + types: [ArticleType, MediaType], +}); const ContributionType = new GraphQLObjectType({ - name: 'Contribution', + name: 'Contribution', fields: () => ({ - model: { type: GraphQLString }, + model: { type: GraphQLString }, reference: { type: ContributionUnionType }, }), }); -*/ /** * @description User Position Type @@ -107,24 +107,19 @@ const UserType = new GraphQLObjectType({ type: GraphQLID, resolve: (parent) => parent.picture, }, - // TODO: Resolve to MediaType - /* - picture: { - type: MediaType, - resolve: async (parent, args, context, info) => {}, - } - */ + picture: { + type: MediaType, + resolve: (parent) => getMedia(null, { id: parent.picture }), + }, interestedTopics: { type: new GraphQLList(GraphQLInt) }, isNewsletterSubscribed: { type: GraphQLBoolean }, profile: { type: UserProfileType }, - /* contributions: { type: new GraphQLList(ContributionType), - }, - */ + }, positions: { type: new GraphQLList(PositionType), }, @@ -145,16 +140,16 @@ const UserType = new GraphQLObjectType({ createdAt: { type: GraphQLDateTime }, createdBy: { type: GraphQLID }, - createdByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), - }, + // createdByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.createdBy }, context, info), + // }, updatedAt: { type: GraphQLDateTime }, updatedBy: { type: GraphQLID }, - updatedByUser: { - type: UserType, - resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), - }, + // updatedByUser: { + // type: UserType, + // resolve: (parent, _, context, info) => getUser(null, { id: parent.updatedBy }, context, info), + // }, schemaVersion: { type: GraphQLInt }, }), });