public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer, HttpClient httpClient) { Options = options ?? throw new ArgumentNullException(nameof(options)); JsonSerializer = serializer ?? throw new ArgumentNullException(nameof(serializer), "please configure the JSON serializer you want to use"); HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); _graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this); }
public GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient) { Options = options; this.HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this); Options.JsonSerializer = JsonSerializer.EnsureAssigned(); }
public static byte[] SerializeToBytes(this GraphQLRequest request, GraphQLHttpClientOptions options) { var json = JsonConvert.SerializeObject(request, options.JsonSerializerSettings); return(Encoding.UTF8.GetBytes(json)); }
public GraphQLHttpClient(GraphQLHttpClientOptions options, HttpClient httpClient, IGraphQLWebsocketJsonSerializer serializer) { Options = options ?? throw new ArgumentNullException(nameof(options)); Options.JsonSerializer = serializer ?? throw new ArgumentNullException(nameof(serializer)); this.HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); this.graphQlHttpWebSocket = new GraphQLHttpWebSocket(GetWebSocketUri(), this); }
/// <summary> /// Creates a <see cref="HttpRequestMessage"/> from this <see cref="GraphQLHttpRequest"/>. /// Used by <see cref="GraphQLHttpClient"/> to convert GraphQL requests when sending them as regular HTTP requests. /// </summary> /// <param name="options">the <see cref="GraphQLHttpClientOptions"/> passed from <see cref="GraphQLHttpClient"/></param> /// <param name="serializer">the <see cref="IGraphQLJsonSerializer"/> passed from <see cref="GraphQLHttpClient"/></param> /// <returns></returns> public virtual HttpRequestMessage ToHttpRequestMessage(GraphQLHttpClientOptions options, IGraphQLJsonSerializer serializer) { var message = new HttpRequestMessage(HttpMethod.Post, options.EndPoint) { Content = new StringContent(serializer.SerializeToString(this), Encoding.UTF8, options.MediaType) }; #pragma warning disable CS0618 // Type or member is obsolete PreprocessHttpRequestMessage(message); #pragma warning restore CS0618 // Type or member is obsolete return(message); }
public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer, HttpClient httpClient) { Options = options ?? throw new ArgumentNullException(nameof(options)); JsonSerializer = serializer ?? throw new ArgumentNullException(nameof(serializer), "please configure the JSON serializer you want to use"); HttpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient)); if (!HttpClient.DefaultRequestHeaders.UserAgent.Any()) { HttpClient.DefaultRequestHeaders.UserAgent.Add(new ProductInfoHeaderValue(GetType().Assembly.GetName().Name, GetType().Assembly.GetName().Version.ToString())); } _lazyHttpWebSocket = new Lazy <GraphQLHttpWebSocket>(() => new GraphQLHttpWebSocket(Options.EndPoint.GetWebSocketUri(), this)); }
public static Task <TGraphQLResponse> DeserializeFromJsonAsync <TGraphQLResponse>(this Stream stream, GraphQLHttpClientOptions options, CancellationToken cancellationToken = default) { using (StreamReader sr = new StreamReader(stream)) using (JsonReader reader = new JsonTextReader(sr)) { JsonSerializer serializer = JsonSerializer.Create(options.JsonSerializerSettings); return(Task.FromResult(serializer.Deserialize <TGraphQLResponse>(reader))); } }
public static TObject DeserializeFromBytes <TObject>(this byte[] utf8Bytes, GraphQLHttpClientOptions options) { return(JsonConvert.DeserializeObject <TObject>(Encoding.UTF8.GetString(utf8Bytes), options.JsonSerializerSettings)); }
public static TGraphQLResponse DeserializeFromJson <TGraphQLResponse>(this string jsonString, GraphQLHttpClientOptions options) { return(JsonConvert.DeserializeObject <TGraphQLResponse>(jsonString, options.JsonSerializerSettings)); }
public static GraphQLHttpClient AsGraphQLClient(this HttpClient httpClient, string endPoint, GraphQLHttpClientOptions graphQLHttpClientOptions) => new GraphQLHttpClient(endPoint, graphQLHttpClientOptions, httpClient);
public static string SerializeToJson(this GraphQLRequest request, GraphQLHttpClientOptions options) { return(JsonConvert.SerializeObject(request, options.JsonSerializerSettings)); }
public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer) : this( options, serializer, new HttpClient(options.HttpMessageHandler)) { // set this flag to dispose the internally created HttpClient when GraphQLHttpClient gets disposed _disposeHttpClient = true; }
public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer) : this(options, serializer, new HttpClient(options.HttpMessageHandler)) { }
public static GraphQLHttpClient AsGraphQLClient(this HttpClient httpClient, GraphQLHttpClientOptions graphQLHttpClientOptions) => new GraphQLHttpClient(graphQLHttpClientOptions, httpClient);
public GraphQLHttpClient(Uri endPoint, GraphQLHttpClientOptions options) { this.EndPoint = endPoint; this.httpClient = new HttpClient(); }
public GraphQLHttpClient(GraphQLHttpClientOptions options) : this(options, new HttpClient(options.HttpMessageHandler)) { }
public GraphQLHttpClient(Uri endPoint, GraphQLHttpClientOptions options, HttpClient httpClient) { this.EndPoint = endPoint; this.httpClient = httpClient; }
public GraphQLHttpClient(string endPoint, GraphQLHttpClientOptions options, HttpClient httpClient) { this.EndPoint = new Uri(endPoint); this.httpClient = httpClient; }