Skip to content

Commit fb657d5

Browse files
authored
refine example
1 parent 64c1d6f commit fb657d5

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

README.md

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,34 @@ Be careful when using `byte[]` in your variables object, as most JSON serializer
5151
### Execute Query/Mutation:
5252

5353
```csharp
54-
public class PersonAndFilmsResponse {
55-
public Person Person { get; set; }
54+
public class ResponseType
55+
{
56+
public PersonType Person { get; set; }
5657
}
5758

58-
public class Person {
59+
public class PersonType
60+
{
5961
public string Name { get; set; }
60-
public FilmConnectionContent FilmConnection { get; set; }
62+
public FilmConnectionType FilmConnection { get; set; }
63+
}
6164

62-
public class FilmConnectionContent {
63-
public List<FilmContent> Films { get; set; }
65+
public class FilmConnectionType {
66+
public List<FilmContentType> Films { get; set; }
67+
}
6468

65-
public class FilmContent {
66-
public string Title { get; set; }
67-
}
68-
}
69+
public class FilmContentType {
70+
public string Title { get; set; }
6971
}
7072

71-
var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/", new NewtonsoftJsonSerializer());
72-
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
73+
var graphQLResponse = await graphQLClient.SendQueryAsync<ResponseType>(personAndFilmsRequest);
7374

7475
var personName = graphQLResponse.Data.Person.Name;
7576
```
7677

7778
Using the extension method for anonymously typed responses (namespace `GraphQL.Client.Abstractions`) you could achieve the same result with the following code:
7879

7980
```csharp
80-
var graphQLResponse = await graphQLClient.SendQueryAsync(personAndFilmsRequest, () => new { person = new Person()} );
81+
var graphQLResponse = await graphQLClient.SendQueryAsync(personAndFilmsRequest, () => new { person = new PersonType()} );
8182
var personName = graphQLResponse.Data.person.Name;
8283
```
8384

0 commit comments

Comments
 (0)