Octokit.GraphQL.NET gives you access to the GitHub GraphQL API from within the .NET Framework. It exposes the GitHub GraphQL API as a strongly-typed LINQ-like API, aiming to follow the GraphQL query syntax as closely as possible, giving the benefits of strong typing across the world's leading programming framework, .NET.
[!NOTE] This software is currently in beta. There are few things left, and there might be bugs - be warned!
The full documentation of GraphQL API can be found on GitHub Docs:
To install the package from the command line, run the following command:
Install-Package Octokit.GraphQL -IncludePrerelease
using Octokit.GraphQL;
using static Octokit.GraphQL.Variable;
// Authenticate with a PAT with a scope 'read:user'
var connection = new Connection(new("Octokit.GraphQL.Net.SampleApp", "1.0"), "LOGGED_IN_GITHUB_USER_TOKEN");
var query = new Query()
.RepositoryOwner(Var("owner"))
.Repository(Var("name"))
.Select(repo => new
{
repo.Id,
repo.Name,
repo.Owner.Login,
repo.IsFork,
repo.IsPrivate,
}).Compile();
var vars = new Dictionary<string, object>
{
{ "owner", "octokit" },
{ "name", "octokit.graphql.net" },
};
var result = await connection.Run(query, vars);
Console.WriteLine(result.Login + " & " + result.Name + " Rocks!");
using Octokit.GraphQL;
using Octokit.GraphQL.Model;
using System;
using System.Linq;
using System.Threading.Tasks;
// Authenticate with a PAT with a scope 'read:user'
var connection = new Connection(new("Octokit.GraphQL.Net.SampleApp", "1.0"), "LOGGED_IN_GITHUB_USER_TOKEN");
// A query to list out who you are actively sponsoring
// That auto pages through all sponsors
var query = new Query()
.Viewer
.SponsorshipsAsSponsor()
.AllPages()
.Select(sponsoring => new
{
User = sponsoring.Sponsorable
.Cast<User>()
.Select(x => new
{
x.Login,
x.Name,
x.Id
}.Single()
}).Compile();
// Queries from the GraphQL API end point
var result = await connection.Run(query);
// Check if sponsoring 'warrenbuckley'
var activeSponsor = result.SingleOrDefault(x => x.User.Login.ToLowerInvariant() == "warrenbuckley");
if(activeSponsor != null)
{
Console.WriteLine("Thanks for sponsoring Warren");
}
There are multiple ways to participate in the community:
git clone https://github.com/octokit/octokit.graphql.net
Octokit.GraphQL.sln
.Octokit.GraphQL
or a test project as appropriateDEBUG|x64
(or DEBUG|Any CPU
).
├──Scripts // Code quality scripts
│ └──configure-integration-tests.ps1 // Integration tests configuration script
├──Tools // Code quality tools
│ └──Generate // GraphQL .NET entity generator
├──Octokit.GraphQL // Main API data contracts library
├──Octokit.GraphQL.Core // Octokit core code
├──Octokit.GraphQL.Core.Generation // Core entity generator tools
├──Octokit.GraphQL.Core.Generation.UnitTests // Core entity generator unit tests
├──Octokit.GraphQL.Core.UnitTests // Octokit core unit tests
├──Octokit.GraphQL.IntegrationTests // Octokit integration tests
└──Octokit.GraphQL.UnitTests // Octokit unit tests