Skip to content

ProgrammingByPermutation/octokit.graphql.net

 
 

Repository files navigation

Octokit.GraphQL.NET

CI Status CodeCov Status NuGet

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!

Getting started

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

Usage scenarios

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

Contributing & Feedback

There are multiple ways to participate in the community:

Building from source

Prerequisites

  1. Ensure you have following components:
  2. Clone the repository:
    git clone https://github.com/octokit/octokit.graphql.net
    

Building the project

  • Open Octokit.GraphQL.sln.
  • Set the Startup Project to Octokit.GraphQL or a test project as appropriate
  • Build with DEBUG|x64 (or DEBUG|Any CPU)

Codebase structure

.
├──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

About

A GitHub GraphQL client library for .NET

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.9%
  • Other 0.1%