diff --git a/src/GraphQL.Client.LocalExecution/GraphQL.Client.LocalExecution.csproj b/src/GraphQL.Client.LocalExecution/GraphQL.Client.LocalExecution.csproj
index e8e162cb..d69fc21b 100644
--- a/src/GraphQL.Client.LocalExecution/GraphQL.Client.LocalExecution.csproj
+++ b/src/GraphQL.Client.LocalExecution/GraphQL.Client.LocalExecution.csproj
@@ -8,9 +8,9 @@
-
-
-
+
+
+
diff --git a/src/GraphQL.Client.LocalExecution/GraphQLLocalExecutionClient.cs b/src/GraphQL.Client.LocalExecution/GraphQLLocalExecutionClient.cs
index 65098ae8..f2c077f6 100644
--- a/src/GraphQL.Client.LocalExecution/GraphQLLocalExecutionClient.cs
+++ b/src/GraphQL.Client.LocalExecution/GraphQLLocalExecutionClient.cs
@@ -9,6 +9,7 @@
using System.Threading.Tasks;
using GraphQL.Client.Abstractions;
using GraphQL.Client.Serializer.Newtonsoft;
+using GraphQL.NewtonsoftJson;
using GraphQL.Subscription;
using GraphQL.Types;
using Newtonsoft.Json;
@@ -41,6 +42,7 @@ public class GraphQLLocalExecutionClient : IGraphQLClient where TSchema
public IGraphQLJsonSerializer Serializer { get; }
private readonly DocumentExecuter _documentExecuter;
+ private readonly DocumentWriter _documentWriter;
public GraphQLLocalExecutionClient(TSchema schema, IGraphQLJsonSerializer serializer)
{
@@ -50,6 +52,7 @@ public GraphQLLocalExecutionClient(TSchema schema, IGraphQLJsonSerializer serial
if (!Schema.Initialized)
Schema.Initialize();
_documentExecuter = new DocumentExecuter();
+ _documentWriter = new DocumentWriter();
}
public void Dispose() { }
@@ -109,12 +112,13 @@ private async Task ExecuteAsync(GraphQLRequest request, Cancell
return result;
}
- private Task> ExecutionResultToGraphQLResponse(ExecutionResult executionResult, CancellationToken cancellationToken = default)
+ private async Task> ExecutionResultToGraphQLResponse(ExecutionResult executionResult, CancellationToken cancellationToken = default)
{
+ string json = await _documentWriter.WriteToStringAsync(executionResult);
// serialize result into utf8 byte stream
- var resultStream = new MemoryStream(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(executionResult, _variablesSerializerSettings)));
+ var resultStream = new MemoryStream(Encoding.UTF8.GetBytes(json));
// deserialize using the provided serializer
- return Serializer.DeserializeFromUtf8StreamAsync(resultStream, cancellationToken);
+ return await Serializer.DeserializeFromUtf8StreamAsync(resultStream, cancellationToken);
}
#endregion
diff --git a/tests/GraphQL.Client.Serializer.Tests/BaseSerializerTest.cs b/tests/GraphQL.Client.Serializer.Tests/BaseSerializerTest.cs
index 53cba0c1..863974ae 100644
--- a/tests/GraphQL.Client.Serializer.Tests/BaseSerializerTest.cs
+++ b/tests/GraphQL.Client.Serializer.Tests/BaseSerializerTest.cs
@@ -16,6 +16,7 @@
using GraphQL.Client.Tests.Common.Chat.Schema;
using GraphQL.Client.Tests.Common.Helpers;
using GraphQL.Client.Tests.Common.StarWars;
+using GraphQL.Client.Tests.Common.StarWars.TestData;
using Xunit;
namespace GraphQL.Client.Serializer.Tests
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/AddMessageVariables.cs b/tests/GraphQL.Client.Tests.Common/Chat/AddMessageVariables.cs
index 0a330007..887c55cd 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/AddMessageVariables.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/AddMessageVariables.cs
@@ -12,7 +12,7 @@ public class AddMessageInput
public string Content { get; set; }
- public DateTime SentAt { get; set; }
+ public string SentAt { get; set; }
}
}
}
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/GraphQLClientChatExtensions.cs b/tests/GraphQL.Client.Tests.Common/Chat/GraphQLClientChatExtensions.cs
index f4417860..07648f06 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/GraphQLClientChatExtensions.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/GraphQLClientChatExtensions.cs
@@ -10,7 +10,7 @@ public static class GraphQLClientChatExtensions
@"mutation($input: MessageInputType){
addMessage(message: $input){
content
- }
+ }
}";
public static Task> AddMessageAsync(this IGraphQLClient client, string message)
@@ -21,7 +21,7 @@ public static Task> AddMessageAsync(th
{
FromId = "2",
Content = message,
- SentAt = DateTime.Now
+ SentAt = DateTime.Now.ToString("s")
}
};
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatMutation.cs b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatMutation.cs
index 1d2cdd28..b005ebc2 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatMutation.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatMutation.cs
@@ -36,7 +36,7 @@ public MessageInputType()
{
Field("fromId");
Field("content");
- Field("sentAt");
+ Field("sentAt");
}
}
}
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSchema.cs b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSchema.cs
index 49126f8a..fbdfedf1 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSchema.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSchema.cs
@@ -1,13 +1,16 @@
+using System;
+using Microsoft.Extensions.DependencyInjection;
+
namespace GraphQL.Client.Tests.Common.Chat.Schema
{
public class ChatSchema : Types.Schema
{
- public ChatSchema(IDependencyResolver resolver)
- : base(resolver)
+ public ChatSchema(IServiceProvider services)
+ : base(services)
{
- Query = resolver.Resolve();
- Mutation = resolver.Resolve();
- Subscription = resolver.Resolve();
+ Query = services.GetRequiredService();
+ Mutation = services.GetRequiredService();
+ Subscription = services.GetRequiredService();
}
}
}
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSubscriptions.cs b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSubscriptions.cs
index f0d08efb..b15ba334 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSubscriptions.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/Schema/ChatSubscriptions.cs
@@ -61,9 +61,9 @@ public ChatSubscriptions(IChat chat)
});
}
- private IObservable SubscribeById(ResolveEventStreamContext context)
+ private IObservable SubscribeById(IResolveEventStreamContext context)
{
- var messageContext = context.UserContext.As();
+ var messageContext = (MessageHandlingContext) context.UserContext;
var user = messageContext.Get("user");
var sub = "Anonymous";
@@ -76,16 +76,16 @@ private IObservable SubscribeById(ResolveEventStreamContext context)
return messages.Where(message => message.From.Id == id);
}
- private Message ResolveMessage(ResolveFieldContext context)
+ private Message ResolveMessage(IResolveFieldContext context)
{
var message = context.Source as Message;
return message;
}
- private IObservable Subscribe(ResolveEventStreamContext context)
+ private IObservable Subscribe(IResolveEventStreamContext context)
{
- var messageContext = context.UserContext.As();
+ var messageContext = (MessageHandlingContext) context.UserContext;
var user = messageContext.Get("user");
var sub = "Anonymous";
diff --git a/tests/GraphQL.Client.Tests.Common/Chat/Schema/MessageType.cs b/tests/GraphQL.Client.Tests.Common/Chat/Schema/MessageType.cs
index 2636390c..e72a0067 100644
--- a/tests/GraphQL.Client.Tests.Common/Chat/Schema/MessageType.cs
+++ b/tests/GraphQL.Client.Tests.Common/Chat/Schema/MessageType.cs
@@ -12,7 +12,7 @@ public MessageType()
Field(o => o.From, false, typeof(MessageFromType)).Resolve(ResolveFrom);
}
- private MessageFrom ResolveFrom(ResolveFieldContext context)
+ private MessageFrom ResolveFrom(IResolveFieldContext context)
{
var message = context.Source;
return message.From;
diff --git a/tests/GraphQL.Client.Tests.Common/Common.cs b/tests/GraphQL.Client.Tests.Common/Common.cs
index 97dd30fe..269ea257 100644
--- a/tests/GraphQL.Client.Tests.Common/Common.cs
+++ b/tests/GraphQL.Client.Tests.Common/Common.cs
@@ -1,6 +1,6 @@
using GraphQL.Client.Tests.Common.Chat.Schema;
-using GraphQL.StarWars;
-using GraphQL.StarWars.Types;
+using GraphQL.Client.Tests.Common.StarWars;
+using GraphQL.Client.Tests.Common.StarWars.Types;
using Microsoft.Extensions.DependencyInjection;
namespace GraphQL.Client.Tests.Common
@@ -13,7 +13,6 @@ public static class Common
public static StarWarsSchema GetStarWarsSchema()
{
var services = new ServiceCollection();
- services.AddTransient(provider => new FuncDependencyResolver(provider.GetService));
services.AddStarWarsSchema();
return services.BuildServiceProvider().GetRequiredService();
}
@@ -21,7 +20,6 @@ public static StarWarsSchema GetStarWarsSchema()
public static ChatSchema GetChatSchema()
{
var services = new ServiceCollection();
- services.AddTransient(provider => new FuncDependencyResolver(provider.GetService));
services.AddChatSchema();
return services.BuildServiceProvider().GetRequiredService();
}
diff --git a/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj b/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj
index 6aeff4a3..24cbf419 100644
--- a/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj
+++ b/tests/GraphQL.Client.Tests.Common/GraphQL.Client.Tests.Common.csproj
@@ -7,13 +7,10 @@
-
-
-
-
-
-
-
+
+
+
+
diff --git a/tests/GraphQL.Client.Tests.Common/StarWars/Extensions/ResolveFieldContextExtensions.cs b/tests/GraphQL.Client.Tests.Common/StarWars/Extensions/ResolveFieldContextExtensions.cs
new file mode 100644
index 00000000..44ba5895
--- /dev/null
+++ b/tests/GraphQL.Client.Tests.Common/StarWars/Extensions/ResolveFieldContextExtensions.cs
@@ -0,0 +1,65 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using GraphQL.Builders;
+using GraphQL.Client.Tests.Common.StarWars.Types;
+using GraphQL.Types.Relay.DataObjects;
+
+namespace GraphQL.Client.Tests.Common.StarWars.Extensions
+{
+ public static class ResolveFieldContextExtensions
+ {
+ public static Connection GetPagedResults(this IResolveConnectionContext context, StarWarsData data, List ids) where U : StarWarsCharacter
+ {
+ List idList;
+ List list;
+ string cursor;
+ string endCursor;
+ var pageSize = context.PageSize ?? 20;
+
+ if (context.IsUnidirectional || context.After != null || context.Before == null)
+ {
+ if (context.After != null)
+ {
+ idList = ids
+ .SkipWhile(x => !Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(x)).Equals(context.After))
+ .Take(context.First ?? pageSize).ToList();
+ }
+ else
+ {
+ idList = ids
+ .Take(context.First ?? pageSize).ToList();
+ }
+ }
+ else
+ {
+ if (context.Before != null)
+ {
+ idList = ids.Reverse()
+ .SkipWhile(x => !Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(x)).Equals(context.Before))
+ .Take(context.Last ?? pageSize).ToList();
+ }
+ else
+ {
+ idList = ids.Reverse()
+ .Take(context.Last ?? pageSize).ToList();
+ }
+ }
+
+ list = data.GetCharactersAsync(idList).Result as List ?? throw new InvalidOperationException($"GetCharactersAsync method should return list of '{typeof(U).Name}' items.");
+ cursor = list.Count > 0 ? list.Last().Cursor : null;
+ endCursor = ids.Count > 0 ? Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(ids.Last())) : null;
+
+ return new Connection
+ {
+ Edges = list.Select(x => new Edge { Cursor = x.Cursor, Node = x }).ToList(),
+ TotalCount = list.Count,
+ PageInfo = new PageInfo
+ {
+ EndCursor = endCursor,
+ HasNextPage = endCursor == null ? false : cursor != endCursor,
+ }
+ };
+ }
+ }
+}
diff --git a/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsData.cs b/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsData.cs
new file mode 100644
index 00000000..f561ed87
--- /dev/null
+++ b/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsData.cs
@@ -0,0 +1,90 @@
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
+using GraphQL.Client.Tests.Common.StarWars.Types;
+
+namespace GraphQL.Client.Tests.Common.StarWars
+{
+ public class StarWarsData
+ {
+ private readonly List _characters = new List();
+
+ public StarWarsData()
+ {
+ _characters.Add(new Human
+ {
+ Id = "1",
+ Name = "Luke",
+ Friends = new List { "3", "4" },
+ AppearsIn = new[] { 4, 5, 6 },
+ HomePlanet = "Tatooine",
+ Cursor = "MQ=="
+ });
+ _characters.Add(new Human
+ {
+ Id = "2",
+ Name = "Vader",
+ AppearsIn = new[] { 4, 5, 6 },
+ HomePlanet = "Tatooine",
+ Cursor = "Mg=="
+ });
+
+ _characters.Add(new Droid
+ {
+ Id = "3",
+ Name = "R2-D2",
+ Friends = new List { "1", "4" },
+ AppearsIn = new[] { 4, 5, 6 },
+ PrimaryFunction = "Astromech",
+ Cursor = "Mw=="
+ });
+ _characters.Add(new Droid
+ {
+ Id = "4",
+ Name = "C-3PO",
+ AppearsIn = new[] { 4, 5, 6 },
+ PrimaryFunction = "Protocol",
+ Cursor = "NA=="
+ });
+ }
+
+ public IEnumerable GetFriends(StarWarsCharacter character)
+ {
+ if (character == null)
+ {
+ return null;
+ }
+
+ var friends = new List();
+ var lookup = character.Friends;
+ if (lookup != null)
+ {
+ foreach (var c in _characters.Where(h => lookup.Contains(h.Id)))
+ friends.Add(c);
+ }
+ return friends;
+ }
+
+ public StarWarsCharacter AddCharacter(StarWarsCharacter character)
+ {
+ character.Id = _characters.Count.ToString();
+ _characters.Add(character);
+ return character;
+ }
+
+ public Task GetHumanByIdAsync(string id)
+ {
+ return Task.FromResult(_characters.FirstOrDefault(h => h.Id == id && h is Human) as Human);
+ }
+
+ public Task GetDroidByIdAsync(string id)
+ {
+ return Task.FromResult(_characters.FirstOrDefault(h => h.Id == id && h is Droid) as Droid);
+ }
+
+ public Task> GetCharactersAsync(List guids)
+ {
+ return Task.FromResult(_characters.Where(c => guids.Contains(c.Id)).ToList());
+ }
+ }
+}
diff --git a/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsMutation.cs b/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsMutation.cs
new file mode 100644
index 00000000..cd577688
--- /dev/null
+++ b/tests/GraphQL.Client.Tests.Common/StarWars/StarWarsMutation.cs
@@ -0,0 +1,35 @@
+using GraphQL.Client.Tests.Common.StarWars.Types;
+using GraphQL.Types;
+
+namespace GraphQL.Client.Tests.Common.StarWars
+{
+ ///
+ /// This is an example JSON request for a mutation
+ /// {
+ /// "query": "mutation ($human:HumanInput!){ createHuman(human: $human) { id name } }",
+ /// "variables": {
+ /// "human": {
+ /// "name": "Boba Fett"
+ /// }
+ /// }
+ /// }
+ ///
+ public class StarWarsMutation : ObjectGraphType