Skip to content

Commit 449a5b2

Browse files
committed
Fix schema check permission for proposal; fix other minor todos
1 parent aeafb16 commit 449a5b2

5 files changed

Lines changed: 41 additions & 31 deletions

File tree

packages/services/api/src/modules/proposals/providers/schema-proposal-storage.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,16 +130,16 @@ export class SchemaProposalStorage {
130130
);
131131

132132
const row = await conn.maybeOne(psql`
133-
INSERT INTO schema_proposal_reviews
134-
("schema_proposal_id", "stage_transition", "author", "service_name")
135-
VALUES (
136-
${args.id}
137-
, ${args.stage}
138-
, ${args.author}
139-
, ${args.serviceName}
140-
)
141-
RETURNING ${schemaProposalReviewFields}
142-
`);
133+
INSERT INTO schema_proposal_reviews
134+
("schema_proposal_id", "stage_transition", "author", "service_name")
135+
VALUES (
136+
${args.id}
137+
, ${args.stage}
138+
, ${args.author}
139+
, ${args.serviceName}
140+
)
141+
RETURNING ${schemaProposalReviewFields}
142+
`);
143143
return SchemaProposalReviewModel.parse(row);
144144
});
145145

@@ -395,7 +395,7 @@ export class SchemaProposalStorage {
395395
) {
396396
const values = records.map(
397397
r => psql`(
398-
${generateChangeHash(r.change)},
398+
${generateChangeHash(r.change)}
399399
,${JSON.stringify(r.change)}
400400
,${r.proposalId}
401401
,${r.service ?? null}

packages/services/api/src/modules/proposals/resolvers/SchemaProposalChangeDetails.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export const SchemaProposalChangeDetails: SchemaProposalChangeDetailsResolvers =
1717
.getProposal({ id: schemaProposalId });
1818

1919
if (!proposal) {
20-
throw new Error('Something went wrong!');
20+
throw new Error('Proposal not found');
2121
}
2222
const ref = await injector
2323
.get(IdTranslator)

packages/services/api/src/modules/schema/providers/registry-checks.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { URL } from 'node:url';
22
import { type GraphQLSchema } from 'graphql';
33
import { Injectable, Scope } from 'graphql-modules';
44
import hashObject from 'object-hash';
5-
import { generateChangeHash } from '@graphql-inspector/compare-changes';
65
import { ChangeType, CriticalityLevel, DiffRule, TypeOfChangeType } from '@graphql-inspector/core';
76
import type { CheckPolicyResponse } from '@hive/policy';
87
import type { CompositionFailureError, ContractsInputType } from '@hive/schema';
@@ -737,18 +736,6 @@ export class RegistryChecks {
737736
);
738737
}
739738

740-
const test = await Promise.all(
741-
inspectorChanges.map(async change => {
742-
const hash = generateChangeHash(
743-
change as unknown as Parameters<typeof generateChangeHash>[0],
744-
);
745-
// @todo batch lookup based on hashes
746-
return hash;
747-
}),
748-
);
749-
// @todo
750-
console.log(JSON.stringify(test));
751-
752739
let isFailure = false;
753740
const safeChanges: Array<SchemaChangeType> = [];
754741
const breakingChanges: Array<SchemaChangeType> = [];

packages/services/api/src/modules/schema/providers/schema-publisher.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -687,10 +687,6 @@ export class SchemaPublisher {
687687
}
688688
}
689689

690-
// The check is where the changes are determined... Should this also be where
691-
// it's associated proposal is found?...
692-
// While I don't love this, it does make returning the change record nicer.
693-
// @todo
694690
checkResult = await this.models[project.type].check({
695691
input: {
696692
sdl,

packages/services/api/src/modules/schema/resolvers/Mutation/schemaCheck.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,43 @@
1+
import { HiveError } from '../../../../shared/errors';
2+
import { SchemaProposalManager } from '../../../proposals/providers/schema-proposal-manager';
3+
import { IdTranslator } from '../../../shared/providers/id-translator';
14
import { SchemaPublisher } from '../../providers/schema-publisher';
25
import type { MutationResolvers } from './../../../../__generated__/types';
36

47
export const schemaCheck: NonNullable<MutationResolvers['schemaCheck']> = async (
58
_,
69
{ input },
7-
{ injector },
10+
{ injector, session },
811
) => {
12+
if (typeof input.schemaProposalId === 'string') {
13+
const selector = await injector
14+
.get(IdTranslator)
15+
.resolveTargetReference({ reference: input.target ?? null });
16+
17+
if (selector?.targetId) {
18+
await session.assertPerformAction({
19+
action: 'schemaProposal:modify',
20+
organizationId: selector.organizationId,
21+
params: {
22+
organizationId: selector.organizationId,
23+
projectId: selector.projectId,
24+
targetId: selector.targetId,
25+
},
26+
});
27+
const proposal = await injector
28+
.get(SchemaProposalManager)
29+
.getProposal({ id: input.schemaProposalId });
30+
if (proposal?.targetId !== selector?.targetId) {
31+
throw new HiveError('Proposal not found');
32+
}
33+
}
34+
}
35+
936
const result = await injector.get(SchemaPublisher).check({
1037
...input,
1138
service: input.service?.toLowerCase(),
1239
target: input.target ?? null,
13-
schemaProposalId: input.schemaProposalId, // @todo check permission
40+
schemaProposalId: input.schemaProposalId,
1441
});
1542

1643
if ('changes' in result) {

0 commit comments

Comments
 (0)