ChilliCream / ChilliCream/graphql-platform
MongoDB integration not filtering child collections
@PascalSenn is already working on this.
Since Jul 12, 2022.
- Dominant language
- C#
- Stars
- 5.8k
- Forks
- 810
- Avg merge
- 15h 39m
- Merged PRs (30d)
- 98
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I have a simple document that has a collection (modelReferences), and within it that I would like to filter the modelReferences by their Id property, however filtering at these child collections does not appear to work.
Note: When the exact same model is configured with the EFCore integration it works as expected, but not using MongoDb integratation.
Here is a simple example, of an unfiltered query on modelReferences child collection:
{
gatewayServicesGatewayDefinitions {
items{
name name
modelReferences {
id
}
}
}
}
Resultant data :
{
"data": {
"gatewayServicesGatewayDefinitions": {
"items": [
{
"name": "Test",
"modelReferences": [
{
"id": "f00554bc-fcef-417c-baee-9234534cb6bd"
}
]
}
]
}
}
}
And with the filter in which the id does not exist:"
{
gatewayServicesGatewayDefinitions {
items{
name name
modelReferences (where: {id:{eq:"f00554bc-fcef-417c-baee-9234534cb6be"}}) {
id
}
}
}
}
Should return no data modelReferences collection items, as that ID does not exist, however it returns everything as if is unfiltered:
{
"data": {
"gatewayServicesGatewayDefinitions": {
"items": [
{
"name": "Test",
"modelReferences": [
{
"id": "f00554bc-fcef-417c-baee-9234534cb6bd"
}
]
}
]
}
}
}
Here is the GraphQL configuration:
builder.Services.AddGraphQLServer()
.AddAuthorization()
.AddType<ErrorResponse>()
.AddType<AggregateEvent>()
.AddType<GatewayServicesGatewayDefinitionSM.GatewayDefinition>()
.AddQueryType()
.AddTypeExtension<GatewayDefinitionGraphQLQuery>()
.AddMutationType()
.AddTypeExtension<GatewayDefinitionGraphQLMutation>()
.AddMongoDbFiltering()
.AddMongoDbSorting()
.AddMongoDbProjections()
.AddMongoDbPagingProviders();
Here is the Query Definition:
public partial class GatewayDefinitionGraphQLQuery
{
[UseFirstOrDefault]
public IExecutable<GatewayServicesGatewayDefinitionSM.GatewayDefinition> GetGatewayServicesGatewayDefinition([Service] IMongoCollection<GatewayServicesGatewayDefinitionSM.GatewayDefinition> collection, Guid id)
{
return collection.Find(x => x.Id == id).AsExecutable();
}
[UseOffsetPaging(IncludeTotalCount = false, DefaultPageSize = 10)]
[UseProjection]
[UseSorting]
[UseFiltering]
public IExecutable<GatewayServicesGatewayDefinitionSM.GatewayDefinition> GetGatewayServicesGatewayDefinitions([Service] IMongoCollection<GatewayServicesGatewayDefinitionSM.GatewayDefinition> collection)
{
return collection.AsExecutable();
}
}
Here is the model definition:
[HotChocolate.AspNetCore.Authorization.Authorize]
[GraphQLName("gatewayServices_gatewayDefinition")]
[Serializable]
[BsonIgnoreExtraElements]
public class GatewayDefinition
{
public string Name { get; set; } = string.Empty;
[HotChocolate.Data.UseFiltering]
[HotChocolate.Data.UseSorting]
public List<GatewayServicesGatewayDefinitionSM.ModelReference> ModelReferences { get; set; } = new();
[BsonId(IdGenerator = typeof(GuidGenerator)), BsonRepresentation(BsonType.String)]
[DataMember(Name = "id")]
public System.Guid? Id { get; set; } = Guid.Empty;
}
Here is the Node Resolver:
public class GatewayDefinitionNodeResolver
{
public Task<GatewayServicesGatewayDefinitionSM.GatewayDefinition> ResolveAsync([Service] IMongoCollection<GatewayServicesGatewayDefinitionSM.GatewayDefinition> collection, Guid id)
{
return collection.Find(x => x.Id == id).FirstOrDefaultAsync();
}
}
Here is the related child type, "ModelRerference" that I am trying to filter:
[HotChocolate.AspNetCore.Authorization.Authorize]
[GraphQLName("gatewayServices_modelReference")]
[Serializable]
[BsonIgnoreExtraElements]
public class ModelReference
{
public System.Guid DomainModelId { get; set; } = Guid.Empty;
public int Depth { get; set; } = 2;
[BsonId(IdGenerator = typeof(GuidGenerator)), BsonRepresentation(BsonType.String)]
public System.Guid? Id { get; set; } = Guid.Empty;
}
Steps to reproduce
- Apply same code as above
Relevant log output
No response
Additional Context?
No response
Product
Hot Chocolate
Version
12.8.2
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.