Skip to content

Added Required Queries #3360

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

Merged
merged 21 commits into from
Mar 14, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
1 change: 0 additions & 1 deletion .coderabbit.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ reviews:
high_level_summary: true
review_status: true
collapse_walkthrough: false
request_changes_workflow: true
auto_review:
enabled: true
drafts: false
Expand Down
13 changes: 9 additions & 4 deletions src/graphql/types/Query/organizations.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { InferSelectModel } from "drizzle-orm";
import { ilike, sql } from "drizzle-orm";
import type { organizationsTable } from "~/src/drizzle/schema";
import { builder } from "~/src/graphql/builder";
import { Organization } from "~/src/graphql/types/Organization/Organization";
Expand All @@ -9,13 +10,17 @@ type OrganizationType = InferSelectModel<typeof organizationsTable>;
builder.queryField("organizations", (t) =>
t.field({
description:
"Query to fetch all organizations. Returns up to 20 organizations.",

resolve: async (_parent, args, ctx): Promise<OrganizationType[]> => {
"Query to fetch all organizations with optional filtering. Returns up to 20 organizations.",
args: {
filter: t.arg.string({ required: false }),
},
resolve: async (_parent, { filter }, ctx): Promise<OrganizationType[]> => {
try {
// Fetch organizations (limit 20)
// Fetch organizations with optional filtering
const organizations =
await ctx.drizzleClient.query.organizationsTable.findMany({
where: (fields) =>
filter ? ilike(fields.name, `%${filter}%`) : sql`TRUE`,
limit: 20,
});

Expand Down
24 changes: 24 additions & 0 deletions src/graphql/types/User/createdOrganizations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { and, ilike, sql } from "drizzle-orm";
import { Organization } from "~/src/graphql/types/Organization/Organization";
import { User } from "~/src/graphql/types/User/User";

User.implement({
fields: (t) => ({
createdOrganizations: t.field({
type: [Organization],
description: "Organizations created by the user",
args: {
filter: t.arg.string({ required: false }),
},
resolve: async (parent, { filter }, ctx) => {
return await ctx.drizzleClient.query.organizationsTable.findMany({
where: (fields, operators) =>
and(
operators.eq(fields.creatorId, parent.id),
filter ? ilike(fields.name, `%${filter}%`) : sql`TRUE`,
),
});
},

Check warning on line 21 in src/graphql/types/User/createdOrganizations.ts

View check run for this annotation

Codecov / codecov/patch

src/graphql/types/User/createdOrganizations.ts#L14-L21

Added lines #L14 - L21 were not covered by tests
}),
}),
});
1 change: 1 addition & 0 deletions src/graphql/types/User/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ import "./state";
import "./updatedAt";
import "./updater";
import "./workPhoneNumber";
import "./createdOrganizations";
Loading
Loading