forked from graphql-dotnet/graphql-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
50 lines (45 loc) · 1.58 KB
/
Copy pathProgram.cs
File metadata and controls
50 lines (45 loc) · 1.58 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
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using GraphQL.Client.Http;
using GraphQL.Client.Serializer.Newtonsoft;
namespace GraphQL.Client.Example
{
public class Program
{
public static async Task Main()
{
using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/", new NewtonsoftJsonSerializer());
var personAndFilmsRequest = new GraphQLRequest
{
Query = @"
query PersonAndFilms($id: ID) {
person(id: $id) {
name
filmConnection {
films {
title
}
}
}
}",
OperationName = "PersonAndFilms",
Variables = new
{
id = "cGVvcGxlOjE="
}
};
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
Console.WriteLine("raw response:");
Console.WriteLine(JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true }));
Console.WriteLine();
Console.WriteLine($"Name: {graphQLResponse.Data.Person.Name}");
var films = string.Join(", ", graphQLResponse.Data.Person.FilmConnection.Films.Select(f => f.Title));
Console.WriteLine($"Films: {films}");
Console.WriteLine();
Console.WriteLine("Press any key to quit...");
Console.ReadKey();
}
}
}