Skip to content

Commit

Permalink
feat: add support for network field in follows (#847)
Browse files Browse the repository at this point in the history
  • Loading branch information
wa0x6e authored May 22, 2024
1 parent 096c18f commit 38170cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/graphql/operations/follows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ export default async function (parent, args) {
ipfs: 'string',
follower: 'string',
space: 'string',
network: 'string',
created: 'number'
};
const whereQuery = buildWhereQuery(fields, 'f', where);
const queryStr = whereQuery.query;
const params: any[] = whereQuery.params;
const params = whereQuery.params.concat(skip, first);

let orderBy = args.orderBy || 'created';
let orderDirection = args.orderDirection || 'desc';
Expand All @@ -34,15 +35,13 @@ export default async function (parent, args) {
spaces.turbo as spaceTurbo,
spaces.hibernated as spaceHibernated
FROM follows f
INNER JOIN spaces ON spaces.id = f.space
WHERE spaces.settings IS NOT NULL ${queryStr}
LEFT JOIN spaces ON spaces.id = f.space
WHERE 1=1 ${queryStr}
ORDER BY ${orderBy} ${orderDirection} LIMIT ?, ?
`;
params.push(skip, first);

let follows: any[] = [];
try {
follows = await db.queryAsync(query, params);
const follows = await db.queryAsync(query, params);
return follows.map(follow => formatFollow(follow));
} catch (e: any) {
log.error(`[graphql] follows, ${JSON.stringify(e)}`);
Expand Down
3 changes: 3 additions & 0 deletions src/graphql/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ input FollowWhere {
follower_in: [String]
space: String
space_in: [String]
network: String
network_in: [String]
created: Int
created_in: [Int]
created_gt: Int
Expand Down Expand Up @@ -504,6 +506,7 @@ type Follow {
ipfs: String
follower: String!
space: Space!
network: String!
created: Int!
}

Expand Down
5 changes: 4 additions & 1 deletion src/helpers/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,12 @@ CREATE TABLE follows (
ipfs VARCHAR(64) NOT NULL,
follower VARCHAR(64) NOT NULL,
space VARCHAR(64) NOT NULL,
network VARCHAR(24) NOT NULL DEFAULT 's',
created INT(11) NOT NULL,
PRIMARY KEY (follower, space),
PRIMARY KEY (follower, space, network),
INDEX ipfs (ipfs),
INDEX space (space),
INDEX network (network),
INDEX created (created)
);

Expand Down

0 comments on commit 38170cb

Please sign in to comment.