From 720691067019ce1e5a457524cdecf75777e89f0d Mon Sep 17 00:00:00 2001 From: MTG2000 Date: Sun, 17 Apr 2022 11:40:07 +0300 Subject: [PATCH] feat: update mocks resolvers --- functions/graphql/types/post.js | 4 +- src/mocks/data/projects.ts | 32 ++++++++++- src/mocks/handlers.ts | 53 ++++++++++++++----- src/mocks/resolvers.ts | 6 ++- .../ProjectDetailsCard/ProjectDetailsCard.tsx | 6 +-- src/utils/interfaces/project.interfaces.ts | 18 +++---- 6 files changed, 89 insertions(+), 30 deletions(-) diff --git a/functions/graphql/types/post.js b/functions/graphql/types/post.js index b2e513c..c9328f8 100644 --- a/functions/graphql/types/post.js +++ b/functions/graphql/types/post.js @@ -14,8 +14,8 @@ const { paginationArgs } = require('./helpers'); const PostBase = interfaceType({ name: 'PostBase', - resolveType(post) { - return post.type + resolveType() { + return null }, definition(t) { t.nonNull.int('id'); diff --git a/src/mocks/data/projects.ts b/src/mocks/data/projects.ts index 7cd255b..df71fc1 100644 --- a/src/mocks/data/projects.ts +++ b/src/mocks/data/projects.ts @@ -92,6 +92,7 @@ export let projects = [ "website": "https://getalby.com/", "lightning_address": "hello@getalby.com", "votes_count": 335, + tags: [], "category": { "id": 9, "title": "Misc / Other" @@ -107,6 +108,7 @@ export let projects = [ "website": "https://geyser.fund/", "lightning_address": "divineorgan67@walletofsatoshi.com", "votes_count": 232, + tags: [], "category": { "id": 1, "title": "Finance" @@ -126,6 +128,7 @@ export let projects = [ "website": "https://kollider.xyz/", "lightning_address": "johns@getalby.com", "votes_count": 220, + tags: [], "category": { "id": 1, "title": "Finance" @@ -141,6 +144,7 @@ export let projects = [ "website": "https://lightning.video/", "lightning_address": "moritz@getalby.com", "votes_count": 205, + tags: [], "category": { "id": 7, "title": "Media & News" @@ -156,6 +160,7 @@ export let projects = [ "website": "https://www.wavlake.com/", "lightning_address": "moritz@getalby.com", "votes_count": 45, + tags: [], "category": { "id": 7, "title": "Media & News" @@ -171,6 +176,7 @@ export let projects = [ "website": "https://www.bitrefill.com/buy", "lightning_address": "moritz@getalby.com", "votes_count": 25, + tags: [], "category": { "id": 8, "title": "Shopping" @@ -186,6 +192,7 @@ export let projects = [ "website": "https://sparkshot.io/", "lightning_address": "johns@getalby.com", "votes_count": 11, + tags: [], "category": { "id": 3, "title": "Art & Collectibles" @@ -201,6 +208,7 @@ export let projects = [ "website": "https://lightning-roulette.com/", "lightning_address": "moritz@getalby.com", "votes_count": 10, + tags: [], "category": { "id": 4, "title": "Gaming" @@ -216,9 +224,11 @@ export let projects = [ "website": "https://lnshort.it/", "lightning_address": "moritz@getalby.com", "votes_count": 10, + tags: [], "category": { "id": 9, - "title": "Misc / Other" + "title": "Misc / Other", + } }, { @@ -231,6 +241,7 @@ export let projects = [ "website": "https://lightning.gifts/", "lightning_address": "moritz@getalby.com", "votes_count": 10, + tags: [], "category": { "id": 8, "title": "Shopping" @@ -246,6 +257,7 @@ export let projects = [ "website": "https://www.lnblackjack.com/", "lightning_address": "moritz@getalby.com", "votes_count": 5, + tags: [], "category": { "id": 4, "title": "Gaming" @@ -265,6 +277,7 @@ export let projects = [ "website": "https://satsbuster.herokuapp.com/", "lightning_address": "subirachs@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -282,6 +295,7 @@ export let projects = [ "website": "https://satstreamer.vercel.app", "lightning_address": "kiwiidb@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -300,6 +314,7 @@ export let projects = [ "website": "https://github.com/Zrce/tipwall-frontend", "lightning_address": "tobitcoin@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -325,6 +340,7 @@ export let projects = [ "website": "https://arionparking.tech/", "lightning_address": "atlantabitdevs@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -342,6 +358,7 @@ export let projects = [ "website": "https://webln.twentyuno.net/widget", "lightning_address": "reneaaron@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -364,6 +381,7 @@ export let projects = [ "website": "https://lnshop.github.io/lnshop/", "lightning_address": "alivesession77@walletofsatoshi.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -379,6 +397,7 @@ export let projects = [ "website": "https://lnmarkets.com/", "lightning_address": "johns@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 1, "title": "Finance" @@ -400,6 +419,7 @@ export let projects = [ "website": "https://geyser.fund", "lightning_address": "divineorgan67@walletofsatoshi.com", "votes_count": 0, + tags: [], "category": { "id": 11, "title": "Shock the Web ⚡️" @@ -415,6 +435,7 @@ export let projects = [ "website": "https://loft.trade/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 1, "title": "Finance" @@ -430,6 +451,7 @@ export let projects = [ "website": "https://kriptode.com/satsforlikes/index.html", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 9, "title": "Misc / Other" @@ -445,6 +467,7 @@ export let projects = [ "website": "https://scarce.city/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 3, "title": "Art & Collectibles" @@ -460,6 +483,7 @@ export let projects = [ "website": "https://stacker.news/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 7, "title": "Media & News" @@ -475,6 +499,7 @@ export let projects = [ "website": "https://www.starbackr.com/", "lightning_address": "moritz@geralby.com", "votes_count": 0, + tags: [], "category": { "id": 7, "title": "Media & News" @@ -490,6 +515,7 @@ export let projects = [ "website": "https://amboss.space/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 6, "title": "Analytics" @@ -505,6 +531,7 @@ export let projects = [ "website": "https://yalls.org/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 2, "title": "Social" @@ -520,6 +547,7 @@ export let projects = [ "website": "https://lightningnetworkstores.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 8, "title": "Shopping" @@ -535,6 +563,7 @@ export let projects = [ "website": "https://lightning-poker.com/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 4, "title": "Gaming" @@ -550,6 +579,7 @@ export let projects = [ "website": "https://lngames.net/", "lightning_address": "moritz@getalby.com", "votes_count": 0, + tags: [], "category": { "id": 4, "title": "Gaming" diff --git a/src/mocks/handlers.ts b/src/mocks/handlers.ts index f3a6c02..ca8a180 100644 --- a/src/mocks/handlers.ts +++ b/src/mocks/handlers.ts @@ -1,35 +1,46 @@ import { graphql } from 'msw' import { allCategories, getCategory, getProject, hottestProjects, newProjects, projectsByCategory, searchProjects } from './resolvers' +import { + NavCategoriesQuery, + ExploreProjectsQuery, + SearchProjectsQuery, + SearchProjectsQueryVariables, + CategoryPageQuery, + CategoryPageQueryVariables, + ProjectDetailsQuery, + ProjectDetailsQueryVariables, + HottestProjectsQuery, + HottestProjectsQueryVariables, + AllCategoriesQuery, + AllCategoriesQueryVariables +} from 'src/graphql' const delay = (ms = 1000) => new Promise((res) => setTimeout(res, ms)) export const handlers = [ - graphql.query('PROJECTS_IN_CATEGORY_QUERY', async (req, res, ctx) => { + graphql.query('NavCategories', async (req, res, ctx) => { await delay() - const { categoryId } = req.variables return res( ctx.data({ - projectsByCategory: projectsByCategory(categoryId), - getCategory: getCategory(categoryId) + allCategories: allCategories() }) ) }), - graphql.query('SEARCH_PROJECTS_QUERY', async (req, res, ctx) => { + graphql.query('AllCategories', async (req, res, ctx) => { await delay() - const { search } = req.variables return res( ctx.data({ - searchProjects: searchProjects(search), + allCategories: allCategories() }) ) }), - graphql.query('AllCategoriesProjects', async (req, res, ctx) => { + graphql.query('ExploreProjects', async (req, res, ctx) => { await delay() return res( @@ -40,27 +51,42 @@ export const handlers = [ ) }), - graphql.query('AllCategories', async (req, res, ctx) => { + graphql.query('CategoryPage', async (req, res, ctx) => { await delay() + const { categoryId } = req.variables + return res( ctx.data({ - allCategories: allCategories() + projectsByCategory: projectsByCategory(categoryId), + getCategory: getCategory(categoryId)! }) ) }), - graphql.query('Project', async (req, res, ctx) => { + + graphql.query('SearchProjects', async (req, res, ctx) => { + await delay() + const { search } = req.variables + + return res( + ctx.data({ + searchProjects: searchProjects(search), + }) + ) + }), + + graphql.query('ProjectDetails', async (req, res, ctx) => { await delay() const { projectId } = req.variables return res( ctx.data({ - getProject: getProject(projectId) + getProject: getProject(projectId) as any }) ) }), - graphql.query('HOTTEST_PROJECTS', async (req, res, ctx) => { + graphql.query('HottestProjects', async (req, res, ctx) => { await delay() return res( @@ -69,4 +95,5 @@ export const handlers = [ }) ) }), + ] \ No newline at end of file diff --git a/src/mocks/resolvers.ts b/src/mocks/resolvers.ts index 36b20dc..2542758 100644 --- a/src/mocks/resolvers.ts +++ b/src/mocks/resolvers.ts @@ -2,8 +2,10 @@ import ASSETS from "src/assets"; import { MOCK_DATA } from "./data"; export function getCategory(id: number) { + + const category = MOCK_DATA.categories.find(c => c.id === id)!; return { - ...MOCK_DATA.categories.find(c => c.id === id), + ...category, project: MOCK_DATA.projects.filter(p => p.category.id === id) } } @@ -25,7 +27,7 @@ export function newProjects() { } export function getProject(projectId: number) { - return MOCK_DATA.projects.find(p => p.id === projectId) + return MOCK_DATA.projects.find(p => p.id === projectId)! } export function searchProjects(search: string) { diff --git a/src/pages/ProjectPage/ProjectDetailsCard/ProjectDetailsCard.tsx b/src/pages/ProjectPage/ProjectDetailsCard/ProjectDetailsCard.tsx index 71d134e..ddd30b2 100644 --- a/src/pages/ProjectPage/ProjectDetailsCard/ProjectDetailsCard.tsx +++ b/src/pages/ProjectPage/ProjectDetailsCard/ProjectDetailsCard.tsx @@ -97,8 +97,8 @@ export default function ProjectDetailsCard({ onClose, direction, ...props }: Pro
-
- +
+

{project?.title}

@@ -141,7 +141,7 @@ export default function ProjectDetailsCard({ onClose, direction, ...props }: Pro
{project.screenshots.slice(0, 4).map((screenshot, idx) =>
setScreenshotsOpen(idx)} > diff --git a/src/utils/interfaces/project.interfaces.ts b/src/utils/interfaces/project.interfaces.ts index c192782..682f8f5 100644 --- a/src/utils/interfaces/project.interfaces.ts +++ b/src/utils/interfaces/project.interfaces.ts @@ -1,18 +1,18 @@ -import { Tag } from "src/graphql"; +import { Project as ApiProject, Tag } from "src/graphql"; import { Image } from "."; export interface Project { - id: number; - title: string; + id: ApiProject['id']; + title: ApiProject['title']; category: Pick; - website?: string; - description: string; + website?: ApiProject['website']; + description: ApiProject['description']; tags: Pick[]; - cover_image: Image; - thumbnail_image: Image; - lightning_address?: string | null, + cover_image: ApiProject['cover_image']; + thumbnail_image: ApiProject['thumbnail_image']; + lightning_address?: ApiProject['lightning_address'] | null, screenshots: Image[]; - votes_count: number; + votes_count: ApiProject['votes_count']; } export interface ProjectCategory {