Skip to content

Commit ed82b43

Browse files
authored
add: enable osograph codegen build (#5512)
* chore: remove explicit `cast` * chore: add `missing` field mappings * chore: run `codegen` scripts * add: enable `osograph` codegen build
1 parent 80693c1 commit ed82b43

File tree

8 files changed

+273
-20
lines changed

8 files changed

+273
-20
lines changed

apps/frontend/app/api/v1/osograph/schema/resolvers/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const dateTimeScalar = new GraphQLScalarType({
3232
},
3333
});
3434

35-
export const resolvers = {
35+
export const resolvers: GraphQLResolverMap<GraphQLContext> = {
3636
DateTime: dateTimeScalar,
3737
Query: {
3838
...userResolvers.Query,
@@ -48,4 +48,4 @@ export const resolvers = {
4848
Organization: organizationResolvers.Organization,
4949
OrganizationMember: memberResolvers.OrganizationMember,
5050
Invitation: invitationResolvers.Invitation,
51-
} as GraphQLResolverMap<GraphQLContext>;
51+
};

apps/frontend/app/api/v1/osograph/schema/resolvers/invitation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { v4 as uuid4 } from "uuid";
22
import { createAdminClient } from "@/lib/supabase/admin";
33
import { sendInvitationEmail } from "@/lib/services/email";
44
import { logger } from "@/lib/logger";
5-
import type { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap";
5+
import type { GraphQLResolverModule } from "@/app/api/v1/osograph/utils/types";
66
import {
77
requireAuthentication,
88
requireOrgMembership,
@@ -23,7 +23,7 @@ import {
2323
ServerErrors,
2424
} from "@/app/api/v1/osograph/utils/errors";
2525

26-
export const invitationResolvers: GraphQLResolverMap<GraphQLContext> = {
26+
export const invitationResolvers: GraphQLResolverModule<GraphQLContext> = {
2727
Query: {
2828
osoApp_invitation: async (
2929
_: unknown,

apps/frontend/app/api/v1/osograph/schema/resolvers/member.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAdminClient } from "@/lib/supabase/admin";
2-
import type { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap";
2+
import type { GraphQLResolverModule } from "@/app/api/v1/osograph/utils/types";
33
import {
44
requireAuthentication,
55
requireOrgMembership,
@@ -22,7 +22,7 @@ import {
2222
ErrorCode,
2323
} from "@/app/api/v1/osograph/utils/errors";
2424

25-
export const memberResolvers: GraphQLResolverMap<GraphQLContext> = {
25+
export const memberResolvers: GraphQLResolverModule<GraphQLContext> = {
2626
OrganizationMember: {
2727
__resolveReference: async (reference: { id: string }) => {
2828
const supabase = createAdminClient();

apps/frontend/app/api/v1/osograph/schema/resolvers/organization.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createAdminClient } from "@/lib/supabase/admin";
2-
import type { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap";
2+
import type { GraphQLResolverModule } from "@/app/api/v1/osograph/utils/types";
33
import {
44
requireAuthentication,
55
requireOrgMembership,
@@ -8,7 +8,7 @@ import {
88
type GraphQLContext,
99
} from "@/app/api/v1/osograph/utils/auth";
1010

11-
export const organizationResolvers: GraphQLResolverMap<GraphQLContext> = {
11+
export const organizationResolvers: GraphQLResolverModule<GraphQLContext> = {
1212
Query: {
1313
osoApp_organization: async (
1414
_: unknown,
@@ -27,6 +27,9 @@ export const organizationResolvers: GraphQLResolverMap<GraphQLContext> = {
2727
return getOrganization(reference.id);
2828
},
2929

30+
orgName: (parent: { org_name: string }) => parent.org_name,
31+
createdAt: (parent: { created_at: string }) => parent.created_at,
32+
3033
members: async (
3134
parent: { id: string },
3235
_args: unknown,

apps/frontend/app/api/v1/osograph/schema/resolvers/user.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { createAdminClient } from "@/lib/supabase/admin";
2-
import type { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap";
2+
import type { GraphQLResolverModule } from "@/app/api/v1/osograph/utils/types";
33
import {
44
getUserProfile,
55
requireAuthentication,
66
type GraphQLContext,
77
} from "@/app/api/v1/osograph/utils/auth";
88
import { UserErrors, ServerErrors } from "@/app/api/v1/osograph/utils/errors";
99

10-
export const userResolvers: GraphQLResolverMap<GraphQLContext> = {
10+
export const userResolvers: GraphQLResolverModule<GraphQLContext> = {
1111
Query: {
1212
osoApp_me: async (_: unknown, _args: unknown, context: GraphQLContext) => {
1313
const authenticatedUser = requireAuthentication(context.user);
@@ -64,6 +64,9 @@ export const userResolvers: GraphQLResolverMap<GraphQLContext> = {
6464
return getUserProfile(reference.id);
6565
},
6666

67+
fullName: (parent: { full_name: string | null }) => parent.full_name,
68+
avatarUrl: (parent: { avatar_url: string | null }) => parent.avatar_url,
69+
6770
organizations: async (
6871
parent: { id: string },
6972
_args: unknown,
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { GraphQLScalarType } from "graphql";
2+
import type { GraphQLResolverMap } from "@apollo/subgraph/dist/schema-helper/resolverMap";
3+
4+
/**
5+
* Helper type to determine if a resolver map value is a resolver object
6+
* (i.e., not a scalar or enum).
7+
*/
8+
type IsResolverObject<T> = T extends GraphQLScalarType
9+
? never
10+
: T extends { [key: string]: string | number }
11+
? T extends { [key: string]: (...args: never[]) => unknown }
12+
? T
13+
: never
14+
: T;
15+
16+
/**
17+
* Type for partial GraphQL resolver modules.
18+
* This is the same as `GraphQLResolverMap` but excludes `scalars` and `enums`,
19+
* so it only allows resolver objects (`Query`, `Mutation`, and type resolvers).
20+
*/
21+
export type GraphQLResolverModule<TContext = unknown> = {
22+
[typeName: string]: IsResolverObject<GraphQLResolverMap<TContext>[string]>;
23+
};

apps/frontend/lib/graphql/codegen.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
import { CodegenConfig } from "@graphql-codegen/cli";
22
import {
33
DAGSTER_GRAPHQL_URL,
4-
// DOMAIN,
4+
DOMAIN,
55
HASURA_URL,
66
OSO_API_KEY,
77
} from "@/lib/config";
88

9-
// const PROTOCOL = DOMAIN.includes("localhost") ? "http" : "https";
10-
// const OSO_GRAPH_URL = new URL(
11-
// "/api/v1/osograph",
12-
// `${PROTOCOL}://${DOMAIN}`,
13-
// ).toString();
9+
const PROTOCOL = DOMAIN.includes("localhost") ? "http" : "https";
10+
const OSO_GRAPH_URL = new URL(
11+
"/api/v1/osograph",
12+
`${PROTOCOL}://${DOMAIN}`,
13+
).toString();
1414

1515
const SCHEMA: Record<string, any> = {};
1616
SCHEMA[HASURA_URL] = {
@@ -19,10 +19,7 @@ SCHEMA[HASURA_URL] = {
1919
},
2020
};
2121
SCHEMA[DAGSTER_GRAPHQL_URL] = {};
22-
// TODO(jabolo): Enable this when oso graph is in production
23-
// so introspection does not fail (the endpoint is not accessible
24-
// until we merge into main for the first time).
25-
// SCHEMA[OSO_GRAPH_URL] = {};
22+
SCHEMA[OSO_GRAPH_URL] = {};
2623
const config: CodegenConfig = {
2724
schema: SCHEMA,
2825
documents: [

0 commit comments

Comments
 (0)