Skip to content

Commit 332e997

Browse files
authored
Merge pull request #240 from warrenbuckley/patch-1
Update ReadMe with a useful example using AllPages & Cast
2 parents cc603c9 + 8c6ec28 commit 332e997

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

readme.md

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,53 @@ var result = await connection.Run(query, vars);
4949

5050
Console.WriteLine(result.Login + " & " + result.Name + " Rocks!");
5151
```
52+
53+
```csharp
54+
using Octokit.GraphQL;
55+
using Octokit.GraphQL.Model;
56+
using System;
57+
using System.Linq;
58+
using System.Threading.Tasks;
59+
60+
namespace Octokit
61+
{
62+
class Program
63+
{
64+
static async Task Main(string[] args)
65+
{
66+
var productInformation = new ProductHeaderValue("ExampleCode", "1.0");
67+
68+
// Personal Access Token - needs a scope of 'read:user'
69+
var connection = new Connection(productInformation, "LOGGED_IN_GITHUB_USER_TOKEN");
70+
71+
// A query to list out who you are actively sponsoring
72+
// That auto pages through all sponsors
73+
var query = new Query()
74+
.Viewer
75+
.SponsorshipsAsSponsor()
76+
.AllPages()
77+
.Select(sponsoring => new
78+
{
79+
User = sponsoring.Sponsorable
80+
.Cast<User>()
81+
.Select(x => new {
82+
x.Login,
83+
x.Name,
84+
x.Id
85+
})
86+
.Single()
87+
})
88+
.Compile();
89+
90+
var result = await connection.Run(query);
91+
92+
// Sponsoring 'warrenbuckley' ?
93+
var activeSponsor = result.SingleOrDefault(x => x.User.Login.ToLowerInvariant() == "warrenbuckley");
94+
if(activeSponsor != null)
95+
{
96+
Console.WriteLine("Thanks for sponsoring Warren");
97+
}
98+
}
99+
}
100+
}
101+
```

0 commit comments

Comments
 (0)