-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
79 lines (67 loc) · 2.75 KB
/
Program.cs
File metadata and controls
79 lines (67 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using Replit.GraphQL;
using System.Linq;
namespace Example
{
public class Program
{
public static async Task Main()
{
Console.WriteLine("Enter your Replit connect.sid cookie value or press enter to skip:");
string sid = Console.ReadLine();
if (string.IsNullOrEmpty(sid)) sid = null;
ReplitGraphQLClient client = new("Example Application", sid);
string userByUsername = @"
query userByUsername($username: String!) {
user: userByUsername(username: $username) {
id
bio
firstName
lastName
timeCreated
}
}";
string replByUrl = @"
query ReplByURL($url: String!) {
repl(url: $url) {
... on Repl {
id
url
title
slug
description
timeCreated
}
}
}";
Console.WriteLine("> Executing a single query: 'userByUsername'");
User user = (await client.Execute<UserContainer>(userByUsername, new Dictionary<string, object>()
{
{
"username", "akac"
}
}))?.User;
if (user is null) Console.WriteLine("The provided user doesn't exist.");
else
{
Console.WriteLine($"Name: {user.FirstName} {user.LastName}");
Console.WriteLine($"ID: {user.Id}");
Console.WriteLine($"Bio: {user.Bio.Replace("\n", ", ")}");
Console.WriteLine($"Registered At: {user.TimeCreated}");
}
Console.WriteLine("> Executing multiple queries: 'replByUrl'");
Repl[] repls = (await client.BulkExecute<ReplContainer>(new GraphQLParameters[]
{
new(replByUrl, new() { { "url", "https://replit.com/@amasad/TroubledPersonalBaitware" } }),
new(replByUrl, new() { { "url", "https://replit.com/@amasad/my-fun-new-app" } }),
new(replByUrl, new() { { "url", "https://replit.com/@amasad/comic-sans" } })
}))?.Select(data => data.Repl).ToArray();
Console.WriteLine($"Retrieved {repls.Length} repls back");
foreach (Repl repl in repls) Console.WriteLine($"=> {repl.Title} ({repl.Id}) was created at {repl.TimeCreated}");
Console.WriteLine("Demo finished!");
Console.ReadKey();
}
}
}