public async Task Should_also_fetch_referencing_contents_if_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(TestSchemas.Ref1Id, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(contentId, contentRefId); var query = CreateQuery(@" query { findMyRefSchema1Content(id: '<ID>') { id referencingMySchemaContents(top: 30, skip: 5) { id data { myLocalizedString { de_DE } } } } }", contentRefId); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(1, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), content.SchemaId.Id.ToString(), A <Q> .That.Matches(x => x.QueryAsOdata == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMyRefSchema1Content = new { id = contentRefId, referencingMySchemaContents = new[] { new { id = contentId, data = new { myLocalizedString = new { de_DE = "de-DE" } } } } } } }; AssertResult(expected, result); }
public async Task Should_cache_referenced_contents_from_flat_data_if_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(TestSchemas.Ref1Id, contentRefId, "schemaRef1Field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(contentId, contentRefId); var query = CreateQuery(@" query { findMySchemaContent(id: '<ID>') { id flatData { myReferences @cache(duration: 1000) { id } } } }", contentId); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(1, content)); var result1 = await ExecuteAsync(new ExecutionOptions { Query = query }); var result2 = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, flatData = new { myReferences = new[] { new { id = contentRefId } } } } } }; AssertResult(expected, result1); AssertResult(expected, result2); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId), A <CancellationToken> ._)) .MustHaveHappenedOnceExactly(); }
public async Task Should_return_null_if_single_content_from_another_schema() { var contentId = DomainId.NewGuid(); var content = TestContent.CreateRef(TestSchemas.Ref1Id, contentId, "ref1-field", "ref1"); var query = CreateQuery(@" query { findMySchemaContent(id: '<ID>') { id } }", contentId); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(10, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMySchemaContent = (object?)null } }; AssertResult(expected, result); }
public async Task Should_also_fetch_referencing_contents_when_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(appId, schemaId, contentId, contentRefId, DomainId.Empty); var query = @" query { findMyRefSchema1Content(id: ""<ID>"") { id referencingMySchemaContents(top: 30, skip: 5) { id data { myString { de } } } } }".Replace("<ID>", contentRefId.ToString()); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId))) .Returns(ResultList.CreateFrom(1, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), content.SchemaId.Id.ToString(), A <Q> .That.Matches(x => x.ODataQuery == "?$top=30&$skip=5" && x.Reference == contentRefId && x.NoTotal == true))) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMyRefSchema1Content = new { id = contentRefId, referencingMySchemaContents = new[] { new { id = contentId, data = new { myString = new { de = "value" } } } } } } }; AssertResult(expected, result); }
public async Task Should_also_fetch_referencing_contents_when_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(appId, schemaId, contentId, contentRefId, DomainId.Empty); var query = @" query { findMyRefSchema1Content(id: ""<ID>"") { id referencingMySchemaContents(top: 30, skip: 5) { id data { myString { de } } } } }".Replace("<ID>", contentRefId.ToString()); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <IReadOnlyList <DomainId> > ._)) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), schemaId.Id.ToString(), A <Q> .That.HasOData("?$top=30&$skip=5", contentRefId))) .Returns(ResultList.CreateFrom(1, content)); var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query }); var expected = new { data = new { findMyRefSchema1Content = new { id = contentRefId, referencingMySchemaContents = new[] { new { id = contentId, data = new { myString = new { de = "value" } } } } } } }; AssertResult(expected, result); }
public async Task Should_also_fetch_union_contents_when_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(appId, schemaId, contentId, contentRefId, DomainId.Empty); var query = @" query { findMySchemaContent(id: ""<ID>"") { id data { myUnion { iv { ... on Content { id } ... on MyRefSchema1 { data { ref1Field { iv } } } __typename } } } } }".Replace("<ID>", contentId.ToString()); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> ._)) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIds(contentId))) .Returns(ResultList.CreateFrom(1, content)); var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, data = new { myUnion = new { iv = new[] { new { id = contentRefId, data = new { ref1Field = new { iv = "ref1" } }, __typename = "MyRefSchema1" } } } } } } }; AssertResult(expected, result); }
public async Task Should_also_fetch_referenced_contents_when_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(appId, schemaId, contentId, contentRefId, DomainId.Empty); var query = @" query { findMySchemaContent(id: ""<ID>"") { id data { myReferences { iv { id data { ref1Field { iv } } } } } } }".Replace("<ID>", contentId.ToString()); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId))) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentId))) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, data = new { myReferences = new { iv = new[] { new { id = contentRefId, data = new { ref1Field = new { iv = "ref1" } } } } } } } } }; AssertResult(expected, result); }
public async Task Should_also_fetch_union_contents_if_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(TestSchemas.Ref1Id, contentRefId, "schemaRef1Field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(contentId, contentRefId); var query = CreateQuery(@" query { findMySchemaContent(id: '<ID>') { id data { myUnion { iv { ... on Content { id } ... on MyRefSchema1 { data { schemaRef1Field { iv } } } __typename } } } } }", contentId); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentRefId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <Q> .That.HasIdsWithoutTotal(contentId), A <CancellationToken> ._)) .Returns(ResultList.CreateFrom(1, content)); var result = await ExecuteAsync(new ExecutionOptions { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, data = new { myUnion = new { iv = new[] { new { id = contentRefId, data = new { schemaRef1Field = new { iv = "ref1" } }, __typename = "MyRefSchema1" } } } } } } }; AssertResult(expected, result); }
public async Task Should_also_fetch_referenced_contents_when_field_is_included_in_query() { var contentRefId = DomainId.NewGuid(); var contentRef = TestContent.CreateRef(schemaRefId1, contentRefId, "ref1-field", "ref1"); var contentId = DomainId.NewGuid(); var content = TestContent.Create(schemaId, contentId, contentRefId, DomainId.Empty); var query = @" query { findMySchemaContent(id: ""<ID>"") { id data { myReferences { iv { id data { ref1Field { iv } } } } } } }".Replace("<ID>", contentId.ToString()); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), A <IReadOnlyList <DomainId> > ._)) .Returns(ResultList.CreateFrom(0, contentRef)); A.CallTo(() => contentQuery.QueryAsync(MatchsContentContext(), MatchId(contentId))) .Returns(ResultList.CreateFrom(1, content)); var result = await sut.QueryAsync(requestContext, new GraphQLQuery { Query = query }); var expected = new { data = new { findMySchemaContent = new { id = content.Id, data = new { myReferences = new { iv = new[] { new { id = contentRefId, data = new { ref1Field = new { iv = "ref1" } } } } } } } } }; AssertResult(expected, result); }