public void GraphQLException_SerializesToIncludePath()
        {
            var e = new GraphQLException("msg", null, null, null, new object[] { "path", 3, "to", "field" });

            Assert.AreEqual(new object[] { "path", 3, "to", "field" }, e.Path);
            Assert.AreEqual("{\"message\":\"msg\",\"path\":[\"path\",3,\"to\",\"field\"]}", e.ToString());
        }
Пример #2
0
 public static IError ArgumentDefaultValueIsInvalid(
     string responseName,
     GraphQLException exception)
 {
     return(ErrorBuilder.FromError(exception.Errors[0])
            .SetExtension("responseName", responseName)
            .Build());
 }
Пример #3
0
        public static void StartsWith(string message, GraphQLException actual, int line, int column, IEnumerable path = null)
        {
            Assert.IsTrue(actual.Message.StartsWith(message));

            var singleLocation = actual.Locations.Single();

            AssertLocation(line, column, singleLocation);
        }
Пример #4
0
        public static void AreEqual(string message, GraphQLException actual, params int[][] locations)
        {
            Assert.AreEqual(message, actual.Message);

            if (locations != null)
            {
                AssertLocations(locations, actual.Locations);
            }
        }
        public void GraphQLException_SerializesToIncludeMessageAndLocations()
        {
            var node = this.GetFieldNode(new Source("{ field }"));

            var e = new GraphQLException("msg", new[] { node });

            Assert.AreEqual("{\"message\":\"msg\",\"locations\":[{\"line\":1,\"column\":3}]}",
                            e.ToString());
        }
Пример #6
0
 public static IError ArgumentValueIsInvalid(
     ArgumentNode argument,
     string responseName,
     GraphQLException exception)
 {
     return(ErrorBuilder.FromError(exception.Errors[0])
            .AddLocation(argument)
            .SetExtension("responseName", responseName)
            .Build());
 }
Пример #7
0
 public static IError InvalidLeafValue(
     GraphQLException exception,
     FieldNode field,
     Path path)
 {
     return(ErrorBuilder.FromError(exception.Errors[0])
            .AddLocation(field)
            .SetPath(path)
            .SetCode(ErrorCodes.Execution.CannotSerializeLeafValue)
            .Build());
 }
Пример #8
0
        public static void AreEqual(string message, GraphQLException actual, int line, int column, IEnumerable path = null)
        {
            Assert.AreEqual(message, actual.Message);

            var singleLocation = actual.Locations.Single();

            AssertLocation(line, column, singleLocation);

            if (path != null)
            {
                AssertPath(path, actual.Path);
            }
        }
        public void GraphQLException_ConvertsSourceAndPositionsToLocations()
        {
            var source = new Source(
                @"{
    field
}");
            var e = new GraphQLException("msg", null, source, new[] { 10 });

            Assert.AreEqual(null, e.Nodes);
            Assert.AreEqual(source, e.ASTSource);
            Assert.AreEqual(new[] { 10 }, e.Positions);
            Assert.AreEqual(new[] { new Location()
                                    {
                                        Line = 2, Column = 9
                                    } }, e.Locations);
        }
        public void GraphQLException_ConvertsNodeWithZeroStartLocationToPositionsAndLocations()
        {
            var source = new Source(
                @"{
    field
}");
            var operationNode = this.GetOperationDefinitionNode(source);
            var e             = new GraphQLException("msg", new[] { operationNode });

            Assert.AreEqual(new[] { operationNode }, e.Nodes);
            Assert.AreEqual(source, e.ASTSource);
            Assert.AreEqual(new[] { 0 }, e.Positions);
            Assert.AreEqual(new[] { new Location()
                                    {
                                        Line = 1, Column = 1
                                    } }, e.Locations);
        }
        public void GraphQLException_ConvertsNodesToPositionsAndLocations()
        {
            var source = new Source(
                @"{
    field
}");
            var fieldNode = this.GetFieldNode(source);

            var e = new GraphQLException("msg", new[] { fieldNode });

            Assert.AreEqual(new[] { fieldNode }, e.Nodes);
            Assert.AreEqual(source, e.ASTSource);
            Assert.AreEqual(new[] { 6 }, e.Positions);
            Assert.AreEqual(new[] { new Location()
                                    {
                                        Line = 2, Column = 5
                                    } }, e.Locations);
        }
Пример #12
0
        private async Task <object> TryResolveField(
            GraphQLFieldSelection selection, GraphQLObjectTypeFieldInfo fieldInfo, IList <GraphQLArgument> arguments, object parent)
        {
            try
            {
                return(await this.ResolveField(fieldInfo, arguments, parent));
            }
            catch (TargetInvocationException ex)
            {
                var aliasOrName = selection.Alias?.Value ?? selection.Name.Value;
                var orderedPath = this.ReorderPath(this.path);

                var exception        = new GraphQLException(ex.InnerException);
                var locatedException = GraphQLException.LocateException(exception, new[] { selection }, orderedPath.Append(aliasOrName));
                this.Errors.Add(locatedException);

                return(await this.CompleteValue(null, fieldInfo.SystemType, selection, arguments, this.path));
            }
        }
Пример #13
0
 public static bool ContainsSamlOrganizationAthenticationError <T>(this GraphQLException <T> graphQLException) => graphQLException.Errors.Any(x => x.Message.Contains("SAML", StringComparison.OrdinalIgnoreCase) && x.Message.Contains("organization", StringComparison.OrdinalIgnoreCase));
Пример #14
0
 public static void MatchSnapshot(this GraphQLException ex)
 {
     QueryResultBuilder.CreateError(ex.Errors).ToJson().MatchSnapshot();
 }
        public void GraphQLException_SerializesToIncludeMessage()
        {
            var e = new GraphQLException("msg");

            Assert.AreEqual("{\"message\":\"msg\"}", e.ToString());
        }