public void GetCategoryById() { IClient commerceToolsClient = this.graphqlFixture.GetService <IClient>(); var category = this.graphqlFixture.CreateCategory(); var query = new GraphQLParameters( @"query Sphere($cid: String!) { categories(where: $cid) { results { id } } }", new Dictionary <string, object>() { { "cid", $"id = \"{category.Id}\"" } } ); var graphQlCommand = new GraphQLCommand <dynamic>(query); var result = commerceToolsClient.ExecuteAsync(graphQlCommand).Result; Assert.Equal(category.Id, result.data.categories.results[0].id.Value); }
public async Task UpdateAnOrder() { //Arrange var orderNumber = $"order-{TestingUtility.RandomInt()}"; var query = @"mutation ($orderId:String, $orderNumber:String){ updateOrder( version: 1, id:$orderId, actions: [ { changeOrderState:{ orderState: Confirmed } }, { setOrderNumber:{ orderNumber: $orderNumber } } ] ) { id, orderNumber, orderState, version } }"; //act await WithCartWithSingleLineItem(client, 2, DefaultCartDraft, async cart => { Assert.Single(cart.LineItems); //create order with null orderNumber await WithUpdateableOrder(client, draft => DefaultOrderFromCartDraftWithNumber(draft, cart, orderNumber: null), async order => { Assert.NotNull(order); Assert.Null(order.OrderNumber); var queryParameters = new GraphQLParameters(query, new Dictionary <string, object> { { "orderId", order.Id }, { "orderNumber", orderNumber } }); var graphQlCommand = new GraphQLCommand <dynamic>(queryParameters); var result = await client.ExecuteAsync(graphQlCommand); var updatedOrderJObject = result.data.updateOrder as JObject; Assert.NotNull(updatedOrderJObject); var updatedOrder = updatedOrderJObject.ToObject <Order>(); Assert.Equal(order.Id, updatedOrder.Id); Assert.Equal(OrderState.Confirmed, updatedOrder.OrderState); Assert.Equal(orderNumber, updatedOrder.OrderNumber); return(updatedOrder); }); }); }
private Uri GetRequestUri <T>(GraphQLCommand <T> command) { string requestUri = "graphql"; List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >(); queryStringParameters.AddRange(this.GetAdditionalParameters(command.AdditionalParameters)); queryStringParameters.ForEach(x => { requestUri = QueryHelpers.AddQueryString(requestUri, x.Key, x.Value); }); return(new Uri(requestUri, UriKind.Relative)); }
private Uri GetRequestUri <T>(GraphQLCommand <T> command) { string requestUri = this.GetMessageBaseWithoutEndpoint() + "/graphql"; List <KeyValuePair <string, string> > queryStringParameters = new List <KeyValuePair <string, string> >(); queryStringParameters.AddRange(this.GetAdditionalParameters(command.AdditionalParameters)); queryStringParameters.ForEach(x => { requestUri = QueryHelpers.AddQueryString(requestUri, x.Key, x.Value); }); return(new Uri(requestUri)); }
private HttpContent GetHttpContent <T>(GraphQLCommand <T> command) { var requestBody = new { query = command.GraphQlParameters.Query, variables = command.GraphQlParameters.Variables, operationName = command.GraphQlParameters.OperationName, }; return(new StringContent(this.serializerService.Serialize(requestBody))); }
public async Task CreateCustomerGroup() { await WithCategory(client, async category => { var query = @"query Test($cid: String!) { categories(where: $cid) { results { id } } }"; var queryParameters = new GraphQLParameters(query, new Dictionary <string, object> { { "cid", $"id = \"{category.Id}\"" } }); var graphQlCommand = new GraphQLCommand <dynamic>(queryParameters); var result = await client.ExecuteAsync(graphQlCommand); Assert.Equal(category.Id, result.data.categories.results[0].id.Value); }); }
public GraphQLHttpApiCommand(GraphQLCommand <T> command, IRequestMessageBuilderFactory requestMessageBuilderFactory) { this.command = command; this.requestBuilder = requestMessageBuilderFactory.GetRequestMessageBuilder <GraphQLRequestMessageBuilder>(); }
public HttpRequestMessage GetRequestMessage <T>(GraphQLCommand <T> command) { return(this.GetRequestMessage <T>(this.GetRequestUri <T>(command), this.GetHttpContent(command), HttpMethod)); }