protected virtual async Task <Tuple <byte[], string> > GetBinaryDataAsync(IGraphQLClient client, BinaryComponent binaryComponent, CancellationToken cancellationToken = default(CancellationToken)) { if (binaryComponent == null) { return(null); } if (binaryComponent?.Variants == null) { Log.Error("Unable to get binary data for CmUri: " + binaryComponent.CmUri()); return(null); } var variant = binaryComponent.Variants.Edges[0].Node; try { Log.Debug("Attempting to get binary at : " + variant.DownloadUrl); var data = await client.HttpClient.ExecuteAsync <byte[]>(new HttpClientRequest { AbsoluteUri = variant.DownloadUrl }, cancellationToken); return(new Tuple <byte[], string>(data.ResponseData, variant.Path)); } catch (Exception ex) { Log.Error(ex, "Unable to get binary data for CmUri: " + binaryComponent.CmUri()); return(null); } }
public GqlQueryProviderTest(GqlClientFixture clientFixture) { var mapper = new Mock <IGraphTypeNameMapper>(); mapper.Setup(_ => _.GetTypeName(It.IsAny <Type>())).Returns((Type t) => t.Name); var schema = Schema.For(@" type Object { id: Int! } type Query { objects: [Object] }"); queryBuilder = new GqlQueryBuilder(schema, mapper.Object); client = clientFixture.CreateClientFor( schema, new { objects = new[] { new { id = 1 }, new { id = 2 }, new { id = 3 } } }); }
public static Task <GraphQLResponse <TResponse> > SendQueryAsync <TResponse>(this IGraphQLClient client, string query, object?variables = null, string?operationName = null, Func <TResponse> defineResponseType = null, CancellationToken cancellationToken = default) { _ = defineResponseType; return(client.SendQueryAsync <TResponse>(new GraphQLRequest(query, variables, operationName), cancellationToken: cancellationToken)); }
/// <summary>Constructor.</summary> /// <param name="isIEnumerableResult">Shows if should return an IEnumerable.</param> /// <param name="queryMethod">Query method.</param> /// <param name="fields">GraphQL HTTP Field Selector Function.</param> /// <param name="args">A variable-length parameters list containing arguments.</param> public GraphQLQuery(HttpClient httpClient, string endpoint, bool isIEnumerableResult, bool isMutation, MethodBase queryMethod, Func <T, T> fields, params object[] args) { _graphQlClientService = new GraphQLHttpClient(httpClient, endpoint); _isIEnumerableResult = isIEnumerableResult; _isMutation = isMutation; QueryMethod = queryMethod; Arguments = args; FieldsSelector = fields; typesDefaultGraphQL = new Dictionary <String, Object>(); }
public BlogController(IGraphQLClient graphQLClient, ILogger <BlogController> logger, IHttpClientFactory httpClientFactory, IServerConfig serverConfig) { _graphQLClientRef = graphQLClient; _logger = logger; _httpClientFactoryRef = httpClientFactory; _serverConfigRef = serverConfig; }
public GitHubApiRepositorySourceRepository(IGitHubClient gitHubClient, ITreesClient treesClient, IGraphQLClient graphQLClient, ILogger <GitHubApiRepositorySourceRepository> logger) { this.gitHubClient = gitHubClient; this.treesClient = treesClient; this.graphQLClient = graphQLClient; this.logger = logger; this.githubAbuseRateLimitPolicy = Policy.Handle <GraphQLRequestException>(ex => ex.HttpStatusCode == System.Net.HttpStatusCode.Forbidden && ex.ResponseBody.Contains("You have triggered an abuse detection mechanism", StringComparison.OrdinalIgnoreCase)) .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (exception, timespan) => { logger.LogWarning($"GitHub abuse rate limit hit, waiting {timespan.TotalSeconds} seconds before trying again"); }); }
protected ApiClient( IMapper mapper, IRestClient <TDtoInterface, TDto> restClient, IGraphQLClient graphClient, TGrpcClient grpcClient, string module, string component ) { _mapper = mapper; _restClient = restClient; _restClient.SetModule(module, component); _graphClient = graphClient; _grpcClient = grpcClient; }
public CustomerClient( IMapper mapper, IRestClient <ICustomerDTO, CustomerDTO> restClient, IGraphQLClient graphClient, GrpcClient <CustomerMessage> grpcClient ) : base( mapper, restClient, graphClient, grpcClient, "Sales", "Customers" ) { }
public static void AddUniswap(this IServiceCollection services) { services.AddSingleton <IGraphQLClient>(ctx => { var graphQLOptions = new GraphQLHttpClientOptions { EndPoint = new Uri("https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v2") }; return(new GraphQLHttpClient(graphQLOptions, new SystemTextJsonSerializer())); }); services.AddSingleton <IUniswap>(ctx => { IGraphQLClient graphQLClient = ctx.GetRequiredService <IGraphQLClient>(); return(new Uniswap(graphQLClient)); }); }
private Schema InitSchema(IGraphQLClient gqlClient) { var request = new GraphQLRequest { Query = GetIntrospectionQuery() }; var result = Task.Run(async() => await gqlClient.SendQueryAsync <JObject>(request, CancellationToken.None)) .GetAwaiter() .GetResult() .Data; var queryType = (JObject)result["__schema"]["queryType"]; var types = ((JArray)result["__schema"]["types"]).Cast <JObject>().ToArray(); var dummySchema = new Schema(); dummySchema.Initialize(); var schemaTypes = new SchemaTypes(dummySchema, new DefaultServiceProvider()); var cache = new Dictionary <string, IGraphType>(); var qt = ResolveGraphType(_ => schemaTypes[_] ?? (cache.ContainsKey(_) ? cache[_] : null), types, queryType, cache); var commonTypes = cache.Values.ToArray(); foreach (var type in types) { ResolveGraphType(_ => schemaTypes[_] ?? (cache.ContainsKey(_) ? cache[_] : null), types, type, cache); } var newSchema = new Schema(); newSchema.Query = (IObjectGraphType)qt; foreach (var type in cache.Values.Except(commonTypes)) { newSchema.RegisterType(type); } newSchema.Initialize(); return(newSchema); }
protected virtual void Page_Load(object sender, EventArgs e) { if (!Request.IsAuthenticated) { Response.StatusCode = (int)HttpStatusCode.NotFound; Response.Redirect("~/404.aspx"); return; } var userClaims = User.Identity as ClaimsIdentity; GraphQLClient = new GraphQLHttpClient(new GraphQLHttpClientOptions { EndPoint = new Uri(ConfigurationManager.AppSettings["Resource"]) }); (GraphQLClient as GraphQLHttpClient).DefaultRequestHeaders.Add( name: "Authorization", value: $"Bearer {userClaims.Claims.Where(claim => claim.Type == "access_token").FirstOrDefault().Value}" ); }
protected virtual Tuple <byte[], string> GetBinaryData(IGraphQLClient client, BinaryComponent binaryComponent) { if (binaryComponent == null) { return(null); } if (binaryComponent?.Variants == null) { Log.Error("Unable to get binary data for CmUri (Variants null): " + binaryComponent.CmUri()); return(null); } try { if (binaryComponent.Variants.Edges == null || binaryComponent.Variants.Edges.Count == 0) { Log.Error("Empty variants returned by GraphQL query for binary component: " + binaryComponent.CmUri()); return(null); } var variant = binaryComponent.Variants.Edges[0].Node; if (string.IsNullOrEmpty(variant.DownloadUrl)) { Log.Error("Binary variant download Url is missing for binary component: " + binaryComponent.CmUri()); return(null); } Log.Debug("Attempting to get binary at : " + variant.DownloadUrl); return(new Tuple <byte[], string>(client.HttpClient.Execute <byte[]>(new HttpClientRequest { AbsoluteUri = variant.DownloadUrl }).ResponseData, variant.Path)); } catch (Exception ex) { Log.Error(ex, "Unable to get binary data for CmUri: " + binaryComponent.CmUri()); return(null); } }
public WorkflowGenProfileModel(IConfiguration config, IGraphQLClient client) : base() { this.config = config; this.graphqlClient = client; }
public CoolStoreService(IGraphQLClient client) { _client = client; }
/// <inheritdoc cref="GraphQLHttpClient.CreateSubscriptionStream{TResponse}(GraphQLRequest)"/> public static IObservable <GraphQLResponse <TResponse> > CreateSubscriptionStream <TResponse>( this IGraphQLClient client, GraphQLRequest request, Func <TResponse> defineResponseType) { _ = defineResponseType; return(client.CreateSubscriptionStream <TResponse>(request)); }
/// <inheritdoc cref="CreateSubscriptionStream{TResponse}(IGraphQLClient,GraphQLRequest,Action{WebSocketException})"/> public static IObservable <GraphQLResponse <TResponse> > CreateSubscriptionStream <TResponse>( this IGraphQLClient client, GraphQLRequest request, Func <TResponse> defineResponseType, Action <WebSocketException> webSocketExceptionHandler) { _ = defineResponseType; return(client.CreateSubscriptionStream <TResponse>(request, webSocketExceptionHandler)); }
public GqlConsumer(IGraphQLClient client) { _client = client; }
public static Task <GraphQLResponse <JoinDeveloperMutationResult> > JoinDeveloperUser(this IGraphQLClient client) { var graphQLRequest = new GraphQLRequest(@" mutation($userId: String){ join(userId: $userId){ displayName id } }" , new { userId = "1" }); return(client.SendMutationAsync <JoinDeveloperMutationResult>(graphQLRequest)); }
public GraphQLRepository(IGraphQLClient graphQLClient) { _graphQLClient = graphQLClient; }
public InventoryController(IGraphQLClient client) { _client = client; }
public static IObservable <GraphQLResponse <TResponse> > CreateSubscriptionStream <TResponse>( this IGraphQLClient client, GraphQLRequest request, Func <TResponse> defineResponseType, Action <Exception> exceptionHandler) => client.CreateSubscriptionStream <TResponse>(request, exceptionHandler);
public GraphQLService( IGraphQLClient httpClient) { _httpClient = httpClient; }
public GraphQLTeamsProvider(IGraphQLClient graphQLClient) : base(graphQLClient) { }
public OwnerConsumer(IGraphQLClient client) { _client = client; }
public ProductController(IGraphQLClient client) { _client = client; }
public static Task <GraphQLResponse <TResponse> > SendQueryAsync <TResponse>(this IGraphQLClient client, GraphQLRequest request, Func <TResponse> defineResponseType, CancellationToken cancellationToken = default) { _ = defineResponseType; return(client.SendQueryAsync <TResponse>(request, cancellationToken)); }
public static Task <GraphQLResponse <AddMessageMutationResult> > AddMessageAsync(this IGraphQLClient client, string message) { var variables = new AddMessageVariables { Input = new AddMessageVariables.AddMessageInput { FromId = "2", Content = message, SentAt = DateTime.Now.ToString("s") } }; var graphQLRequest = new GraphQLRequest(ADD_MESSAGE_QUERY, variables); return(client.SendMutationAsync <AddMessageMutationResult>(graphQLRequest)); }
/// <summary> /// Creates a subscription to a GraphQL server. The connection is not established until the first actual subscription is made.<br/> /// All subscriptions made to this stream share the same hot observable.<br/> /// All <see cref="WebSocketException"/>s are passed to the <paramref name="webSocketExceptionHandler"/> to be handled externally.<br/> /// If the <paramref name="webSocketExceptionHandler"/> completes normally, the subscription is recreated with a new connection attempt.<br/> /// Other <see cref="Exception"/>s or any exception thrown by <paramref name="webSocketExceptionHandler"/> will cause the sequence to fail. /// </summary> /// <param name="client">the GraphQL client</param> /// <param name="request">the GraphQL request for this subscription</param> /// <param name="webSocketExceptionHandler">an external handler for all <see cref="WebSocketException"/>s occurring within the sequence</param> /// <returns>an observable stream for the specified subscription</returns> public static IObservable <GraphQLResponse <TResponse> > CreateSubscriptionStream <TResponse>(this IGraphQLClient client, GraphQLRequest request, Action <WebSocketException> webSocketExceptionHandler) => client.CreateSubscriptionStream <TResponse>(request, e => { if (e is WebSocketException webSocketException) { webSocketExceptionHandler(webSocketException); } else { throw e; } });
public static Task <GraphQLResponse <TResponse> > SendMutationAsync <TResponse>(this IGraphQLClient client, GraphQLRequest request, Func <TResponse> defineResponseType, CancellationToken cancellationToken = default) => client.SendMutationAsync <TResponse>(request, cancellationToken);
public static ApiClient CreateClient(IGraphQLClient graphQL) => new ApiClient(graphQL);