-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
why client에서 피드 요청에 대한 스크롤링을 구현하기 위해서 서버쪽 api 를 임시로 작성 how graphql 에서 전달받은 시간 이후 값을 neo4j에서 쿼리로 조회 * 사용자 정보값은 추가 예정 client확인용으로 작업한 사항
- Loading branch information
1 parent
ec8204b
commit f31e4e0
Showing
3 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |