Skip to content

[EdgeDB] Pin queries #3208

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d82be69
chore: add pinnable edgedb query
adam-soltech May 10, 2024
03125c1
Add /graphql to logged path for DX
CarsonF May 9, 2024
4292a6d
Remove the deprecated `version` from docker compose files
CarsonF May 9, 2024
e73bcae
Financial Approvers (#3206)
CarsonF May 9, 2024
cf457b4
Register story EdgeDB repository
May 6, 2024
918e6d5
Fix scripture verseId query types
May 6, 2024
9d17f3e
Update delete method to use repo.readOne
May 8, 2024
f257881
[EdgeDB] Film queries (#3185)
willdch May 9, 2024
1b559a8
[EdgeDB] EthnoArt queries (#3205)
willdch May 9, 2024
abfb1d0
Use FinancialApprovers instead of all Controllers for project workflow
May 9, 2024
32e8048
Add the project type to step changed notification
May 10, 2024
0f29097
Expose Partner.engagements (#3209)
rdonigian May 10, 2024
733b71d
Disable CI edgedb tests while I'm out
CarsonF May 10, 2024
65608a6
Adjust imports/exports
CarsonF Apr 4, 2024
10b4e47
Don't blame me
CarsonF May 20, 2024
2e87064
[Hotfix] Change `Promise.all` to `for await` in project status handle…
andrewmurraydavid May 16, 2024
6bb689c
Add primary partner name to project workflow notification (#3210)
atGit2021 May 21, 2024
661dfe1
Change config hostUrl to observable
CarsonF May 21, 2024
1433853
Update config hostUrl to reflect the current unix path in tests
CarsonF May 21, 2024
8d28850
Change local file bucket GET to use idiomatic Nestjs abstraction
CarsonF May 22, 2024
2731c01
Fix tests to generate correct fake file size based on content
CarsonF May 22, 2024
507be09
Update tests to use real file url requests (actually e2e)
CarsonF May 21, 2024
5492495
Switch tests to use new file urls
CarsonF Jan 24, 2024
026a699
Drop deprecated short-lived downloadUrl field (#3061)
CarsonF May 22, 2024
b1348f7
[EdgeDB] Add Pins Seeding (#3212)
bryanjnelson May 22, 2024
d3168cb
chore: add pinnable edgedb query
adam-soltech May 10, 2024
ee8ac45
refactor: tested working queries for pinning
adam-soltech May 29, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/components/pin/dto/pinnable.dto.ts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't needed since Pinnable isn't a Resource.

Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Field, InterfaceType } from '@nestjs/graphql';
import { keys } from 'ts-transformer-keys';
import { ID, IdField } from '../../../common';

@InterfaceType({
description: 'An item that can be pinned',
})
export class Pinnable {
static readonly Props = keys<Pinnable>();
static readonly SecuredProps = keys<Pinnable>();

@IdField()
readonly id: ID;

Expand Down
83 changes: 83 additions & 0 deletions src/components/pin/pin.edgedb.repository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import { Inject, Injectable } from '@nestjs/common';
import { DateTime } from 'luxon';
import { ID, PublicOf, Session } from '~/common';
import { Client } from '~/core/edgedb';
import { PinRepository } from './pin.repository';

@Injectable()
export class PinEdgeDBRepository implements PublicOf<PinRepository> {
constructor(@Inject(Client) private readonly client: Client) {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export class PinEdgeDBRepository implements PublicOf<PinRepository> {
constructor(@Inject(Client) private readonly client: Client) {}
export class PinEdgeDBRepository
extends CommonRepository
implements PublicOf<PinRepository> {


async isPinned(id: ID, session: Session): Promise<boolean> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@CarsonF - Since the schema itself defines a pinned property that is automatically inherited by any type that implements the Pinnable abstract type, doesn't that make this isPinned method unneeded in the EdgeDB world?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The pinned property is a computed shortcut.
User.pins holds the links for the Pinnable objects that user has pinned.
So this could query cast the ID to the Pinnable instance and then check the pinned property on it.
That uses the current user global which has already been connected in the app code in another layer.

select (<Pinnable><uuid>$id).pinned

Or

with obj := <Pinnable><uuid>$id
select obj.pinned

const res: boolean | null = await this.client.querySingle(
`
select exists(
select BaseNode {
id,
pinned_by := .<pinned[is User]> {
id
}
}
filter .id = <uuid>$id
and .pinned_by.id = <uuid>$userId
);
`,
{
id,
userId: session.userId,
},
);

return Boolean(res);
}

async add(id: ID, session: Session): Promise<void> {
const createdAt = DateTime.local();

await this.client.query(
`
with BaseNode := (
select BaseNode
filter .id = <uuid>$id
),
User := (
select User
filter .id = <uuid>$userId
)
insert PinnedRelation {
node := BaseNode,
user := User,
createdAt := <datetime>$createdAt
}
unless conflict on (.node, .user)
`,
{
id,
userId: session.userId,
createdAt: createdAt.toJSDate(),
},
);
}

async remove(id: ID, session: Session): Promise<void> {
await this.client.query(
`
with BaseNode := (
select BaseNode
filter .id = <uuid>$id
),
User := (
select User
filter .id = <uuid>$userId
)
delete PinnedRelation
filter .node = BaseNode
and .user = User
`,
{
id,
userId: session.userId,
},
);
}
}
8 changes: 7 additions & 1 deletion src/components/pin/pin.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import { Module } from '@nestjs/common';
import { splitDb } from '~/core';
import { PinEdgeDBRepository } from './pin.edgedb.repository';
import { PinRepository } from './pin.repository';
import { PinResolver } from './pin.resolver';
import { PinService } from './pin.service';

@Module({
providers: [PinResolver, PinService, PinRepository],
providers: [
PinResolver,
PinService,
splitDb(PinRepository, PinEdgeDBRepository),
],
exports: [PinService],
})
export class PinModule {}
Loading