Skip to content

Commit

Permalink
Update permission description via grapql (#1594)
Browse files Browse the repository at this point in the history
* Mutation for permission

* update permission2

* Update permission via graphql

* Update schema

---------

Co-authored-by: Bjørn Hoffmann <ManBearTM@users.noreply.github.com>
Co-authored-by: Bjørn Hoffmann <bjorn.id@bhoffmann.com>
  • Loading branch information
3 people authored Mar 30, 2023
1 parent afa1623 commit 67b7d5e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 5 deletions.
39 changes: 39 additions & 0 deletions apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLMutation.cs
Original file line number Diff line number Diff line change
@@ -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<NonNullGraphType<PermissionDtoType>>("permission")
.Argument<NonNullGraphType<UpdatePermissionInputType>>("permission", "Permission to update")
.Resolve()
.WithScope()
.WithService<IMarketParticipantPermissionsClient>()
.ResolveAsync(async (context, client) =>
{
var updatePermissionDto = context.GetArgument<UpdatePermissionDto>("permission");
await client.UpdatePermissionAsync(updatePermissionDto);
return await client.GetPermissionAsync(updatePermissionDto.Id);
});
}
}
}
6 changes: 1 addition & 5 deletions apps/dh/api-dh/source/DataHub.WebApi/GraphQL/GraphQLQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,7 @@ public GraphQLQuery()
.Resolve()
.WithScope()
.WithService<IMarketParticipantPermissionsClient>()
.ResolveAsync(async (context, client) =>
{
var id = context.GetArgument<int>("id");
return await client.GetPermissionAsync(id);
});
.ResolveAsync(async (context, client) => await client.GetPermissionAsync(context.GetArgument<int>("id")));

Field<NonNullGraphType<ListGraphType<NonNullGraphType<PermissionDtoType>>>>("permissions")
.Resolve()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public GraphQLSchema(IServiceProvider provider)
this.RegisterTypeMapping<EicFunction, EicFunctionEnum>();

Query = provider.GetRequiredService<GraphQLQuery>();
Mutation = provider.GetRequiredService<GraphQLMutation>();
}
}
}
Original file line number Diff line number Diff line change
@@ -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<UpdatePermissionDto>
{
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");
}
}
}
17 changes: 17 additions & 0 deletions libs/dh/shared/domain/src/lib/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Actor>;
Expand Down Expand Up @@ -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 */
Expand Down
16 changes: 16 additions & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
schema {
query: GraphQLQuery
mutation: GraphQLMutation
}

type Actor {
Expand Down Expand Up @@ -86,6 +87,13 @@ enum EicFunction {
SYSTEM_OPERATOR
}

type GraphQLMutation {
permission(
"""Permission to update"""
permission: UpdatePermissionInput!
): Permission!
}

type GraphQLQuery {
actors: [Actor!]!
batch(
Expand Down Expand Up @@ -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!
Expand Down

0 comments on commit 67b7d5e

Please sign in to comment.