Exemple #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)
            });
        }
Exemple #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);
 }
Exemple #3
0
        public CommunicationChannelMessageMutation(ICommunicationChannelMessageSubscriptionProvider communicationChannelMessageSubscriptionProvider)
        {
            Name = "CommunicationChannelMessageMutation";

            this.FieldAsyncWithScope <StringGraphType, CommunicationChannelMessageDto>(
                "create",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "userId"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "channelId"
            },
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "content"
            },
                    new QueryArgument <NonNullGraphType <IntGraphType> > {
                Name = "type"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new CreateCommunicationChannelMessageCommand()
                {
                    UserId    = ctx.GetString("userId"),
                    ChannelId = ctx.GetString("channelId"),
                    Content   = ctx.GetString("content"),
                    Type      = (CommunicationChannelMessageType)ctx.GetInt("type")
                };

                var communicationChannelMessageDto = await mediator.Send(command);

                // Přidám zprávu do kolekce přidaných zpráv (v GraphQL kontextu), aby se mohla zaslat "notifikace" subscriberům.
                communicationChannelMessageSubscriptionProvider.AddCommunicationChannelMessage(
                    communicationChannelMessageDto);

                return(communicationChannelMessageDto);
            }
                );

            this.FieldAsyncWithScope <BooleanGraphType, bool>(
                "delete",
                arguments:
                new QueryArguments
                (
                    new QueryArgument <NonNullGraphType <StringGraphType> > {
                Name = "id"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new DeleteCommunicationChannelMessageCommand()
                {
                    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 = "content"
            }
                ),
                resolve: async(ctx, mediator) =>
            {
                var command = new UpdateCommunicationChannelMessageCommand()
                {
                    Id      = ctx.GetString("id"),
                    Content = ctx.GetString("content")
                };

                await mediator.Send(command);

                return(true);
            }
                );
        }