@@ -25,21 +25,31 @@ static void expectError(const char *queryStr, const char *expectedError) {
2525 auto ast = parseString (queryStr, &actualError);
2626
2727 EXPECT_FALSE (ast);
28- EXPECT_STREQ (expectedError, actualError );
28+ EXPECT_STREQ (actualError, expectedError );
2929
3030 std::free ((void *)actualError);
3131}
3232
33- static void expectSuccess (const char *queryStr) {
33+ static void expectSuccessImpl (const char *queryStr, bool enableSchema ) {
3434 const char *actualError = nullptr ;
35- auto ast = parseString (queryStr, &actualError);
35+ auto ast = enableSchema
36+ ? parseStringWithExperimentalSchemaSupport (queryStr, &actualError)
37+ : parseString (queryStr, &actualError);
3638
3739 EXPECT_TRUE (ast != nullptr );
3840 EXPECT_STREQ (nullptr , actualError);
3941
4042 std::free ((void *)actualError);
4143}
4244
45+ static void expectSuccess (const char *queryStr) {
46+ expectSuccessImpl (queryStr, false );
47+ }
48+
49+ static void expectSchemaSuccess (const char *queryStr) {
50+ expectSuccessImpl (queryStr, true );
51+ }
52+
4353static void checkSimpleError () {
4454 expectError (" query myquery on type { field }" ,
4555 " 1.15-16: syntax error, unexpected on, expecting ( or @ or {" );
@@ -283,3 +293,36 @@ TEST(ParserTests, ProducesCorrectOutputForKitchenSink) {
283293 ss.str ().c_str ());
284294 free ((void *)json);
285295}
296+
297+ static void expectSchemaParsing (const char *queryStr) {
298+ char buf[strlen (" 1.1-XXX: schema support disabled" ) + 1 ];
299+ ASSERT_LT (strlen (queryStr), 999 );
300+ snprintf (
301+ buf,
302+ sizeof (buf),
303+ " 1.1-%lu: schema support disabled" ,
304+ strlen (queryStr));
305+ expectError (queryStr, buf);
306+ expectSchemaSuccess (queryStr);
307+ }
308+
309+ #define DIRECTIVES " @d1(a: 1) @d2(a: 2)"
310+
311+ TEST (SchemaParserTests, SimpleSchema) {
312+ expectSchemaParsing (
313+ " schema " DIRECTIVES " { query: QueryType, mutation: MutType }" );
314+ expectSchemaParsing (" scalar SomeScalar " DIRECTIVES);
315+ expectSchemaParsing (" type SomeObject implements SomeInterface " DIRECTIVES
316+ " { someField : SomeType }" );
317+ expectSchemaParsing (" interface SomeInterface " DIRECTIVES
318+ " { someField : SomeType }" );
319+ expectSchemaParsing (" union SomeUnion " DIRECTIVES
320+ " = SomeType | SomeOtherType" );
321+ expectSchemaParsing (" enum SomeEnum " DIRECTIVES " { VALUE, OTHER_VALUE }" );
322+ expectSchemaParsing (" input SomeInput " DIRECTIVES " { someField: SomeType, "
323+ " otherField: otherType }" );
324+ expectSchemaParsing (" extend type SomeType " DIRECTIVES
325+ " { anotherField : AnotherType }" );
326+ expectSchemaParsing (" directive @somedirective(a1 : t1 = 1 " DIRECTIVES
327+ " , a2 : t2) on foo | bar" );
328+ }
0 commit comments