From 12c3d9bf6c963fadce6ad9acdfc341f09c56ee8e Mon Sep 17 00:00:00 2001 From: Maximilian Csuk Date: Mon, 23 Oct 2023 11:29:44 +0200 Subject: [PATCH] Improved createCIs graphql interface: make name optional and allow specifying ciid --- backend/Omnikeeper/GraphQL/GraphQLMutation.cs | 16 ++++++++++++---- backend/Omnikeeper/GraphQL/Types/InputTypes.cs | 10 ++++++---- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/backend/Omnikeeper/GraphQL/GraphQLMutation.cs b/backend/Omnikeeper/GraphQL/GraphQLMutation.cs index 76224211..259999d7 100644 --- a/backend/Omnikeeper/GraphQL/GraphQLMutation.cs +++ b/backend/Omnikeeper/GraphQL/GraphQLMutation.cs @@ -158,8 +158,7 @@ public GraphQLMutation(ICIModel ciModel, IAttributeModel attributeModel, IRelati var userContext = context.GetUserContext(); - - var layers = createCIs.Select(ci => ci.LayerIDForName); + var layers = createCIs.Select(ci => ci.LayerIDForName).Where(layerID => layerID != null).Cast().ToHashSet(); // TODO: this is not ideal; we should split up writes to multiple layers better foreach (var layer in layers) if (await authzFilterManager.ApplyPreFilterForMutation(new PreCreateContextForCIs(), userContext.User, layer, layer, userContext.Transaction, userContext.GetTimeThreshold(context.Path)) is AuthzFilterResultDeny d) @@ -171,9 +170,18 @@ public GraphQLMutation(ICIModel ciModel, IAttributeModel attributeModel, IRelati var createdCIIDs = new List(); foreach (var ci in createCIs) { - Guid ciid = await ciModel.CreateCI(userContext.Transaction); + Guid? inputCIID = ci.CIID; + Guid ciid; + if (inputCIID.HasValue) + { + ciid = await ciModel.CreateCI(inputCIID.Value, userContext.Transaction); + } else + { + ciid = await ciModel.CreateCI(userContext.Transaction); + } - await attributeModel.InsertCINameAttribute(ci.Name, ciid, ci.LayerIDForName, userContext.ChangesetProxy, userContext.Transaction, otherLayersValueHandling); + if (ci.Name != null && ci.LayerIDForName != null) + await attributeModel.InsertCINameAttribute(ci.Name, ciid, ci.LayerIDForName, userContext.ChangesetProxy, userContext.Transaction, otherLayersValueHandling); createdCIIDs.Add(ciid); } diff --git a/backend/Omnikeeper/GraphQL/Types/InputTypes.cs b/backend/Omnikeeper/GraphQL/Types/InputTypes.cs index fb3a67d4..36652810 100644 --- a/backend/Omnikeeper/GraphQL/Types/InputTypes.cs +++ b/backend/Omnikeeper/GraphQL/Types/InputTypes.cs @@ -8,15 +8,17 @@ namespace Omnikeeper.GraphQL.Types { public class CreateCIInput { - public string Name { get; private set; } - public string LayerIDForName { get; private set; } + public Guid? CIID { get; private set; } + public string? Name { get; private set; } + public string? LayerIDForName { get; private set; } } public class CreateCIInputType : InputObjectGraphType { public CreateCIInputType() { - Field(x => x.Name); - Field(x => x.LayerIDForName); + Field("ciid", x => x.CIID, type: typeof(GuidGraphType)); + Field(x => x.Name, nullable: true); + Field(x => x.LayerIDForName, nullable: true); } }