Skip to content

Commit

Permalink
[Add] 새 피드 요청 반환하는 api prototype 작성 #24 #32
Browse files Browse the repository at this point in the history
why
client에서 피드 요청에 대한 스크롤링을 구현하기 위해서 서버쪽 api 를 임시로 작성

how
graphql 에서 전달받은 시간 이후 값을 neo4j에서 쿼리로 조회

*
사용자 정보값은 추가 예정
client확인용으로 작업한 사항
  • Loading branch information
WooYeonSeo committed Nov 22, 2019
1 parent ec8204b commit f31e4e0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
16 changes: 16 additions & 0 deletions server/src/api/feed/feed.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
scalar Upload

type Feed {
content: String!
createdAt: String
}

type PageInfo {
endCursor: String
hasNextPage: Boolean
}
type Query {
getFeeds: [Feed]!
feeds(first: Int, cursor: String): [Feed]!
pageInfo: PageInfo
}
41 changes: 41 additions & 0 deletions server/src/api/feed/feed.resolvers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import db from "../../db";
import { MATCH_NEW_FEEDS } from "../../schema/feed/query";
const session = db.session();

interface IPageParam {
first: number;
after: number;
cursor: string;
}
export interface IKey<T> {
[key: string]: T;
}

const parseResult = result => {
const returnArr: Array<IKey<string | number>> = [];
for (const item of result) {
let i = 0;
const obj = {};
for (const key of item.keys) {
obj[key] = item.get(i);
i++;
}

returnArr.push(obj);
}
return returnArr;
};

export default {
Query: {
feeds: async (
_,
{ first, cursor = "9999-12-31T09:29:26.050Z" }: IPageParam
) => {
const result = await session.run(MATCH_NEW_FEEDS, { cursor, first });

const parsedResult = parseResult(result.records);
return parsedResult;
}
}
};
6 changes: 6 additions & 0 deletions server/src/schema/feed/query.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const MATCH_NEW_FEEDS = `MATCH (a:User { email: '[email protected]' })-[:AUTHOR]->(f:Feed)
where f.createdAt < datetime({cursor})
RETURN a.nickname as nickname, a.thumbnail as thumbnail ,
f.content as content ,apoc.convert.toString(f.createdAt) as createdAt
LIMIT {first} `;
export { MATCH_NEW_FEEDS };

0 comments on commit f31e4e0

Please sign in to comment.