From 67b7d5e3500b2a2d8e62f3f9689996cef3c039ae Mon Sep 17 00:00:00 2001 From: Morten Vestergaard Hansen Date: Thu, 30 Mar 2023 14:47:35 +0200 Subject: [PATCH] Update permission description via grapql (#1594) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Mutation for permission * update permission2 * Update permission via graphql * Update schema --------- Co-authored-by: Bjørn Hoffmann Co-authored-by: Bjørn Hoffmann --- .../DataHub.WebApi/GraphQL/GraphQLMutation.cs | 39 +++++++++++++++++++ .../DataHub.WebApi/GraphQL/GraphQLQuery.cs | 6 +-- .../DataHub.WebApi/GraphQL/GraphQLSchema.cs | 1 + .../Types/UpdatePermissionInputType.cs | 29 ++++++++++++++ .../domain/src/lib/generated/graphql.ts | 17 ++++++++ schema.graphql | 16 ++++++++ 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLMutation.cs create mode 100644 apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/UpdatePermissionInputType.cs diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLMutation.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLMutation.cs new file mode 100644 index 0000000000..0f3c962fad --- /dev/null +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLMutation.cs @@ -0,0 +1,39 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +using Energinet.DataHub.MarketParticipant.Client; +using Energinet.DataHub.MarketParticipant.Client.Models; +using GraphQL; +using GraphQL.MicrosoftDI; +using GraphQL.Types; + +namespace Energinet.DataHub.WebApi.GraphQL +{ + public class GraphQLMutation : ObjectGraphType + { + public GraphQLMutation() + { + Field>("permission") + .Argument>("permission", "Permission to update") + .Resolve() + .WithScope() + .WithService() + .ResolveAsync(async (context, client) => + { + var updatePermissionDto = context.GetArgument("permission"); + await client.UpdatePermissionAsync(updatePermissionDto); + return await client.GetPermissionAsync(updatePermissionDto.Id); + }); + } + } +} diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs index 5dd47dc347..835c485331 100644 --- a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs @@ -37,11 +37,7 @@ public GraphQLQuery() .Resolve() .WithScope() .WithService() - .ResolveAsync(async (context, client) => - { - var id = context.GetArgument("id"); - return await client.GetPermissionAsync(id); - }); + .ResolveAsync(async (context, client) => await client.GetPermissionAsync(context.GetArgument("id"))); Field>>>("permissions") .Resolve() diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLSchema.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLSchema.cs index 743b138f70..6eb7a83536 100644 --- a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLSchema.cs +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLSchema.cs @@ -45,6 +45,7 @@ public GraphQLSchema(IServiceProvider provider) this.RegisterTypeMapping(); Query = provider.GetRequiredService(); + Mutation = provider.GetRequiredService(); } } } diff --git a/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/UpdatePermissionInputType.cs b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/UpdatePermissionInputType.cs new file mode 100644 index 0000000000..875e1b8f64 --- /dev/null +++ b/apps/dh/api-dh/source/DataHub.WebApi/GraphQL/Types/UpdatePermissionInputType.cs @@ -0,0 +1,29 @@ +// Copyright 2020 Energinet DataHub A/S +// +// Licensed under the Apache License, Version 2.0 (the "License2"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using Energinet.DataHub.MarketParticipant.Client.Models; +using GraphQL.Types; + +namespace Energinet.DataHub.WebApi.GraphQL +{ + public class UpdatePermissionInputType : InputObjectGraphType + { + public UpdatePermissionInputType() + { + Name = "UpdatePermissionInput"; + Field(x => x.Id).Description("The id of the permission to update"); + Field(x => x.Description).Description("The description of the permission to update"); + } + } +} diff --git a/libs/dh/shared/domain/src/lib/generated/graphql.ts b/libs/dh/shared/domain/src/lib/generated/graphql.ts index a135a9b179..0c72730475 100644 --- a/libs/dh/shared/domain/src/lib/generated/graphql.ts +++ b/libs/dh/shared/domain/src/lib/generated/graphql.ts @@ -85,6 +85,16 @@ export enum EicFunction { SystemOperator = 'SYSTEM_OPERATOR' } +export type GraphQlMutation = { + __typename?: 'GraphQLMutation'; + permission: Permission; +}; + + +export type GraphQlMutationPermissionArgs = { + permission: UpdatePermissionInput; +}; + export type GraphQlQuery = { __typename?: 'GraphQLQuery'; actors: Array; @@ -279,6 +289,13 @@ export enum TimeSeriesType { Production = 'PRODUCTION' } +export type UpdatePermissionInput = { + /** The description of the permission to update */ + description: Scalars['String']; + /** The id of the permission to update */ + id: Scalars['Int']; +}; + export type UserRole = { __typename?: 'UserRole'; /** The user role description */ diff --git a/schema.graphql b/schema.graphql index 611efeb7de..128a70ca68 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,5 +1,6 @@ schema { query: GraphQLQuery + mutation: GraphQLMutation } type Actor { @@ -86,6 +87,13 @@ enum EicFunction { SYSTEM_OPERATOR } +type GraphQLMutation { + permission( + """Permission to update""" + permission: UpdatePermissionInput! + ): Permission! +} + type GraphQLQuery { actors: [Actor!]! batch( @@ -268,6 +276,14 @@ enum TimeSeriesType { PRODUCTION } +input UpdatePermissionInput { + """The description of the permission to update""" + description: String! + + """The id of the permission to update""" + id: Int! +} + type UserRole { """The user role description""" description: String!