コード例 #1
0
        public GraphQLSubscription(ICommunicationChannelMessageSubscriptionProvider communicationChannelMessageSubscriptionProvider,
                                   ICommunicationChannelSubscriptionProvider communicationChannelSubscriptionProvider)
        {
            _communicationChannelMessageSubscriptionProvider = communicationChannelMessageSubscriptionProvider;
            _communicationChannelSubscriptionProvider        = communicationChannelSubscriptionProvider;

            Name = "Subscription";

            AddField(new EventStreamFieldType
            {
                Name      = "communicationChannelMessageAddedToChannel",
                Arguments = new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "channelId"
                }
                    ),
                Type       = typeof(CommunicationChannelMessageType),
                Resolver   = new FuncFieldResolver <CommunicationChannelMessageDto>(ResolveCommunicationChannelMessage),
                Subscriber = new EventStreamResolver <CommunicationChannelMessageDto>(SubscribeByCommunicationChannelId)
            });

            AddField(new EventStreamFieldType
            {
                Name      = "communicationChannelAddedForUser",
                Arguments = new QueryArguments(
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                    Name = "userId"
                }
                    ),
                Type       = typeof(CommunicationChannelType),
                Resolver   = new FuncFieldResolver <CommunicationChannelDto>(ResolveCommunicationChannel),
                Subscriber = new EventStreamResolver <CommunicationChannelDto>(SubscribeToCommunicationChannelByUserId)
            });
        }
コード例 #2
0
 public GraphQLSchema(IServiceProvider provider, ICommunicationChannelMessageSubscriptionProvider communicationChannelMessageSubscriptionProvider, ICommunicationChannelSubscriptionProvider communicationChannelSubscriptionProvider)
     : base(provider)
 {
     Query        = provider.GetRequiredService <GraphQLQuery>();
     Mutation     = provider.GetRequiredService <GraphQLMutation>();
     Subscription = new GraphQLSubscription(communicationChannelMessageSubscriptionProvider, communicationChannelSubscriptionProvider);
 }
コード例 #3
0
        public CommunicationChannelMutation(ICommunicationChannelSubscriptionProvider communicationChannelSubscriptionProvider)
        {
            _communicationChannelSubscriptionProvider = communicationChannelSubscriptionProvider;
            Name = "CommunicationChannelMutation";

            this.FieldAsyncWithScope <CommunicationChannelType, CommunicationChannelDto>(
                "create",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "name"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "desc"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new CreateCommunicationChannelCommand()
                {
                    Name        = ctx.GetString("name"),
                    Description = ctx.GetString("desc")
                };

                var channel = await mediator.Send(command);

                _communicationChannelSubscriptionProvider.UpdateCommunicationChannel(channel);

                return(channel);
            }
                );

            this.FieldAsyncWithScope <BooleanGraphType, bool>(
                "delete",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new DeleteCommunicationChannelCommand()
                {
                    Id = ctx.GetString("id")
                };

                await mediator.Send(command);

                return(true);
            }
                );

            this.FieldAsyncWithScope <BooleanGraphType, bool>(
                "update",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "name"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "desc"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new UpdateCommunicationChannelCommand()
                {
                    Id          = ctx.GetString("id"),
                    Name        = ctx.GetString("name"),
                    Description = ctx.GetString("desc"),
                };

                await mediator.Send(command);

                return(true);
            }
                );

            this.FieldAsyncWithScope <BooleanGraphType, bool>(
                "addUser",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelId"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new AddUserToCommunicationChannelCommand()
                {
                    UserId    = ctx.GetString("userId"),
                    ChannelId = ctx.GetString("channelId")
                };

                var channel = await mediator.Send(command);

                _communicationChannelSubscriptionProvider.UpdateCommunicationChannel(channel);

                return(true);
            }
                );

            this.FieldAsyncWithScope <BooleanGraphType, bool>(
                "removeUser",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelId"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new RemoveUserFromCommunicationChannelCommand()
                {
                    UserId    = ctx.GetString("userId"),
                    ChannelId = ctx.GetString("channelId")
                };

                var channel = await mediator.Send(command);

                _communicationChannelSubscriptionProvider.UpdateCommunicationChannel(channel);

                return(true);
            }
                );
        }