Skip to content

Commit 6bcbbc5

Browse files
authored
feat(api): Organization.projects and Projects.targets (#6812)
1 parent 7574cce commit 6bcbbc5

File tree

24 files changed

+255
-213
lines changed

24 files changed

+255
-213
lines changed

integration-tests/testkit/flow.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,12 @@ export function getOrganizationProjects(selector: OrganizationSelectorInput, aut
298298
query getOrganizationProjects($selector: OrganizationSelectorInput!) {
299299
organization(reference: { bySelector: $selector }) {
300300
projects {
301-
nodes {
302-
id
303-
slug
304-
name
301+
edges {
302+
node {
303+
id
304+
slug
305+
name
306+
}
305307
}
306308
}
307309
}

integration-tests/testkit/schema-policy.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ export const OrganizationAndProjectsWithSchemaPolicy = graphql(`
99
id
1010
}
1111
projects {
12-
nodes {
13-
id
14-
schemaPolicy {
12+
edges {
13+
node {
1514
id
15+
schemaPolicy {
16+
id
17+
}
1618
}
1719
}
1820
}

integration-tests/testkit/seed.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ export function initSeed() {
223223
token,
224224
).then(r => r.expectNoGraphQLErrors());
225225

226-
const projects = projectsResult.organization?.projects.nodes;
226+
const projects = projectsResult.organization?.projects.edges.map(edge => edge.node);
227227

228228
if (!projects) {
229229
throw new Error(`Could not get projects for org ${organization.slug}`);

integration-tests/tests/api/policy/policy-crud.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ describe('Policy CRUD', () => {
2828
}).then(r => r.expectNoGraphQLErrors());
2929

3030
expect(result.organization?.schemaPolicy).toBe(null);
31-
expect(result.organization?.projects.nodes).toHaveLength(1);
32-
expect(result.organization?.projects.nodes[0].schemaPolicy).toBeNull();
31+
expect(result.organization?.projects.edges).toHaveLength(1);
32+
expect(result.organization?.projects.edges[0].node.schemaPolicy).toBeNull();
3333
},
3434
);
3535

@@ -123,8 +123,8 @@ describe('Policy CRUD', () => {
123123
authToken: ownerToken,
124124
}).then(r => r.expectNoGraphQLErrors());
125125

126-
expect(result.organization?.projects.nodes).toHaveLength(1);
127-
expect(result.organization?.projects.nodes[0].schemaPolicy).toBeNull();
126+
expect(result.organization?.projects.edges).toHaveLength(1);
127+
expect(result.organization?.projects.edges[0].node.schemaPolicy).toBeNull();
128128
},
129129
);
130130

@@ -179,8 +179,8 @@ describe('Policy CRUD', () => {
179179
}).then(r => r.expectNoGraphQLErrors());
180180

181181
expect(result.organization?.schemaPolicy).toBe(null);
182-
expect(result.organization?.projects.nodes).toHaveLength(1);
183-
expect(result.organization?.projects.nodes[0].schemaPolicy).toBeNull();
182+
expect(result.organization?.projects.edges).toHaveLength(1);
183+
expect(result.organization?.projects.edges[0].node.schemaPolicy).toBeNull();
184184

185185
const upsertResult = await setOrganizationSchemaPolicy(VALID_POLICY, true);
186186

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import type { Project } from '../../shared/entities';
22

3-
export type ProjectConnectionMapper = readonly Project[];
43
export type ProjectMapper = Project;

packages/services/api/src/modules/project/module.graphql.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { gql } from 'graphql-modules';
33
export default gql`
44
extend type Query {
55
project(reference: ProjectReferenceInput! @tag(name: "public")): Project @tag(name: "public")
6-
projects(selector: OrganizationSelectorInput!): ProjectConnection!
76
}
87
98
extend type Mutation {
@@ -85,7 +84,7 @@ export default gql`
8584
}
8685
8786
extend type Organization {
88-
projects: ProjectConnection!
87+
projects: ProjectConnection! @tag(name: "public")
8988
viewerCanCreateProject: Boolean!
9089
projectBySlug(projectSlug: String!): Project
9190
}
@@ -122,9 +121,14 @@ export default gql`
122121
viewerCanDelete: Boolean!
123122
}
124123
124+
type ProjectEdge {
125+
node: Project! @tag(name: "public")
126+
cursor: String! @tag(name: "public")
127+
}
128+
125129
type ProjectConnection {
126-
nodes: [Project!]!
127-
total: Int!
130+
edges: [ProjectEdge!]! @tag(name: "public")
131+
pageInfo: PageInfo! @tag(name: "public")
128132
}
129133
130134
input CreateProjectInput {

packages/services/api/src/modules/project/resolvers/Organization.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,23 @@ export const Organization: Pick<
66
OrganizationResolvers,
77
'projectBySlug' | 'projects' | 'viewerCanCreateProject' | '__isTypeOf'
88
> = {
9-
projects: (organization, _, { injector }) => {
10-
return injector.get(ProjectManager).getProjects({ organizationId: organization.id });
9+
projects: async (organization, _, { injector }) => {
10+
const projects = await injector
11+
.get(ProjectManager)
12+
.getProjects({ organizationId: organization.id });
13+
14+
return {
15+
edges: projects.map(node => ({
16+
cursor: '',
17+
node,
18+
})),
19+
pageInfo: {
20+
hasNextPage: false,
21+
hasPreviousPage: false,
22+
endCursor: '',
23+
startCursor: '',
24+
},
25+
};
1126
},
1227
viewerCanCreateProject: async (organization, _arg, { injector }) => {
1328
return injector.get(Session).canPerformAction({

packages/services/api/src/modules/project/resolvers/ProjectConnection.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/services/api/src/modules/project/resolvers/Query/projects.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
import type { Target } from '../../shared/entities';
22

3-
export type TargetConnectionMapper = readonly Target[];
43
export type TargetMapper = Target;

0 commit comments

Comments
 (0)