Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
292e7c6
make README example consistent with example project, fix default seri…
rose-a Feb 24, 2020
fec61b3
remove unnecessary code in example
rose-a Feb 24, 2020
049ed1a
create tests to cover request cancellation ( #140)
rose-a Feb 24, 2020
af10247
speed up cancellation tests
rose-a Feb 24, 2020
21dbaaf
Merge pull request #170 from graphql-dotnet/test-request-cancellation
rose-a Feb 24, 2020
a0e9a16
fix expected execution time
rose-a Feb 24, 2020
62afa73
fix cancellation test
rose-a Feb 25, 2020
53761b1
use class fixtures, fix disposal of GraphQLHttpWebSocket
rose-a Feb 25, 2020
da094ae
remove configure await
rose-a Feb 26, 2020
b218496
fix reconnect test
rose-a Mar 2, 2020
5e83a24
add debug output
rose-a Mar 3, 2020
ce40801
consolidate naming, optimize threading in websocket
rose-a Mar 4, 2020
a6dbfb9
allow 500ms for cancellation
rose-a Mar 4, 2020
b501c04
extend default timeout
rose-a Mar 4, 2020
7837edd
remove ConfigureAwait
rose-a Mar 9, 2020
2c4aec7
eliminate helpers class
rose-a Mar 9, 2020
b1888b4
eliminate incomingMessagesSubject
rose-a Mar 9, 2020
c9acd48
fix tests locally
rose-a Mar 9, 2020
3a9df0c
extend execution time in cancellation tests
rose-a Mar 9, 2020
6834eef
don't measure execution time in tests
rose-a Mar 9, 2020
80ec167
enable windows workflow for comparison
rose-a Mar 9, 2020
0a7f91d
disable windows job again
rose-a Mar 9, 2020
9fb7fbd
Merge pull request #182 from graphql-dotnet/optimize-integration-tests
rose-a Mar 9, 2020
52c8731
use a Dictionary as a base for GraphQLRequest
rose-a Mar 9, 2020
86424d5
remove dependency on Dahomey.Json, add test with extension
rose-a Mar 9, 2020
68e6b1f
fix GraphQLRequest.Equals
rose-a Mar 9, 2020
a4bcd9c
Merge pull request #183 from graphql-dotnet/base-request-on-dictionary
rose-a Mar 9, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/branches-windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Branch workflow
on:
on:
push:
branches-ignore:
- '**'
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.idea/
.vs/
.vscode/
bin/
obj/
*.user
21 changes: 9 additions & 12 deletions GraphQL.Client.sln
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "assets", "assets", "{6326E0
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Server.Test", "tests\GraphQL.Server.Test\GraphQL.Server.Test.csproj", "{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".github", ".github", "{C42106CF-F685-4F29-BC18-A70616BD68A0}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "workflows", "workflows", "{05CAF9B2-981E-40C0-AE31-5FA56E351F12}"
ProjectSection(SolutionItems) = preProject
.github\workflows\branches-ubuntu.yml = .github\workflows\branches-ubuntu.yml
.github\workflows\branches.yml = .github\workflows\branches.yml
.github\workflows\main.yml = .github\workflows\main.yml
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{D61415CA-D822-43DD-9AE7-993B8B60E855}"
EndProject
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}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Primitives", "src\GraphQL.Primitives\GraphQL.Primitives.csproj", "{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Primitives.Tests", "tests\GraphQL.Primitives.Tests\GraphQL.Primitives.Tests.csproj", "{C212983F-67DB-44EB-BFB0-5DA75A86DF55}"
Expand All @@ -68,6 +62,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GraphQL.Client.Tests.Common
EndProject
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}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{89AD33AB-64F6-4F82-822F-21DF7A10CEC0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GraphQL.Client.Example", "examples\GraphQL.Client.Example\GraphQL.Client.Example.csproj", "{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -78,10 +76,6 @@ Global
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3}.Release|Any CPU.Build.0 = Release|Any CPU
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{95D78D57-3232-491D-BAD6-F373D76EA34D}.Release|Any CPU.Build.0 = Release|Any CPU
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Debug|Any CPU.Build.0 = Debug|Any CPU
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand Down Expand Up @@ -130,14 +124,16 @@ Global
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5}.Release|Any CPU.Build.0 = Release|Any CPU
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{E95A1258-F666-4D4E-9101-E0C46F6A3CB3} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
{05CAF9B2-981E-40C0-AE31-5FA56E351F12} = {C42106CF-F685-4F29-BC18-A70616BD68A0}
{95D78D57-3232-491D-BAD6-F373D76EA34D} = {D61415CA-D822-43DD-9AE7-993B8B60E855}
{87FC440E-6A4D-47D8-9EB2-416FC31CC4A6} = {47C98B55-08F1-4428-863E-2C5C876DEEFE}
{C212983F-67DB-44EB-BFB0-5DA75A86DF55} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
{92107DF5-73DF-4371-8EB1-6734FED704AD} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
Expand All @@ -150,6 +146,7 @@ Global
{CA842D18-FC4A-4281-B1FF-080FA91887B8} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
{0D307BAD-27AE-4A5D-8764-4AA2620B01E9} = {0B0EDB0F-FF67-4B78-A8DB-B5C23E1FEE8C}
{7FFFEC00-D751-4FFC-9FD4-E91858F9A1C5} = {47C98B55-08F1-4428-863E-2C5C876DEEFE}
{6B13B87D-1EF4-485F-BC5D-891E2F4DA6CD} = {89AD33AB-64F6-4F82-822F-21DF7A10CEC0}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {387AC1AC-F90C-4EF8-955A-04D495C75AF4}
Expand Down
92 changes: 51 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,76 @@ The Library will try to follow the following standards and documents:
```csharp
var heroRequest = new GraphQLRequest {
Query = @"
{
hero {
name
}
}"
{
hero {
name
}
}"
};
```

#### OperationName and Variables Request:

```csharp
var heroAndFriendsRequest = new GraphQLRequest {
var personAndFilmsRequest = new GraphQLRequest {
Query =@"
query HeroNameAndFriends($episode: Episode) {
hero(episode: $episode) {
name
friends {
name
}
}
}",
OperationName = "HeroNameAndFriends",
Variables = new {
episode = "JEDI"
}
query PersonAndFilms($id: ID) {
person(id: $id) {
name
filmConnection {
films {
title
}
}
}
}",
OperationName = "PersonAndFilms",
Variables = new {
id = "cGVvcGxlOjE="
}
};
```

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.

### Execute Query/Mutation:

```csharp
var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");

public class HeroAndFriendsResponse {
public Hero Hero {get; set;}
public class PersonAndFilmsResponse {
public PersonContent Person { get; set; }

public class Hero {
public string Name {get; set;}
public class PersonContent {
public string Name { get; set; }
public FilmConnectionContent FilmConnection { get; set; }

public List<Hero> Friends {get; set;}
public class FilmConnectionContent {
public List<FilmContent> Films { get; set; }

public class FilmContent {
public string Title { get; set; }
}
}
}
}

var graphQLResponse = await graphQLClient.SendQueryAsync<HeroAndFriendsResponse>(heroAndFriendsRequest);
var graphQLResponse = await graphQLClient.SendQueryAsync<PersonAndFilmsResponse>(personAndFilmsRequest);

var heroName = graphQLResponse.Data.Hero.Name;
var personName = graphQLResponse.Data.Person.Name;
```



### Use Subscriptions

```csharp
public class UserJoinedSubscriptionResult {
public ChatUser UserJoined { get; set; }
public ChatUser UserJoined { get; set; }

public class ChatUser {
public string DisplayName { get; set; }
public string Id { get; set; }
}
public class ChatUser {
public string DisplayName { get; set; }
public string Id { get; set; }
}
}
```

Expand All @@ -84,21 +94,21 @@ public class UserJoinedSubscriptionResult {
```csharp
var userJoinedRequest = new GraphQLRequest {
Query = @"
subscription {
userJoined{
displayName
id
}
}"
subscription {
userJoined{
displayName
id
}
}"
};

IObservable<GraphQLResponse<UserJoinedSubscriptionResult>> subscriptionStream
= client.CreateSubscriptionStream<UserJoinedSubscriptionResult>(userJoinedRequest);
= client.CreateSubscriptionStream<UserJoinedSubscriptionResult>(userJoinedRequest);

var subscription = subscriptionStream.Subscribe(response =>
{
Console.WriteLine($"user '{response.Data.UserJoined.DisplayName}' joined")
});
{
Console.WriteLine($"user '{response.Data.UserJoined.DisplayName}' joined")
});
```

#### End Subscription
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="3.1.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\GraphQL.Client\GraphQL.Client.csproj" />
<ProjectReference Include="..\..\tests\GraphQL.Server.Test\GraphQL.Server.Test.csproj" />
</ItemGroup>

</Project>
21 changes: 21 additions & 0 deletions examples/GraphQL.Client.Example/PersonAndFilmsResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace GraphQL.Client.Http.Examples
{
public class PersonAndFilmsResponse {
public PersonContent Person { get; set; }

public class PersonContent {
public string Name { get; set; }
public FilmConnectionContent FilmConnection { get; set; }

public class FilmConnectionContent {
public List<FilmContent> Films { get; set; }

public class FilmContent {
public string Title { get; set; }
}
}
}
}
}
48 changes: 48 additions & 0 deletions examples/GraphQL.Client.Example/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Linq;
using System.Text.Json;
using System.Threading.Tasks;
using GraphQL.Client.Serializer.Newtonsoft;

namespace GraphQL.Client.Http.Examples {

public class Program {

public static async Task Main(string[] args) {

using var graphQLClient = new GraphQLHttpClient("https://swapi.apis.guru/");

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();
}

}
}
41 changes: 0 additions & 41 deletions examples/GraphQL.Client.Http.Examples/Program.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,34 @@ namespace GraphQL.Client.Abstractions.Websocket {
/// <summary>
/// A Subscription Request
/// </summary>
public class GraphQLWebSocketRequest : IEquatable<GraphQLWebSocketRequest> {
public class GraphQLWebSocketRequest : Dictionary<string, object>, IEquatable<GraphQLWebSocketRequest> {
public const string IdKey = "id";
public const string TypeKey = "type";
public const string PayloadKey = "payload";

/// <summary>
/// The Identifier of the Response
/// </summary>
[DataMember(Name = IdKey)]
public virtual string Id { get; set; }
public string Id {
get => ContainsKey(IdKey) ? (string)this[IdKey] : null;
set => this[IdKey] = value;
}

/// <summary>
/// The Type of the Request
/// </summary>
[DataMember(Name = TypeKey)]
public virtual string Type { get; set; }
public string Type {
get => ContainsKey(TypeKey) ? (string)this[TypeKey] : null;
set => this[TypeKey] = value;
}

/// <summary>
/// The payload of the websocket request
/// </summary>
[DataMember(Name = PayloadKey)]
public virtual GraphQLRequest Payload { get; set; }
public GraphQLRequest Payload {
get => ContainsKey(PayloadKey) ? (GraphQLRequest) this[PayloadKey] : null;
set => this[PayloadKey] = value;
}

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

Expand Down
Loading