Skip to content

Instantly share code, notes, and snippets.

View mdcarmo's full-sized avatar
🏠
Working from home

Marcelo Dias mdcarmo

🏠
Working from home
View GitHub Profile
class Program
{
static void Main(string[] args)
{
var timeExecution = new Stopwatch();
Console.WriteLine($"Iniciando a execução");
timeExecution.Start();
InitProcess();
timeExecution.Stop();
@mdcarmo
mdcarmo / mutationDelete.cs
Created April 23, 2022 21:09
Exemplo de mutação do tipo delete graphQL
Field<StringGraphType>(
"deleteCustomer",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "customerId" }),
resolve: context =>
{
var customerId = context.GetArgument<Guid>("customerId");
var customer = repository.GetById(customerId, false).Result;
if (customer == null)
{
context.Errors.Add(new ExecutionError("Cliente não encontrado na base de dados com este id."));
@mdcarmo
mdcarmo / mutationUpdate.cs
Created April 23, 2022 21:06
exemplo de mutação update do graphql
Field<CustomerType>(
"updateCustomer",
arguments: new QueryArguments(
new QueryArgument<NonNullGraphType<CustomerInputType>> { Name = "customer" },
new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "customerId" }),
resolve: context =>
{
var customer = context.GetArgument<Customer>("customer");
var customerId = context.GetArgument<Guid>("customerId");
@mdcarmo
mdcarmo / mutationCreate.cs
Created April 23, 2022 20:14
Exemplo de mutação create graphql
Field<CustomerType>(
"createCustomer",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<CustomerInputType>> { Name = "customer" }),
resolve: context =>
{
var customer = context.GetArgument<Customer>("customer");
return repository.Create(customer);
}
);
@mdcarmo
mdcarmo / queryById.cs
Created April 23, 2022 20:06
Field para consulta de client por ID no GraphQL
Field<CustomerType>(
"customerById",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "customerId" }),
resolve: context =>
{
Guid id;
if (!Guid.TryParse(context.GetArgument<string>("customerId"), out id))
{
context.Errors.Add(new ExecutionError("Valor inserido não é um guid válido"));
return null;
@mdcarmo
mdcarmo / ProductController.cs
Created June 9, 2019 23:34
ProductController
namespace Products.Api.Controllers
{
[Route("v1/product")]
public class ProductController: Controller
{
private readonly IProdutctService _productsService;
public ProductController(IProdutctService productsService)
{
_productsService = productsService;
@mdcarmo
mdcarmo / ProductService.cs
Created June 9, 2019 23:30
ProductService
namespace Products.Api.Services
{
public class ProductService : IProdutctService
{
private readonly Dictionary<string, int> _productListStorage = new Dictionary<string, int>();
public Dictionary<string, int> GetProducts()
{
return _productListStorage;
}
@mdcarmo
mdcarmo / IProductService.cs
Created June 9, 2019 23:28
IProductService
namespace Products.Api.Services
{
public interface IProdutctService
{
Dictionary<string, int> GetProducts();
void AddProduct(ProductModel product);
void RemoveProduct(string productName);
}
}
@mdcarmo
mdcarmo / ProductModel.cs
Created June 9, 2019 23:06
ProductModel
namespace Products.Api.Models
{
public class ProductModel
{
public string Name { get; set; }
public int Quantity { get; set; }
}
}
@mdcarmo
mdcarmo / example.js
Created July 24, 2018 11:42
Retry an AJAX and JQuery
$.ajax({
url : 'someurl',
type : 'POST',
data : ....,
tryCount : 0,
retryLimit : 3,
success : function(json) {
//do something
},
error : function(xhr, textStatus, errorThrown ) {