Skip to content

Latest commit

 

History

History
53 lines (50 loc) · 942 Bytes

README.md

File metadata and controls

53 lines (50 loc) · 942 Bytes

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 :(");
}