graphql-net-client icon indicating copy to clipboard operation
graphql-net-client copied to clipboard

Very simple GraphQL client for .NET/C#

graphql-net-client

Very simple GraphQL client for .NET/C#. Requires JSON.NET!

Typed result

class GqlObj
{
    public string name { get; set; }
    public string id { get; set; }
}

var client = new GraphQLClient("https://mygraphql.endpoint");
var query = @"
    query($id: String) { 
        someObject(id: $id) {
            id
            name
        }
    }
";
var obj = client.Query(query, new { id = "123" }).Get<GqlObj>("someObject");
if (obj != null)
{
    Console.WriteLine(obj.name);
}
else
{
    Console.WriteLine("Null :(");
}

Dynamic result

var client = new GraphQLClient("https://mygraphql.endpoint");
var query = @"
    query($id: String) { 
        someObject(id: $id) {
            id
            name
        }
    }
";
var obj = client.Query(query, new { id = "123" }).Get("someObject");
if (obj != null)
{
    Console.WriteLine((string)obj.name);
}
else
{
    Console.WriteLine("Null :(");
}