@@ -242,7 +242,7 @@ private function parseTypes(string $graphQlSchemaContent) : array
242242 {
243243 $ typeKindsPattern = '(type|interface|union|enum|input) ' ;
244244 $ typeNamePattern = '([_A-Za-z][_0-9A-Za-z]+) ' ;
245- $ typeDefinitionPattern = '([^\{\} ]*)(\{[^\}]*\}) ' ;
245+ $ typeDefinitionPattern = '([^\{]*)(\{[^\}]*\}) ' ;
246246 $ spacePattern = '[\s\t\n\r]+ ' ;
247247
248248 preg_match_all (
@@ -357,19 +357,24 @@ private function addPlaceHolderInSchema(string $graphQlSchemaContent) :string
357357 $ typeDefinitionPattern = '([^\{]*)(\{[\s\t\n\r^\}]*\}) ' ;
358358 $ spacePattern = '([\s\t\n\r]+) ' ;
359359
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
361365 $ 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} " ,
364368 $ graphQlSchemaContent
365369 );
366370
367- //add placeholder in empty enums
371+ //add placeholder in empty types
368372 $ 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} " ,
371375 $ graphQlSchemaContent
372376 );
377+
373378 return $ graphQlSchemaContent ;
374379 }
375380
0 commit comments