public async Task Deserialize_StringList_ListOfStringValueNode() { // arrange var inputParser = new InputParser(new DefaultTypeConverter()); Path path = Path.New("root"); ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType stringListType = new ListType(schema.GetType <StringType>("String")); // act var value = DictionaryDeserializer.DeserializeResult( stringListType, new List <object> { new StringValueNode("abc") }, inputParser, path); // assert Assert.Collection( ((IEnumerable <string>)value) !, v => Assert.Equal("abc", v)); }
public async Task Deserialize_Dictionary() { // arrange var inputParser = new InputParser(new DefaultTypeConverter()); Path path = Path.New("root"); ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType person = schema.GetType <ObjectType>("Person"); var dict = new Dictionary <string, object>(); // act var value = DictionaryDeserializer.DeserializeResult( person, dict, inputParser, path); // assert Assert.Same(dict, value); }
public ValueTask InvokeAsync(IMiddlewareContext context) { if (context.Result is SerializedData s) { context.Result = s.Data is IReadOnlyDictionary <string, object> d ? d : DictionaryDeserializer.DeserializeResult( context.Selection.Type, s.Data, context.Service <InputParser>(), context.Path); } else if (context.Result is null && !context.Selection.Field.Directives.Contains(DirectiveNames.Computed) && context.Parent <object>() is IReadOnlyDictionary <string, object> dict) { string responseName = context.Selection.SyntaxNode.Alias == null ? context.Selection.SyntaxNode.Name.Value : context.Selection.SyntaxNode.Alias.Value; dict.TryGetValue(responseName, out var obj); context.Result = DictionaryDeserializer.DeserializeResult( context.Selection.Type, obj, context.Service <InputParser>(), context.Path); } return(_next.Invoke(context)); }
public async Task Deserialize_String() { // arrange ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType stringType = schema.GetType <StringType>("String"); // act object value = DictionaryDeserializer.DeserializeResult(stringType, "abc"); // assert Assert.Equal("abc", value); }
public async Task Deserialize_Null() { // arrange ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType person = schema.GetType <ObjectType>("Person"); // act object value = DictionaryDeserializer.DeserializeResult(person, null); // assert Assert.Null(value); }
public async Task Deserialize_Dictionary() { // arrange ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType person = schema.GetType <ObjectType>("Person"); var dict = new Dictionary <string, object>(); // act object value = DictionaryDeserializer.DeserializeResult(person, dict); // assert Assert.Same(dict, value); }
public ValueTask InvokeAsync(IMiddlewareContext context) { if (context.Result is SerializedData s) { context.Result = s.Data is IDictionary <string, object> d ? d : DictionaryDeserializer.DeserializeResult(context.Field.Type, s.Data); } else if (context.Result is null && !context.Field.Directives.Contains(DirectiveNames.Computed) && context.Parent <object>() is IDictionary <string, object> dict) { string responseName = context.FieldSelection.Alias == null ? context.FieldSelection.Name.Value : context.FieldSelection.Alias.Value; dict.TryGetValue(responseName, out object?obj); context.Result = DictionaryDeserializer.DeserializeResult(context.Field.Type, obj); } return(_next.Invoke(context)); }
public async Task Deserialize_StringList_StringList() { // arrange ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType stringListType = new ListType(schema.GetType <StringType>("String")); // act object value = DictionaryDeserializer.DeserializeResult( stringListType, new List <string> { "abc" }); // assert Assert.Collection( ((IEnumerable <string>)value) !, v => Assert.Equal("abc", v)); }
public async Task Deserialize_String() { // arrange var inputParser = new InputParser(new DefaultTypeConverter()); Path path = Path.New("root"); ISchema schema = await new ServiceCollection() .AddGraphQLServer() .AddQueryType <Query>() .BuildSchemaAsync(); IType stringType = schema.GetType <StringType>("String"); // act var value = DictionaryDeserializer.DeserializeResult( stringType, "abc", inputParser, path); // assert Assert.Equal("abc", value); }