-
-
Notifications
You must be signed in to change notification settings - Fork 744
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added TypeConverter for RelayId (#3917)
- Loading branch information
1 parent
0ea46fe
commit 27af060
Showing
4 changed files
with
118 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
src/HotChocolate/MongoDb/test/Data.MongoDb.Paging.Tests/MongoDbRelayTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
using HotChocolate.Execution; | ||
using HotChocolate.Data.MongoDb.Filters; | ||
using HotChocolate.Types; | ||
using HotChocolate.Types.Pagination; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using MongoDB.Bson.Serialization.Attributes; | ||
using Snapshooter.Xunit; | ||
using System.Threading.Tasks; | ||
using MongoDB.Bson; | ||
using Xunit; | ||
|
||
namespace HotChocolate.Data.MongoDb.Paging | ||
{ | ||
public class MongoDbRelayTests | ||
{ | ||
[Fact] | ||
public async Task Return_BsonId() | ||
{ | ||
Snapshot.FullName(); | ||
|
||
IRequestExecutor executor = await new ServiceCollection() | ||
.AddTransient<OffsetPagingProvider, MongoDbOffsetPagingProvider>() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.AddType<FooType>() | ||
.AddTypeConverter<ObjectId, string>(x => x.ToString()) | ||
.BuildRequestExecutorAsync(); | ||
|
||
IExecutionResult result = await executor | ||
.ExecuteAsync(@" | ||
{ | ||
foo { | ||
id | ||
} | ||
}"); | ||
|
||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
[Fact] | ||
public async Task Return_Node() | ||
{ | ||
Snapshot.FullName(); | ||
|
||
IRequestExecutor executor = await new ServiceCollection() | ||
.AddTransient<OffsetPagingProvider, MongoDbOffsetPagingProvider>() | ||
.AddGraphQL() | ||
.AddQueryType<Query>() | ||
.AddType<FooType>() | ||
.AddTypeConverter<ObjectId, string>(x => x.ToString()) | ||
.AddTypeConverter<string, ObjectId>(x => ObjectId.Parse(x.ToString())) | ||
.EnableRelaySupport() | ||
.BuildRequestExecutorAsync(); | ||
|
||
IExecutionResult result = await executor | ||
.ExecuteAsync(@" | ||
{ | ||
node(id:""Rm9vCmQ2MGRmMTYyZWQwNzY2ZTE1Y2NlNmIxMGU="") { | ||
id | ||
} | ||
}"); | ||
|
||
result.ToJson().MatchSnapshot(); | ||
} | ||
|
||
public class Query | ||
{ | ||
public Foo GetFoo() => new Foo { Id = ObjectId.Parse("507f191e810c19729de860ea") }; | ||
} | ||
|
||
public class FooType : ObjectType<Foo> | ||
{ | ||
protected override void Configure(IObjectTypeDescriptor<Foo> descriptor) | ||
{ | ||
descriptor.ImplementsNode() | ||
.IdField(x => x.Id) | ||
.ResolveNode((_, objectId) => Task.FromResult(new Foo { Id = objectId })); | ||
} | ||
} | ||
|
||
public class Foo | ||
{ | ||
[BsonId] | ||
public ObjectId Id { get; set; } | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
....MongoDb.Paging.Tests/__snapshots__/MongoDbOffsetPagingFindFluentTests.Return_BsonId.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"data": { | ||
"foo": { | ||
"id": "Rm9vCmQ1MDdmMTkxZTgxMGMxOTcyOWRlODYwZWE=" | ||
} | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
...ta.MongoDb.Paging.Tests/__snapshots__/MongoDbOffsetPagingFindFluentTests.Return_Node.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"data": { | ||
"node": null | ||
} | ||
} |