Beispiel #1
0
        public void GraphQLQueryGeneratorFromFields_Should_Throw_When_No_Matching_Argument_Found_Two_Arguments()
        {
            // Arrange
            var fieldGenerator = new GraphQLFieldBuilder();
            var queryGenerator = new GraphQLQueryGeneratorFromFields();

            var argument1 = new GraphQLQueryArgument("hello1Argument", "Value1");
            var argument2 = new GraphQLQueryArgument("hello2Argument", "Value2");

            // Act / Assert
            var exception = Assert.Throws <GraphQLArgumentVariableNotFoundException>(() =>
            {
                // Get the query
                var query = queryGenerator.GenerateQuery(GraphQLOperationType.Query, fieldGenerator.GenerateSelectionSet(typeof(SampleQuery)),
                                                         argument1, argument2);
            });

            // Assert
            // Should contain two element
            Assert.Equal(2, exception.Arguments.Count());

            // Argument should contain helloArgument and value
            Assert.Contains(argument1, exception.Arguments);
            Assert.Contains(argument2, exception.Arguments);
        }
        public void Test_Single_Other_Possible_Type_With_Extra_Field()
        {
            var fields = new GraphQLField[]
            {
                new GraphQLField("alias", "field", null, null, null,
                                 new Dictionary <string, GraphQLTargetType>
                {
                    {
                        "interfaceConcreteType",
                        new GraphQLTargetType
                        (
                            typeof(string),
                            new List <GraphQLField>
                        {
                            new GraphQLField("alias", "field", null, null),
                            new GraphQLField("alias2", "field2", null, null)
                        }
                        )
                    }
                }),
            };
            var queryGenerator = new GraphQLQueryGeneratorFromFields();
            var expected       = "{\"query\":\"query{alias:field ... on interfaceConcreteType{alias:field alias2:field2}}\"}";

            var actual = queryGenerator.GenerateQuery(GraphQLOperationType.Query, fields);

            Assert.Equal(expected, actual);
        }
        public void Test_Case_Hero()
        {
            // Arrange
            var expected     = "{\"query\":\"query{hero{friends{name} name}}\"}";
            var fieldBuilder = new GraphQLFieldBuilder();
            var queryBuilder = new GraphQLQueryGeneratorFromFields();

            // Act
            // Get fields
            var fields =
                fieldBuilder.GenerateSelectionSet(typeof(Query_Test_Case_Hero));
            var actual = queryBuilder.GenerateQuery(GraphQLOperationType.Query, fields);

            // Assert
            Assert.Equal(expected, actual);
        }
        public void Test_Single_Field_Should_Not_Generate_Seperate_Field_And_Alias()
        {
            // Arrange
            var expected     = "{\"query\":\"query{field}\"}";
            var fieldBuilder = new GraphQLFieldBuilder();
            var queryBuilder = new GraphQLQueryGeneratorFromFields();

            // Act
            // Get fields
            var fields =
                fieldBuilder.GenerateSelectionSet(typeof(Query_Test_Single_Field_Should_Not_Generate_Seperate_Field_And_Alias));
            var actual = queryBuilder.GenerateQuery(GraphQLOperationType.Query, fields);

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #5
0
        public void Test_Variable_Complex_Dynamic_Type()
        {
            // Arrange
            var expected     = "{\"query\":\"query($variableName:Type!){field(argumentName:$variableName)}\",\"variables\":{\"variableName\":{\"field1\":\"value1\",\"field2\":\"value2\"}}}";
            var fieldBuilder = new GraphQLFieldBuilder();
            var queryBuilder = new GraphQLQueryGeneratorFromFields();

            // Act
            // Get fields
            var fields =
                fieldBuilder.GenerateSelectionSet(typeof(Query));
            var actual = queryBuilder.GenerateQuery(GraphQLOperationType.Query, fields,
                                                    new GraphQLQueryArgument("variableName", new { field1 = "value1", field2 = "value2" }));

            // Assert
            Assert.Equal(expected, actual);
        }
Beispiel #6
0
        public void GraphQLQueryGeneratorFromFields_Should_Throw_When_No_Matching_Argument_Found()
        {
            // Arrange
            var fieldGenerator = new GraphQLFieldBuilder();
            var queryGenerator = new GraphQLQueryGeneratorFromFields();

            // Act / Assert
            var exception = Assert.Throws <GraphQLArgumentVariableNotFoundException>(() =>
            {
                // Get the query
                var query = queryGenerator.GenerateQuery(GraphQLOperationType.Query, fieldGenerator.GenerateSelectionSet(typeof(SampleQuery)),
                                                         new GraphQLQueryArgument("helloArgument", "Value"));
            });

            // Assert
            // Should contain one element
            Assert.Equal(1, exception.Arguments.Count());

            // Argument should contain helloArgument and value
            Assert.Equal("helloArgument", exception.Arguments.First().VariableName);
            Assert.Equal("Value", exception.Arguments.First().ArgumentValue);
        }