Beispiel #1
0
 public static DocumentNode Parse(this Parser parser,
                                  string sourceText, ParserOptions options)
 {
     return(parser.Parse(new Source(sourceText), options));
 }
Beispiel #2
0
        public void Parse_Kitchen_Sink_Query_AllProps_No_Cache()
        {
            // arrange
            byte[] source = Encoding.UTF8.GetBytes(
                JsonConvert.SerializeObject(
                    new GraphQLRequestDto
            {
                Query = FileResource.Open("kitchen-sink.graphql")
                        .NormalizeLineBreaks(),
                NamedQuery    = "ABC",
                OperationName = "DEF",
                Variables     = new Dictionary <string, object>
                {
                    { "a", "b" },
                    { "b", new Dictionary <string, object>
                      {
                          { "a", "b" },
                          { "b", true },
                          { "c", 1 },
                          { "d", 1.1 },
                      } },
                    { "c", new List <object>
                      {
                          new Dictionary <string, object>
                          {
                              { "a", "b" },
                          }
                      } },
                },
                Extensions = new Dictionary <string, object>
                {
                    { "aa", "bb" },
                    { "bb", new Dictionary <string, object>
                      {
                          { "aa", "bb" },
                          { "bb", true },
                          { "cc", 1 },
                          { "df", 1.1 },
                      } },
                    { "cc", new List <object>
                      {
                          new Dictionary <string, object>
                          {
                              { "aa", "bb" },
                              { "ab", null },
                              { "ac", false },
                          }
                      } },
                }
            }).NormalizeLineBreaks());

            // act
            var parserOptions = new ParserOptions();
            var requestParser = new Utf8GraphQLRequestParser(
                source, parserOptions);
            IReadOnlyList <GraphQLRequest> batch = requestParser.Parse();

            // assert
            Assert.Collection(batch,
                              r =>
            {
                Assert.Equal("ABC", r.QueryName);
                Assert.Equal("DEF", r.OperationName);

                r.Variables.MatchSnapshot(
                    new SnapshotNameExtension("Variables"));
                r.Extensions.MatchSnapshot(
                    new SnapshotNameExtension("Extensions"));
                QuerySyntaxSerializer.Serialize(r.Query, true)
                .MatchSnapshot(new SnapshotNameExtension("Query"));
            });
        }
Beispiel #3
0
 public static DocumentNode Parse(
     ReadOnlySpan <byte> graphQLData,
     ParserOptions options) =>
 new Utf8GraphQLParser(graphQLData, options).Parse();