Exemplo n.º 1
0
        /// <summary>
        /// Writes a <see cref="GraphQLWebSocketMessageType.Stop"/> message to the writer
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="operationId">The operation id of the operation</param>
        public static void WriteStopOperationMessage(
            this SocketMessageWriter writer,
            string operationId)
        {
            if (operationId == null)
            {
                throw new ArgumentNullException(nameof(operationId));
            }

            writer.WriteStartObject();
            writer.WriteType(GraphQLWebSocketMessageType.Stop);
            writer.WriteId(operationId);
            writer.WriteEndObject();
        }
Exemplo n.º 2
0
        public async Task UnregisterAsync(string subscriptionId)
        {
            if (_subs.TryRemove(subscriptionId, out Sub? sub))
            {
                var writer = new SocketMessageWriter();

                writer.WriteStartObject();
                writer.WriteType(MessageTypes.Subscription.Stop);
                writer.WriteId(subscriptionId);
                writer.WriteEndObject();

                await sub.Connection.SendAsync(writer.Body);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Writes a <see cref="GraphQLWebSocketMessageType.ConnectionInit"/>message to the writer
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="payload">The payload of the init message</param>
        public static void WriteInitializeMessage(
            this SocketMessageWriter writer,
            object?payload)
        {
            writer.WriteStartObject();
            writer.WriteType(GraphQLWebSocketMessageType.ConnectionInit);

            if (payload is not null)
            {
                writer.WriteStartPayload();
                JsonSerializer.Serialize(writer.Writer, payload);
            }

            writer.WriteEndObject();
        }
Exemplo n.º 4
0
        /// <summary>
        /// Writes a <see cref="GraphQLWebSocketMessageType.Start"/> message to the writer
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="operationId">The operation id of the operation</param>
        /// <param name="request">The operation request containing the payload</param>
        public static void WriteStartOperationMessage(
            this SocketMessageWriter writer,
            string operationId,
            OperationRequest request)
        {
            if (operationId == null)
            {
                throw new ArgumentNullException(nameof(operationId));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            writer.WriteStartObject();
            writer.WriteType(GraphQLWebSocketMessageType.Start);
            writer.WriteId(operationId);
            writer.WriteStartPayload();
            writer.Serialize(request);
            writer.WriteEndObject();
        }
Exemplo n.º 5
0
 /// <summary>
 /// Writes a <see cref="GraphQLWebSocketMessageType.ConnectionTerminate"/> message to the
 /// writer
 /// </summary>
 /// <param name="writer">The writer</param>
 public static void WriteTerminateMessage(this SocketMessageWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteType(GraphQLWebSocketMessageType.ConnectionTerminate);
     writer.WriteEndObject();
 }
Exemplo n.º 6
0
 /// <summary>
 /// Writes a <see cref="GraphQLWebSocketMessageType.ConnectionInit"/>message to the writer
 /// </summary>
 /// <param name="writer">The writer</param>
 public static void WriteInitializeMessage(this SocketMessageWriter writer)
 {
     writer.WriteStartObject();
     writer.WriteType(GraphQLWebSocketMessageType.ConnectionInit);
     writer.WriteEndObject();
 }