Skip to content
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

feat(apps/gql): handle upvote mutations better & add PanoPost.isUpvotedByViewer resolver #628

Merged
merged 9 commits into from
Aug 11, 2023

Conversation

usirin
Copy link
Member

@usirin usirin commented Aug 10, 2023

Adds a new simple wrapper around DataLoader so apps don't use it directly, which gives us a solid extension for the future.

Used this loader, it's not optimized by us, because we delegate it to prisma's own dataloader abstaction by using prisma.upvote.findUnique: https://www.prisma.io/docs/guides/performance-and-optimization/query-optimization-performance#solving-n1-in-graphql-with-findunique-and-prismas-dataloader

Checklist

  • discord username: umut
  • Closes feat(gql): add PanoPost.isUpvotedByViewer field #621
  • Closes feat(gql-utils): add support for multiple query identifiers #623
  • PR must be created for an issue from issues under "In progress" column from our project board.
  • A descriptive and understandable title: The PR title should clearly describe the nature and purpose of the changes. The PR title should be the first thing displayed when the PR is opened. And it should follow the semantic commit rules, and should include the app/package/service name in the title. For example, a title like "docs(@kampus-apps/pano): Add README.md" can be used.
  • Related file selection: Only relevant files should be touched and no other files should be affected.
  • I ran npx turbo run at the root of the repository, and build was successful.
  • I installed the npm packages using npm install --save-exact <package> so my package is pinned to a specific npm version. Leave empty if no package was installed. Leave empty if no package was installed with this PR.

How were these changes tested?

Please describe the tests you did to test the changes you made. Please also specify your test configuration.

@usirin usirin requested a review from a team as a code owner August 10, 2023 23:22
@vercel
Copy link

vercel bot commented Aug 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
kampus-gql ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 11, 2023 11:46pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
kampus-next ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2023 11:46pm
kampus-pasaport ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2023 11:46pm
kampus-ui ⬜️ Ignored (Inspect) Visit Preview Aug 11, 2023 11:46pm

Copy link
Member

@alicangunduz alicangunduz left a comment

Choose a reason for hiding this comment

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

💯

@usirin usirin changed the title Is upvoted by viewer feat(apps/gql): handle upvote mutations better & add PanoPost.isUpvotedByViewer resolver Aug 11, 2023
Copy link
Member

@rasitds rasitds left a comment

Choose a reason for hiding this comment

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

💯 lets goooooooooooooooooooo

return new DataLoader(async (keys: readonly TKey[]) => {
const result = (await batchFn(keys)) ?? [];

onComplete?.(result as unknown as TValue[]);
Copy link
Member Author

@usirin usirin Aug 11, 2023

Choose a reason for hiding this comment

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

@sevilayerkan let's add a test for this loader and cover this case, we can use prisma/create-loader-test.test.ts as an example

it("accepts an onComplete handler after prisma fetch is done", async () => {
mockedPrisma.user.findMany.mockResolvedValueOnce([
mockUser({ id: "1" }),
mockUser({ id: "2" }),
]);
const onComplete = vi.fn();
const byID = createPrismaLoader(mockedPrisma.user, "id", onComplete);
const result = await Promise.all([byID.load("1"), byID.load("2")]);
expect(onComplete).toHaveBeenCalledWith(result);
});

@usirin usirin merged commit f32f91a into dev Aug 11, 2023
2 checks passed
@usirin usirin deleted the is-upvoted-by-viewer branch August 11, 2023 23:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat(gql-utils): add support for multiple query identifiers feat(gql): add PanoPost.isUpvotedByViewer field
3 participants