Skip to content

Commit 752e009

Browse files
committed
Convert REST API for Analysis CRUD to GraphQL mutation
1 parent a9d342d commit 752e009

File tree

3 files changed

+122
-5
lines changed

3 files changed

+122
-5
lines changed

apps/analysis/mutation.py

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
generate_input_type_for_serializer,
55
PsGrapheneMutation,
66
PsDeleteMutation,
7+
PsBulkGrapheneMutation,
8+
)
9+
from deep.permissions import (
10+
ProjectPermissions as PP,
11+
IsProjectMember,
712
)
8-
from deep.permissions import ProjectPermissions as PP
9-
1013
from .models import (
1114
AnalysisPillar,
1215
DiscardedEntry,
@@ -17,6 +20,7 @@
1720
AnalysisReport,
1821
AnalysisReportUpload,
1922
AnalysisReportSnapshot,
23+
Analysis,
2024
)
2125
from .schema import (
2226
get_analysis_pillar_qs,
@@ -31,6 +35,7 @@
3135
AnalysisReportType,
3236
AnalysisReportUploadType,
3337
AnalysisReportSnapshotType,
38+
AnalysisType,
3439
)
3540
from .serializers import (
3641
AnalysisPillarGqlSerializer,
@@ -42,6 +47,7 @@
4247
AnalysisReportSerializer,
4348
AnalysisReportSnapshotSerializer,
4449
AnalysisReportUploadSerializer,
50+
AnalysisGqlSerializer,
4551
)
4652

4753

@@ -84,7 +90,7 @@
8490
)
8591

8692

87-
# Analysi Report
93+
# Analysis Report
8894
AnalysisReportInputType = generate_input_type_for_serializer(
8995
'AnalysisReportInputType',
9096
serializer_class=AnalysisReportSerializer,
@@ -105,6 +111,11 @@
105111
serializer_class=AnalysisReportUploadSerializer,
106112
)
107113

114+
AnalysisInputType = generate_input_type_for_serializer(
115+
'AnalysisInputType',
116+
serializer_class=AnalysisGqlSerializer,
117+
)
118+
108119

109120
class RequiredPermissionMixin():
110121
permissions = [
@@ -269,6 +280,46 @@ class Arguments:
269280
result = graphene.Field(AnalysisReportUploadType)
270281

271282

283+
class CreateAnalysis(RequiredPermissionMixin, PsGrapheneMutation):
284+
class Arguments:
285+
data = AnalysisInputType(required=True)
286+
model = Analysis
287+
serializer_class = AnalysisGqlSerializer
288+
result = graphene.Field(AnalysisType)
289+
290+
291+
class UpdateAnalysis(RequiredPermissionMixin, PsGrapheneMutation):
292+
class Arguments:
293+
data = AnalysisInputType(required=True)
294+
id = graphene.ID(required=True)
295+
model = Analysis
296+
serializer_class = AnalysisGqlSerializer
297+
result = graphene.Field(AnalysisType)
298+
299+
300+
class DeleteAnalysis(RequiredPermissionMixin, PsDeleteMutation):
301+
class Arguments:
302+
id = graphene.ID(required=True)
303+
model = Analysis
304+
result = graphene.Field(AnalysisType)
305+
306+
307+
class BulkAnalysisInputType(AnalysisInputType):
308+
id = graphene.ID()
309+
310+
311+
class BulkAnalysis(PsBulkGrapheneMutation):
312+
class Arguments:
313+
items = graphene.List(graphene.NonNull(BulkAnalysisInputType))
314+
delete_ids = graphene.List(graphene.NonNull(graphene.ID))
315+
316+
result = graphene.List(AnalysisType)
317+
deleted_result = graphene.List(graphene.NonNull(AnalysisType))
318+
model = Analysis
319+
serializer_class = AnalysisGqlSerializer
320+
permissions = [IsProjectMember]
321+
322+
272323
class Mutation():
273324
# Analysis Pillar
274325
analysis_pillar_update = UpdateAnalysisPillar.Field()
@@ -289,3 +340,8 @@ class Mutation():
289340
# -- Uploads
290341
analysis_report_upload_create = CreateAnalysisReportUpload.Field()
291342
analysis_report_upload_delete = DeleteAnalysisReportUpload.Field()
343+
# Analysis
344+
analysis_create = CreateAnalysis.Field()
345+
analysis_update = UpdateAnalysis.Field()
346+
analysis_delete = DeleteAnalysis.Field()
347+
analysis_bulk = BulkAnalysis.Field()

apps/analysis/serializers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def validate(self, data):
409409
return data
410410

411411

412-
class AnalysisGqlSerializer(UserResourceSerializer):
412+
class AnalysisGqlSerializer(UserResourceSerializer, ProjectPropertySerializerMixin):
413413
id = IntegerIDField(required=False)
414414
analysis_pillar = AnalysisPillarGqlSerializer(many=True, source='analysispillar_set', required=False)
415415
start_date = serializers.DateField(required=False, allow_null=True)
@@ -420,10 +420,10 @@ class Meta:
420420
'id',
421421
'title',
422422
'team_lead',
423-
'project',
424423
'start_date',
425424
'end_date',
426425
'cloned_from',
426+
'analysis_pillar',
427427
)
428428

429429
def validate_project(self, project):
@@ -432,6 +432,7 @@ def validate_project(self, project):
432432
return project
433433

434434
def validate(self, data):
435+
data['project'] = self.project
435436
start_date = data.get('start_date')
436437
end_date = data.get('end_date')
437438
if start_date and start_date > end_date:

schema.graphql

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,16 @@ type AnalysisFrameworkVisibleProjectType {
260260
isPrivate: Boolean!
261261
}
262262

263+
input AnalysisInputType {
264+
id: ID
265+
title: String!
266+
teamLead: ID!
267+
startDate: Date
268+
endDate: Date!
269+
clonedFrom: ID
270+
analysisPillar: [AnalysisPillarGqlInputType!]
271+
}
272+
263273
type AnalysisListType {
264274
results: [AnalysisType!]
265275
totalCount: Int
@@ -304,6 +314,18 @@ type AnalysisPillarEntryListType {
304314
pageSize: Int
305315
}
306316

317+
input AnalysisPillarGqlInputType {
318+
title: String!
319+
mainStatement: String
320+
informationGap: String
321+
filters: GenericScalar
322+
assignee: ID!
323+
analysis: ID!
324+
clonedFrom: ID
325+
statements: [AnalyticalStatementGqlInputType!]
326+
clientId: String
327+
}
328+
307329
type AnalysisPillarListType {
308330
results: [AnalysisPillarType!]
309331
totalCount: Int
@@ -3258,13 +3280,29 @@ enum AutomaticSummaryStatusEnum {
32583280
SEND_FAILED
32593281
}
32603282

3283+
type BulkAnalysis {
3284+
errors: [[GenericScalar!]]
3285+
result: [AnalysisType]
3286+
deletedResult: [AnalysisType!]
3287+
}
3288+
32613289
input BulkAnalysisFrameworkMembershipInputType {
32623290
id: ID
32633291
member: ID!
32643292
role: ID
32653293
clientId: String
32663294
}
32673295

3296+
input BulkAnalysisInputType {
3297+
id: ID
3298+
title: String!
3299+
teamLead: ID!
3300+
startDate: Date
3301+
endDate: Date!
3302+
clonedFrom: ID
3303+
analysisPillar: [AnalysisPillarGqlInputType!]
3304+
}
3305+
32683306
type BulkEntry {
32693307
errors: [[GenericScalar!]]
32703308
result: [EntryType]
@@ -3535,6 +3573,12 @@ type ConnectorSourceType {
35353573
statusDisplay: EnumDescription!
35363574
}
35373575

3576+
type CreateAnalysis {
3577+
errors: [GenericScalar!]
3578+
ok: Boolean
3579+
result: AnalysisType
3580+
}
3581+
35383582
type CreateAnalysisFramework {
35393583
errors: [GenericScalar!]
35403584
ok: Boolean
@@ -3660,6 +3704,12 @@ scalar DateTime
36603704

36613705
scalar Decimal
36623706

3707+
type DeleteAnalysis {
3708+
errors: [GenericScalar!]
3709+
ok: Boolean
3710+
result: AnalysisType
3711+
}
3712+
36633713
type DeleteAnalysisPillarDiscardedEntry {
36643714
errors: [GenericScalar!]
36653715
ok: Boolean
@@ -5421,6 +5471,10 @@ type ProjectMutationType {
54215471
analysisReportSnapshotCreate(data: AnalysisReportSnapshotInputType!): CreateAnalysisReportSnapshot
54225472
analysisReportUploadCreate(data: AnalysisReportUploadInputType!): CreateAnalysisReportUpload
54235473
analysisReportUploadDelete(id: ID!): DeleteAnalysisReportUpload
5474+
analysisCreate(data: AnalysisInputType!): CreateAnalysis
5475+
analysisUpdate(data: AnalysisInputType!, id: ID!): UpdateAnalysis
5476+
analysisDelete(id: ID!): DeleteAnalysis
5477+
analysisBulk(deleteIds: [ID!], items: [BulkAnalysisInputType!]): BulkAnalysis
54245478
exportCreate(data: ExportCreateInputType!): CreateUserExport
54255479
exportUpdate(data: ExportUpdateInputType!, id: ID!): UpdateUserExport
54265480
exportCancel(id: ID!): CancelUserExport
@@ -6301,6 +6355,12 @@ input UnifiedConnectorWithSourceInputType {
63016355
sources: [ConnectorSourceGqInputType!]
63026356
}
63036357

6358+
type UpdateAnalysis {
6359+
errors: [GenericScalar!]
6360+
ok: Boolean
6361+
result: AnalysisType
6362+
}
6363+
63046364
type UpdateAnalysisFramework {
63056365
errors: [GenericScalar!]
63066366
ok: Boolean

0 commit comments

Comments
 (0)