Skip to content

Commit

Permalink
Improved createCIs graphql interface: make name optional and allow sp…
Browse files Browse the repository at this point in the history
…ecifying ciid
  • Loading branch information
maximiliancsuk committed Oct 23, 2023
1 parent 2c37f1d commit 12c3d9b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 12 additions & 4 deletions backend/Omnikeeper/GraphQL/GraphQLMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>().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)
Expand All @@ -171,9 +170,18 @@ public GraphQLMutation(ICIModel ciModel, IAttributeModel attributeModel, IRelati
var createdCIIDs = new List<Guid>();
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);
}
Expand Down
10 changes: 6 additions & 4 deletions backend/Omnikeeper/GraphQL/Types/InputTypes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Check warning on line 12 in backend/Omnikeeper/GraphQL/Types/InputTypes.cs

View workflow job for this annotation

GitHub Actions / Run backend tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 12 in backend/Omnikeeper/GraphQL/Types/InputTypes.cs

View workflow job for this annotation

GitHub Actions / Run backend performance tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
public string? LayerIDForName { get; private set; }

Check warning on line 13 in backend/Omnikeeper/GraphQL/Types/InputTypes.cs

View workflow job for this annotation

GitHub Actions / Run backend tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.

Check warning on line 13 in backend/Omnikeeper/GraphQL/Types/InputTypes.cs

View workflow job for this annotation

GitHub Actions / Run backend performance tests

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
}
public class CreateCIInputType : InputObjectGraphType<CreateCIInput>
{
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);
}
}

Expand Down

0 comments on commit 12c3d9b

Please sign in to comment.