Skip to content

Commit

Permalink
Merge pull request #184 from graphql-dotnet/develop
Browse files Browse the repository at this point in the history
Release v2.1.1
  • Loading branch information
rose-a authored Mar 9, 2020
2 parents 592db06 + a4bcd9c commit b5750ed
Show file tree
Hide file tree
Showing 49 changed files with 1,325 additions and 971 deletions.
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

0 comments on commit b5750ed

Please sign in to comment.