示例#1
0
        public async Task <IActionResult> PostGraphQL(string app, [FromBody] GraphQLQuery query)
        {
            var(hasError, response) = await graphQl.QueryAsync(Context, query);

            if (hasError)
            {
                return(BadRequest(response));
            }
            else
            {
                return(Ok(response));
            }
        }
        public async Task <IActionResult> GetGraphQL(string app, [FromQuery] GraphQLGetDto?queries = null)
        {
            var request = queries?.ToQuery() ?? new GraphQLQuery();

            var(hasError, response) = await graphQl.QueryAsync(Context, request);

            if (hasError)
            {
                return(BadRequest(response));
            }
            else
            {
                return(Ok(response));
            }
        }
示例#3
0
        public async Task Should_return_empty_object_for_empty_query(string query)
        {
            var result = await sut.QueryAsync(app, user, new GraphQLQuery { Query = query });

            var expected = new
            {
                data = new
                {
                }
            };

            AssertJson(expected, new { data = result.Data });
        }
示例#4
0
        public async Task <IActionResult> PostGraphQL(string app, [FromBody] GraphQLQuery query)
        {
            var result = await graphQl.QueryAsync(Context().Base, query);

            if (result.Errors?.Length > 0)
            {
                return(BadRequest(new { result.Data, result.Errors }));
            }
            else
            {
                return(Ok(new { result.Data }));
            }
        }
示例#5
0
        public async Task Should_return_multiple_assets_when_querying_assets()
        {
            const string query = @"
                query {
                  queryAssets(search: ""my-query"", top: 30, skip: 5) {
                    id
                    version
                    created
                    createdBy
                    lastModified
                    lastModifiedBy
                    url
                    thumbnailUrl
                    sourceUrl
                    mimeType
                    fileName
                    fileSize
                    fileVersion
                    isImage
                    pixelWidth
                    pixelHeight
                  }
                }";

            var assetEntity = CreateAsset(Guid.NewGuid());

            var assets = new List <IAssetEntity> {
                assetEntity
            };

            A.CallTo(() => assetRepository.QueryAsync(appEntity.Id, null, null, "my-query", 30, 5))
            .Returns(Task.FromResult <IReadOnlyList <IAssetEntity> >(assets));

            var result = await sut.QueryAsync(appEntity, new GraphQLQuery { Query = query });

            var expected = new
            {
                data = new
                {
                    queryAssets = new dynamic[]
                    {
                        new
                        {
                            id             = assetEntity.Id,
                            version        = 1,
                            created        = assetEntity.Created.ToDateTimeUtc(),
                            createdBy      = "subject:user1",
                            lastModified   = assetEntity.LastModified.ToDateTimeUtc(),
                            lastModifiedBy = "subject:user2",
                            url            = $"assets/{assetEntity.Id}",
                            thumbnailUrl   = $"assets/{assetEntity.Id}?width=100",
                            sourceUrl      = $"assets/source/{assetEntity.Id}",
                            mimeType       = "image/png",
                            fileName       = "MyFile.png",
                            fileSize       = 1024,
                            fileVersion    = 123,
                            isImage        = true,
                            pixelWidth     = 800,
                            pixelHeight    = 600
                        }
                    }
                }
            };

            AssertJson(expected, new { data = result.Data });
        }