Пример #1
0
        public static void Serialize(
            ISyntaxNode node,
            TextWriter writer,
            bool useIndentation)
        {
            var serializer = new QuerySyntaxSerializer(useIndentation);

            serializer.Visit(node, new DocumentWriter(writer));
        }
Пример #2
0
        public void Serialize_KitchenSinkWithoutIndentation_CanBeParsed()
        {
            // arrange
            string query = FileResource.Open("kitchen-sink.graphql");

            var serializer = new QuerySyntaxSerializer();
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            string       serializedQuery = content.ToString();
            DocumentNode parsedQuery     = Parser.Default.Parse(serializedQuery);

            content.Clear();
            serializer.Visit(parsedQuery, new DocumentWriter(writer));
            Assert.Equal(serializedQuery, content.ToString());
        }
Пример #3
0
        public void Serialize_KitchenSinkWithoutIndentation_OutputIsOneLine()
        {
            // arrange
            string query = FileResource.Open("kitchen-sink.graphql");

            var serializer = new QuerySyntaxSerializer();
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            content.ToString().Snapshot();
        }
Пример #4
0
        public void Serialize_ShortHandQueryWithIndentation_LineBetweenFields()
        {
            // arrange
            string query = "{ foo { foo bar { foo @foo @bar bar @bar baz } } }";

            var serializer = new QuerySyntaxSerializer(true);
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            content.ToString().Snapshot();
        }
Пример #5
0
        public void Serialize_ShortHandQueryWithIndentation_OutputIsFormatted()
        {
            // arrange
            string query = "{ foo(s: \"String\") { bar @foo " +
                           "{ baz @foo @bar } } }";

            var serializer = new QuerySyntaxSerializer(true);
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            content.ToString().Snapshot();
        }
        public void Serialize_KitchenSinkWithIndentation_OutputIsFormatted()
        {
            // arrange
            string query = FileResource.Open("kitchen-sink.graphql");

            var serializer = new QuerySyntaxSerializer(true);
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Utf8GraphQLParser.Parse(query);


            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            content.ToString().MatchSnapshot();
        }
Пример #7
0
        public void Serialize_FargmentWithVariableDefs_InOutShouldBeTheSame()
        {
            // arrange
            string query = "fragment Foo ($bar: [String!]!) on Bar { baz }";

            var serializer = new QuerySyntaxSerializer();
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query,
                                                              new ParserOptions(allowFragmentVariables: true));

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            Assert.Equal(
                query,
                content.ToString());
        }
Пример #8
0
        public void Serialize_ShortHandQueryNoIndentation_InOutShouldBeTheSame()
        {
            // arrange
            var query = "{ foo(s: \"String\") { bar @foo " +
                        "{ baz @foo @bar } } }";

            var serializer = new QuerySyntaxSerializer();
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            Assert.Equal(
                query,
                content.ToString());
        }
Пример #9
0
        public void RewriteEveryFieldOfTheQuery()
        {
            // arange
            DocumentNode document = Utf8GraphQLParser.Parse(
                "{ foo { bar { baz } } }");

            // act
            DocumentNode rewritten = document
                                     .Rewrite <DirectiveQuerySyntaxRewriter, DirectiveNode>(
                new DirectiveNode("upper"));

            // assert
            var content        = new StringBuilder();
            var stringWriter   = new StringWriter(content);
            var documentWriter = new DocumentWriter(stringWriter);
            var serializer     = new QuerySyntaxSerializer();

            serializer.Visit(rewritten, documentWriter);
            content.ToString().MatchSnapshot();
        }
Пример #10
0
        public void Serialize_QueryWithVarDeclaration_InOutShouldBeTheSame()
        {
            // arrange
            string query =
                "query Foo($bar: [String!]!) { foo(s: \"String\") " +
                "{ bar @foo { baz @foo @bar } } }";

            var serializer = new QuerySyntaxSerializer();
            var content    = new StringBuilder();
            var writer     = new StringWriter(content);

            DocumentNode queryDocument = Parser.Default.Parse(query);

            // act
            serializer.Visit(queryDocument, new DocumentWriter(writer));

            // assert
            Assert.Equal(
                query,
                content.ToString());
        }