diff --git a/lib/helpers.dart b/lib/helpers.dart index a6cae357..770e37c3 100644 --- a/lib/helpers.dart +++ b/lib/helpers.dart @@ -271,9 +271,6 @@ GraphQLSchema schemaFromJsonString(String jsonS) => Future 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}\';' diff --git a/lib/schema/graphql.dart b/lib/schema/graphql.dart index fb3600f8..529a5d29 100644 --- a/lib/schema/graphql.dart +++ b/lib/schema/graphql.dart @@ -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']); } diff --git a/test/builder_test.dart b/test/builder_test.dart index 186fab6f..3af5974c 100644 --- a/test/builder_test.dart +++ b/test/builder_test.dart @@ -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())); + + expect(testBuilder(builder, {'a|lib/api.schema.json': '{"data": {}}'}), + throwsA(TypeMatcher())); + + expect( + testBuilder( + builder, {'a|lib/api.schema.json': 'not even a json file'}), + throwsA(TypeMatcher())); + }); }); }