Skip to content

Commit

Permalink
Create some invalid schema file test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
comigor committed Jun 10, 2019
1 parent 8689def commit e976fe1
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
3 changes: 0 additions & 3 deletions lib/helpers.dart
Expand Up @@ -271,9 +271,6 @@ GraphQLSchema schemaFromJsonString(String jsonS) =>

Future<String> generate(
GraphQLSchema schema, String path, GeneratorOptions options) async {
assert(schema != null, 'Schema can\'t be null.');
assert(path != null, 'Input file can\'t be null.');

final basename = p.basenameWithoutExtension(path);
final customParserImport = options.customParserImport != null
? ' import \'${options.customParserImport}\';'
Expand Down
2 changes: 1 addition & 1 deletion lib/schema/graphql.dart
Expand Up @@ -30,7 +30,7 @@ class GraphQLSchema {
json != null &&
json['data'] != null &&
json['data']['__schema'] != null,
'JSON schema file must be the output of a Introspection Query.');
'JSON schema file must be the output of an Introspection Query.');
return _$GraphQLSchemaFromJson(json['data']['__schema']);
}

Expand Down
15 changes: 15 additions & 0 deletions test/builder_test.dart
Expand Up @@ -49,5 +49,20 @@ void main() {
'a|lib/schemas/project5.api.dart': emptyGeneratorResponse('project5'),
});
});

test(
'A .schema.json file must be an Introspection Query response, or generator will throw',
() async {
expect(testBuilder(builder, {'a|lib/api.schema.json': '{}'}),
throwsA(TypeMatcher<AssertionError>()));

expect(testBuilder(builder, {'a|lib/api.schema.json': '{"data": {}}'}),
throwsA(TypeMatcher<AssertionError>()));

expect(
testBuilder(
builder, {'a|lib/api.schema.json': 'not even a json file'}),
throwsA(TypeMatcher<FormatException>()));
});
});
}

0 comments on commit e976fe1

Please sign in to comment.