Skip to content

Commit b5750ed

Browse files
authored
Merge pull request #184 from graphql-dotnet/develop
Release v2.1.1
2 parents 592db06 + a4bcd9c commit b5750ed

File tree

49 files changed

+1325
-971
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+1325
-971
lines changed

.github/workflows/branches-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Branch workflow
2-
on:
2+
on:
33
push:
44
branches-ignore:
55
- '**'

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
.idea/
22
.vs/
3+
.vscode/
34
bin/
45
obj/
56
*.user

GraphQL.Client.sln

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{6326E0
3131
EndProject
3232
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Server.Test", "tests\GraphQL.Server.Test\GraphQL.Server.Test.csproj", "{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}"
3333
EndProject
34-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{C42106CF-F685-4F29-BC18-A70616BD68A0}"
35-
EndProject
3634
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{05CAF9B2-981E-40C0-AE31-5FA56E351F12}"
3735
ProjectSection(SolutionItems) = preProject
3836
.github\workflows\branches-ubuntu.yml = .github\workflows\branches-ubuntu.yml
3937
.github\workflows\branches.yml = .github\workflows\branches.yml
4038
.github\workflows\main.yml = .github\workflows\main.yml
4139
EndProjectSection
4240
EndProject
43-
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{D61415CA-D822-43DD-9AE7-993B8B60E855}"
44-
EndProject
45-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Http.Examples", "examples\GraphQL.Client.Http.Examples\GraphQL.Client.Http.Examples.csproj", "{95D78D57-3232-491D-BAD6-F373D76EA34D}"
46-
EndProject
4741
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Primitives", "src\GraphQL.Primitives\GraphQL.Primitives.csproj", "{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}"
4842
EndProject
4943
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Primitives.Tests", "tests\GraphQL.Primitives.Tests\GraphQL.Primitives.Tests.csproj", "{C212983F-67DB-44EB-BFB0-5DA75A86DF55}"
@@ -68,6 +62,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Tests.Common
6862
EndProject
6963
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Serializer.SystemTextJson", "src\GraphQL.Client.Serializer.SystemTextJson\GraphQL.Client.Serializer.SystemTextJson.csproj", "{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}"
7064
EndProject
65+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{89AD33AB-64F6-4F82-822F-21DF7A10CEC0}"
66+
EndProject
67+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL.Client.Example", "examples\GraphQL.Client.Example\GraphQL.Client.Example.csproj", "{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}"
68+
EndProject
7169
Global
7270
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7371
Debug|Any CPU = Debug|Any CPU
@@ -78,10 +76,6 @@ Global
7876
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
7977
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
8078
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Release|Any CPU.Build.0 = Release|Any CPU
81-
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
82-
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Debug|Any CPU.Build.0 = Debug|Any CPU
83-
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Release|Any CPU.ActiveCfg = Release|Any CPU
84-
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Release|Any CPU.Build.0 = Release|Any CPU
8579
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
8680
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
8781
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -130,14 +124,16 @@ Global
130124
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
131125
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
132126
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Release|Any CPU.Build.0 = Release|Any CPU
127+
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
128+
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
129+
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
130+
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Release|Any CPU.Build.0 = Release|Any CPU
133131
EndGlobalSection
134132
GlobalSection(SolutionProperties) = preSolution
135133
HideSolutionNode = FALSE
136134
EndGlobalSection
137135
GlobalSection(NestedProjects) = preSolution
138136
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
139-
{05CAF9B2-981E-40C0-AE31-5FA56E351F12} = {C42106CF-F685-4F29-BC18-A70616BD68A0}
140-
{95D78D57-3232-491D-BAD6-F373D76EA34D} = {D61415CA-D822-43DD-9AE7-993B8B60E855}
141137
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6} = {47C98B55-08F1-4428-863E-2C5C876DEEFE}
142138
{C212983F-67DB-44EB-BFB0-5DA75A86DF55} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
143139
{92107DF5-73DF-4371-8EB1-6734FED704AD} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
@@ -150,6 +146,7 @@ Global
150146
{CA842D18-FC4A-4281-B1FF-080FA91887B8} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
151147
{0D307BAD-27AE-4A5D-8764-4AA2620B01E9} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
152148
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5} = {47C98B55-08F1-4428-863E-2C5C876DEEFE}
149+
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD} = {89AD33AB-64F6-4F82-822F-21DF7A10CEC0}
153150
EndGlobalSection
154151
GlobalSection(ExtensibilityGlobals) = postSolution
155152
SolutionGuid = {387AC1AC-F90C-4EF8-955A-04D495C75AF4}

README.md

Lines changed: 51 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,66 +16,76 @@ The Library will try to follow the following standards and documents:
1616
```csharp
1717
var heroRequest = new GraphQLRequest {
1818
Query = @"
19-
{
20-
hero {
21-
name
22-
}
23-
}"
19+
{
20+
hero {
21+
name
22+
}
23+
}"
2424
};
2525
```
2626

2727
#### OperationName and Variables Request:
28+
2829
```csharp
29-
var heroAndFriendsRequest = new GraphQLRequest {
30+
var personAndFilmsRequest = new GraphQLRequest {
3031
Query =@"
31-
query HeroNameAndFriends($episode: Episode) {
32-
hero(episode: $episode) {
33-
name
34-
friends {
35-
name
36-
}
37-
}
38-
}",
39-
OperationName = "HeroNameAndFriends",
40-
Variables = new {
41-
episode = "JEDI"
42-
}
32+
query PersonAndFilms($id: ID) {
33+
person(id: $id) {
34+
name
35+
filmConnection {
36+
films {
37+
title
38+
}
39+
}
40+
}
41+
}",
42+
OperationName = "PersonAndFilms",
43+
Variables = new {
44+
id = "cGVvcGxlOjE="
45+
}
4346
};
4447
```
4548

4649
Be careful when using `byte[]` in your variables object, as most JSON serializers will treat that as binary data! If you really need to send a *list of bytes* with a `byte[]` as a source, then convert it to a `List<byte>` first, which will tell the serializer to output a list of numbers instead of a base64-encoded string.
4750

4851
### Execute Query/Mutation:
52+
4953
```csharp
5054
var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");
5155

52-
public class HeroAndFriendsResponse {
53-
public Hero Hero {get; set;}
56+
public class PersonAndFilmsResponse {
57+
public PersonContent Person { get; set; }
5458

55-
public class Hero {
56-
public string Name {get; set;}
59+
public class PersonContent {
60+
public string Name { get; set; }
61+
public FilmConnectionContent FilmConnection { get; set; }
5762

58-
public List<Hero> Friends {get; set;}
63+
public class FilmConnectionContent {
64+
public List<FilmContent> Films { get; set; }
65+
66+
public class FilmContent {
67+
public string Title { get; set; }
68+
}
69+
}
5970
}
6071
}
6172

62-
var graphQLResponse = await graphQLClient.SendQueryAsync<HeroAndFriendsResponse>(heroAndFriendsRequest);
73+
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
6374

64-
var heroName = graphQLResponse.Data.Hero.Name;
75+
var personName = graphQLResponse.Data.Person.Name;
6576
```
6677

6778

68-
6979
### Use Subscriptions
7080

7181
```csharp
7282
public class UserJoinedSubscriptionResult {
73-
public ChatUser UserJoined { get; set; }
83+
public ChatUser UserJoined { get; set; }
7484

75-
public class ChatUser {
76-
public string DisplayName { get; set; }
77-
public string Id { get; set; }
78-
}
85+
public class ChatUser {
86+
public string DisplayName { get; set; }
87+
public string Id { get; set; }
88+
}
7989
}
8090
```
8191

@@ -84,21 +94,21 @@ public class UserJoinedSubscriptionResult {
8494
```csharp
8595
var userJoinedRequest = new GraphQLRequest {
8696
Query = @"
87-
subscription {
88-
userJoined{
89-
displayName
90-
id
91-
}
92-
}"
97+
subscription {
98+
userJoined{
99+
displayName
100+
id
101+
}
102+
}"
93103
};
94104

95105
IObservable<GraphQLResponse<UserJoinedSubscriptionResult>> subscriptionStream
96-
= client.CreateSubscriptionStream<UserJoinedSubscriptionResult>(userJoinedRequest);
106+
= client.CreateSubscriptionStream<UserJoinedSubscriptionResult>(userJoinedRequest);
97107

98108
var subscription = subscriptionStream.Subscribe(response =>
99-
{
100-
Console.WriteLine($"user '{response.Data.UserJoined.DisplayName}' joined")
101-
});
109+
{
110+
Console.WriteLine($"user '{response.Data.UserJoined.DisplayName}' joined")
111+
});
102112
```
103113

104114
#### End Subscription

examples/GraphQL.Client.Http.Examples/GraphQL.Client.Http.Examples.csproj renamed to examples/GraphQL.Client.Example/GraphQL.Client.Example.csproj

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,8 @@
66
<IsPackable>false</IsPackable>
77
</PropertyGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
11-
</ItemGroup>
12-
139
<ItemGroup>
1410
<ProjectReference Include="..\..\src\GraphQL.Client\GraphQL.Client.csproj" />
15-
<ProjectReference Include="..\..\tests\GraphQL.Server.Test\GraphQL.Server.Test.csproj" />
1611
</ItemGroup>
1712

1813
</Project>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System.Collections.Generic;
2+
3+
namespace GraphQL.Client.Http.Examples
4+
{
5+
public class PersonAndFilmsResponse {
6+
public PersonContent Person { get; set; }
7+
8+
public class PersonContent {
9+
public string Name { get; set; }
10+
public FilmConnectionContent FilmConnection { get; set; }
11+
12+
public class FilmConnectionContent {
13+
public List<FilmContent> Films { get; set; }
14+
15+
public class FilmContent {
16+
public string Title { get; set; }
17+
}
18+
}
19+
}
20+
}
21+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
using System;
2+
using System.Linq;
3+
using System.Text.Json;
4+
using System.Threading.Tasks;
5+
using GraphQL.Client.Serializer.Newtonsoft;
6+
7+
namespace GraphQL.Client.Http.Examples {
8+
9+
public class Program {
10+
11+
public static async Task Main(string[] args) {
12+
13+
using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");
14+
15+
var personAndFilmsRequest = new GraphQLRequest {
16+
Query = @"
17+
query PersonAndFilms($id: ID) {
18+
person(id: $id) {
19+
name
20+
filmConnection {
21+
films {
22+
title
23+
}
24+
}
25+
}
26+
}",
27+
OperationName = "PersonAndFilms",
28+
Variables = new {
29+
id = "cGVvcGxlOjE="
30+
}
31+
};
32+
33+
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);
34+
Console.WriteLine("raw response:");
35+
Console.WriteLine(JsonSerializer.Serialize(graphQLResponse, new JsonSerializerOptions { WriteIndented = true }));
36+
37+
Console.WriteLine();
38+
Console.WriteLine($"Name: {graphQLResponse.Data.Person.Name}" );
39+
var films = string.Join(", ", graphQLResponse.Data.Person.FilmConnection.Films.Select(f => f.Title));
40+
Console.WriteLine($"Films: {films}");
41+
42+
Console.WriteLine();
43+
Console.WriteLine("Press any key to quit...");
44+
Console.ReadKey();
45+
}
46+
47+
}
48+
}

examples/GraphQL.Client.Http.Examples/Program.cs

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/GraphQL.Client.Abstractions.Websocket/GraphQLWebSocketRequest.cs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,34 @@ namespace GraphQL.Client.Abstractions.Websocket {
88
/// <summary>
99
/// A Subscription Request
1010
/// </summary>
11-
public class GraphQLWebSocketRequest : IEquatable<GraphQLWebSocketRequest> {
11+
public class GraphQLWebSocketRequest : Dictionary<string, object>, IEquatable<GraphQLWebSocketRequest> {
1212
public const string IdKey = "id";
1313
public const string TypeKey = "type";
1414
public const string PayloadKey = "payload";
1515

1616
/// <summary>
1717
/// The Identifier of the Response
1818
/// </summary>
19-
[DataMember(Name = IdKey)]
20-
public virtual string Id { get; set; }
19+
public string Id {
20+
get => ContainsKey(IdKey) ? (string)this[IdKey] : null;
21+
set => this[IdKey] = value;
22+
}
2123

2224
/// <summary>
2325
/// The Type of the Request
2426
/// </summary>
25-
[DataMember(Name = TypeKey)]
26-
public virtual string Type { get; set; }
27+
public string Type {
28+
get => ContainsKey(TypeKey) ? (string)this[TypeKey] : null;
29+
set => this[TypeKey] = value;
30+
}
2731

2832
/// <summary>
2933
/// The payload of the websocket request
3034
/// </summary>
31-
[DataMember(Name = PayloadKey)]
32-
public virtual GraphQLRequest Payload { get; set; }
35+
public GraphQLRequest Payload {
36+
get => ContainsKey(PayloadKey) ? (GraphQLRequest) this[PayloadKey] : null;
37+
set => this[PayloadKey] = value;
38+
}
3339

3440
private TaskCompletionSource<bool> _tcs = new TaskCompletionSource<bool>();
3541

0 commit comments

Comments
 (0)