Beispiel #1
0
        public void TestGraphqlEndPointsUnauthorized(string entityName)
        {
            var api = new WebApi(_configure, _output);

            var query = new RestSharp.JsonObject();

            query.Add("query", "{ " + entityName + "{id}}");
            var response = api.Post($"/api/graphql", query);

            // we should get a valid response back
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Beispiel #2
0
        public void TestGraphqlEndPoints(string entityName)
        {
            var api = new WebApi(_configure, _output);

            var query = new RestSharp.JsonObject();

            query.Add("query", "{ " + entityName + "{id}}");

            api.ConfigureAuthenticationHeaders();
            var response = api.Post($"/api/graphql", query);

            //check the ids are valid
            var validIds = JObject.Parse(response.Content)["data"][entityName]
                           .Select(o => o["id"].Value <string>())
                           .All(o => !string.IsNullOrWhiteSpace(o));

            //valid ids returned and a valid response
            Assert.Equal(HttpStatusCode.OK, response.StatusCode);
        }
Beispiel #3
0
        /// <summary>
        ///	Query builder for batch updating of an entity
        ///	Takes a list of BaseEntities to update.
        /// Generates new attribute values for all entities to be updated to,
        /// and returns a GraphQL query to perform the update with.
        /// </summary>
        /// <param name="baseEntities">The list of BaseEntities to be updated</param>
        /// <returns>The graphql query as a json object</returns>
        public static RestSharp.JsonObject BatchUpdateEntityQueryBuilder(List <BaseEntity> baseEntities)
        {
            string entityName     = baseEntities[0].EntityName;
            var    attributeNames = baseEntities[0].Attributes.Select(x => x.Name).ToList();
            var    newAttributes  = new EntityFactory(entityName).Construct().ToJson();
            var    valuesToUpdate = new RestSharp.JsonObject();

            attributeNames.ForEach(x => valuesToUpdate.Add(x.LowerCaseFirst(), $"{newAttributes[x.LowerCaseFirst()]}"));

            // Build the entity variables part
            var entityVar = new RestSharp.JsonObject
            {
                { $"idsToUpdate", baseEntities.Select(x => x.Id).ToArray() },
                { "valuesToUpdate", valuesToUpdate },
                { "fieldsToUpdate", attributeNames.ToArray() },
            };

            // Build the graphQL Query part
            var queryPart = $@"mutation update{entityName}sConditional (
				$valuesToUpdate: {entityName}Input,
				$fieldsToUpdate: [String],
				$idsToUpdate:[ID])
				{{update{entityName}sConditional(
					ids: $idsToUpdate,
					valuesToUpdate: $valuesToUpdate,
					fieldsToUpdate: $fieldsToUpdate){{
						value
					}}
				}}"                ;

            // Constructing query string
            RestSharp.JsonObject query = new RestSharp.JsonObject
            {
                { "operationName", $"update{entityName}sConditional" },
                { "variables", entityVar },
                { "query", queryPart }
            };
            return(query);
        }
Beispiel #4
0
        /// <summary>
        /// Query builder for deleting an entity
        /// </summary>
        /// <param name="entityKeyGuid"></param>
        /// <returns>The graphql query as a json object</returns>
        public static RestSharp.JsonObject DeleteEntityQueryBuilder(List <BaseEntity> entityList)
        {
            var entityName = entityList[0].EntityName;
            var guids      = new List <Guid>();

            entityList.ForEach(x => guids.Add(x.Id));

            var entityVar = new RestSharp.JsonObject();

            entityVar.Add($"{entityName.LowerCaseFirst()}Ids", guids.ToArray());

            var queryPart = $@"mutation delete (${entityList[0].EntityName.LowerCaseFirst()}Ids: [ID])
				{{ delete{entityName}({entityName.LowerCaseFirst()}Ids:
				${entityName.LowerCaseFirst()}Ids){{ id __typename }} }}"                ;

            var query = new RestSharp.JsonObject
            {
                { "operationName", "delete" },
                { "variables", entityVar },
                { "query", queryPart }
            };

            return(query);
        }