|
1 | 1 | using System.Text;
|
| 2 | +using HotChocolate.Language; |
2 | 3 | using HotChocolate.Skimmed.Serialization;
|
3 |
| -using HotChocolate.Types; |
| 4 | +using DirectiveLocation = HotChocolate.Types.DirectiveLocation; |
4 | 5 |
|
5 | 6 | namespace HotChocolate.Skimmed;
|
6 | 7 |
|
@@ -161,4 +162,97 @@ directive @skip("Custom argument description" ifCustom: String! @custom) on ENUM
|
161 | 162 | Assert.True(argument.Directives.ContainsName("custom"));
|
162 | 163 | Assert.Equal(DirectiveLocation.EnumValue, directive.Locations);
|
163 | 164 | }
|
| 165 | + |
| 166 | + [Fact] |
| 167 | + public void Parse_Input_Object_With_Default_Value() |
| 168 | + { |
| 169 | + // arrange |
| 170 | + var sdl = |
| 171 | + """ |
| 172 | + input BookFilter { |
| 173 | + genre: Genre = FANTASY |
| 174 | + } |
| 175 | + enum Genre { |
| 176 | + FANTASY |
| 177 | + SCIENCE_FICTION |
| 178 | + } |
| 179 | + """; |
| 180 | + |
| 181 | + // act |
| 182 | + var schema = SchemaParser.Parse(Encoding.UTF8.GetBytes(sdl)); |
| 183 | + // assert |
| 184 | + Assert.Collection( |
| 185 | + schema.Types.OrderBy(t => t.Name), |
| 186 | + type => |
| 187 | + { |
| 188 | + var inputType = Assert.IsType<InputObjectTypeDefinition>(type); |
| 189 | + Assert.Equal("BookFilter", inputType.Name); |
| 190 | + var genreField = Assert.Single(inputType.Fields); |
| 191 | + Assert.Equal("genre", genreField.Name); |
| 192 | + Assert.IsType<EnumTypeDefinition>(genreField.Type); |
| 193 | + Assert.NotNull(genreField.DefaultValue); |
| 194 | + Assert.Equal("FANTASY", genreField.DefaultValue.Value); |
| 195 | + }, |
| 196 | + type => |
| 197 | + { |
| 198 | + var genreType = Assert.IsType<EnumTypeDefinition>(type); |
| 199 | + Assert.Equal("Genre", genreType.Name); |
| 200 | + }); |
| 201 | + } |
| 202 | + |
| 203 | + [Fact] |
| 204 | + public void Parse_Input_Object_With_Multiple_Default_Values() |
| 205 | + { |
| 206 | + // arrange |
| 207 | + var sdl = |
| 208 | + """ |
| 209 | + input BookFilter { |
| 210 | + genre: Genre = FANTASY |
| 211 | + author: String = "Lorem ipsum" |
| 212 | + } |
| 213 | + enum Genre { |
| 214 | + FANTASY |
| 215 | + SCIENCE_FICTION |
| 216 | + } |
| 217 | +
|
| 218 | + scalar String |
| 219 | + """; |
| 220 | + |
| 221 | + // act |
| 222 | + var schema = SchemaParser.Parse(Encoding.UTF8.GetBytes(sdl)); |
| 223 | + // assert |
| 224 | + Assert.Collection( |
| 225 | + schema.Types.OrderBy(t => t.Name), |
| 226 | + type => |
| 227 | + { |
| 228 | + var inputType = Assert.IsType<InputObjectTypeDefinition>(type); |
| 229 | + Assert.Equal("BookFilter", inputType.Name); |
| 230 | + Assert.Collection(inputType.Fields.OrderBy(f => f.Name), |
| 231 | + authorField => |
| 232 | + { |
| 233 | + Assert.Equal("author", authorField.Name); |
| 234 | + var fieldType = Assert.IsType<ScalarTypeDefinition>(authorField.Type); |
| 235 | + Assert.Equal("String", fieldType.Name); |
| 236 | + Assert.NotNull(authorField.DefaultValue); |
| 237 | + Assert.Equal("Lorem ipsum", authorField.DefaultValue.Value); |
| 238 | + }, |
| 239 | + genreField => |
| 240 | + { |
| 241 | + Assert.Equal("genre", genreField.Name); |
| 242 | + Assert.IsType<EnumTypeDefinition>(genreField.Type); |
| 243 | + Assert.NotNull(genreField.DefaultValue); |
| 244 | + Assert.Equal("FANTASY", genreField.DefaultValue.Value); |
| 245 | + }); |
| 246 | + }, |
| 247 | + type => |
| 248 | + { |
| 249 | + var genreType = Assert.IsType<EnumTypeDefinition>(type); |
| 250 | + Assert.Equal("Genre", genreType.Name); |
| 251 | + }, |
| 252 | + type => |
| 253 | + { |
| 254 | + var stringType = Assert.IsType<ScalarTypeDefinition>(type); |
| 255 | + Assert.Equal("String", stringType.Name); |
| 256 | + }); |
| 257 | + } |
164 | 258 | }
|
0 commit comments