コード例 #1
0
 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);
 }
コード例 #2
0
 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();
 }
コード例 #3
0
        public static byte[] SerializeToBytes(this GraphQLRequest request,
                                              GraphQLHttpClientOptions options)
        {
            var json = JsonConvert.SerializeObject(request, options.JsonSerializerSettings);

            return(Encoding.UTF8.GetBytes(json));
        }
コード例 #4
0
 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);
 }
コード例 #5
0
        /// <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);
        }
コード例 #6
0
        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));
        }
コード例 #7
0
        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)));
                }
        }
コード例 #8
0
 public static TObject DeserializeFromBytes <TObject>(this byte[] utf8Bytes,
                                                      GraphQLHttpClientOptions options)
 {
     return(JsonConvert.DeserializeObject <TObject>(Encoding.UTF8.GetString(utf8Bytes), options.JsonSerializerSettings));
 }
コード例 #9
0
 public static TGraphQLResponse DeserializeFromJson <TGraphQLResponse>(this string jsonString,
                                                                       GraphQLHttpClientOptions options)
 {
     return(JsonConvert.DeserializeObject <TGraphQLResponse>(jsonString, options.JsonSerializerSettings));
 }
コード例 #10
0
 public static GraphQLHttpClient AsGraphQLClient(this HttpClient httpClient, string endPoint, GraphQLHttpClientOptions graphQLHttpClientOptions) =>
 new GraphQLHttpClient(endPoint, graphQLHttpClientOptions, httpClient);
コード例 #11
0
 public static string SerializeToJson(this GraphQLRequest request,
                                      GraphQLHttpClientOptions options)
 {
     return(JsonConvert.SerializeObject(request, options.JsonSerializerSettings));
 }
コード例 #12
0
 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;
 }
コード例 #13
0
 public GraphQLHttpClient(GraphQLHttpClientOptions options, IGraphQLWebsocketJsonSerializer serializer) : this(options, serializer, new HttpClient(options.HttpMessageHandler))
 {
 }
コード例 #14
0
 public static GraphQLHttpClient AsGraphQLClient(this HttpClient httpClient, GraphQLHttpClientOptions graphQLHttpClientOptions) =>
 new GraphQLHttpClient(graphQLHttpClientOptions, httpClient);
コード例 #15
0
 public GraphQLHttpClient(Uri endPoint, GraphQLHttpClientOptions options)
 {
     this.EndPoint   = endPoint;
     this.httpClient = new HttpClient();
 }
コード例 #16
0
 public GraphQLHttpClient(GraphQLHttpClientOptions options) : this(options, new HttpClient(options.HttpMessageHandler))
 {
 }
コード例 #17
0
 public GraphQLHttpClient(Uri endPoint, GraphQLHttpClientOptions options, HttpClient httpClient)
 {
     this.EndPoint   = endPoint;
     this.httpClient = httpClient;
 }
コード例 #18
0
 public GraphQLHttpClient(string endPoint, GraphQLHttpClientOptions options, HttpClient httpClient)
 {
     this.EndPoint   = new Uri(endPoint);
     this.httpClient = httpClient;
 }