@@ -242,7 +242,7 @@ private function parseTypes(string $graphQlSchemaContent) : array
242
242
{
243
243
$ typeKindsPattern = '(type|interface|union|enum|input) ' ;
244
244
$ typeNamePattern = '([_A-Za-z][_0-9A-Za-z]+) ' ;
245
- $ typeDefinitionPattern = '([^\{\} ]*)(\{[^\}]*\}) ' ;
245
+ $ typeDefinitionPattern = '([^\{]*)(\{[^\}]*\}) ' ;
246
246
$ spacePattern = '[\s\t\n\r]+ ' ;
247
247
248
248
preg_match_all (
@@ -357,19 +357,24 @@ private function addPlaceHolderInSchema(string $graphQlSchemaContent) :string
357
357
$ typeDefinitionPattern = '([^\{]*)(\{[\s\t\n\r^\}]*\}) ' ;
358
358
$ spacePattern = '([\s\t\n\r]+) ' ;
359
359
360
- //add placeholder in empty types
360
+ // TODO review this workaround
361
+ // Replace enums before types, there is a bug in which some enums are caught by the type regex
362
+ // If we process them first they will have their placeholder inserted appropriately without the :String suffix
363
+ // This means they will not be caught by the following preg_replace
364
+ //add placeholder in empty enums
361
365
$ graphQlSchemaContent = preg_replace (
362
- "/ {$ typesKindsPattern }{$ spacePattern }{$ typeNamePattern }{$ spacePattern }{$ typeDefinitionPattern }/im " ,
363
- "\$1 \$2 \$3 \$4 \$5{ \n{$ placeholderField }: String \n} " ,
366
+ "/ {$ enumKindsPattern }{$ spacePattern }{$ typeNamePattern }{$ spacePattern }{$ typeDefinitionPattern }/im " ,
367
+ "\$1 \$2 \$3 \$4 \$5{ \n{$ placeholderField }\n} " ,
364
368
$ graphQlSchemaContent
365
369
);
366
370
367
- //add placeholder in empty enums
371
+ //add placeholder in empty types
368
372
$ graphQlSchemaContent = preg_replace (
369
- "/ {$ enumKindsPattern }{$ spacePattern }{$ typeNamePattern }{$ spacePattern }{$ typeDefinitionPattern }/im " ,
370
- "\$1 \$2 \$3 \$4 \$5{ \n{$ placeholderField }\n} " ,
373
+ "/ {$ typesKindsPattern }{$ spacePattern }{$ typeNamePattern }{$ spacePattern }{$ typeDefinitionPattern }/im " ,
374
+ "\$1 \$2 \$3 \$4 \$5{ \n{$ placeholderField }: String \n} " ,
371
375
$ graphQlSchemaContent
372
376
);
377
+
373
378
return $ graphQlSchemaContent ;
374
379
}
375
380
0 commit comments