public void Parser_ImplementsInterfaces() { // arrange string sourceText = "interface a implements e { b: String } "; var parser = new Utf8GraphQLParser( Encoding.UTF8.GetBytes(sourceText)); // act DocumentNode document = parser.Parse(); // assert var def = (document.Definitions[0] as InterfaceTypeDefinitionNode); Assert.NotNull(def); Assert.Equal("a", def.Name.Value); Assert.Null(def.Description); Assert.Single(def.Fields); Assert.Equal("b", def.Fields[0].Name.Value); Assert.Empty(def.Directives); Assert.Single(def.Interfaces); Assert.Equal("e", def.Interfaces[0].Name.Value); Assert.Equal(NodeKind.InterfaceTypeDefinition, def.Kind); }
public static unsafe DocumentNode Parse( string sourceText, ParserOptions options) { if (string.IsNullOrEmpty(sourceText)) { throw new ArgumentException(SourceText_Empty, nameof(sourceText)); } if (options == null) { throw new ArgumentNullException(nameof(options)); } var length = checked (sourceText.Length * 4); byte[]? source = null; Span <byte> sourceSpan = length <= GraphQLConstants.StackallocThreshold ? stackalloc byte[length] : source = ArrayPool <byte> .Shared.Rent(length); try { ConvertToBytes(sourceText, ref sourceSpan); var parser = new Utf8GraphQLParser(sourceSpan, options); return(parser.Parse()); } finally { if (source != null) { sourceSpan.Clear(); ArrayPool <byte> .Shared.Return(source); } } }
public void QueryWithComments() { // arrange byte[] sourceText = Encoding.UTF8.GetBytes( @"{ hero { name # Queries can have comments! friends(a:""foo"" b: 123456 c:null d: true) { name } } }".NormalizeLineBreaks()); // act var parser = new Utf8GraphQLParser( sourceText, ParserOptions.Default); DocumentNode document = parser.Parse(); // assert document.MatchSnapshot(); QuerySyntaxSerializer.Serialize(document) .MatchSnapshot(new SnapshotNameExtension("serialized")); }