Skip to content

Commit 8e8d364

Browse files
committed
Update GraphQlReader.php
Based on feedback #31879 (comment) from @Bartlomiejsz > regarding first issue - with empty enum. It looks like the fix is to replace first matching group in both $typeDefinitionPattern variables: > > ([^\{]*) > with: > > ([^\{\}]*) > Then this regex will check if there is neither beginning or ending bracket in this place
1 parent afa8b04 commit 8e8d364

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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(
@@ -354,27 +354,22 @@ private function addPlaceHolderInSchema(string $graphQlSchemaContent) :string
354354
$typesKindsPattern = '(type|interface|input|union)';
355355
$enumKindsPattern = '(enum)';
356356
$typeNamePattern = '([_A-Za-z][_0-9A-Za-z]+)';
357-
$typeDefinitionPattern = '([^\{]*)(\{[\s\t\n\r^\}]*\})';
357+
$typeDefinitionPattern = '([^\{\}]*)(\{[\s\t\n\r^\}]*\})';
358358
$spacePattern = '([\s\t\n\r]+)';
359359

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
365-
$graphQlSchemaContent = preg_replace(
366-
"/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
367-
"\$1\$2\$3\$4\$5{\n{$placeholderField}\n}",
368-
$graphQlSchemaContent
369-
);
370-
371360
//add placeholder in empty types
372361
$graphQlSchemaContent = preg_replace(
373362
"/{$typesKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
374363
"\$1\$2\$3\$4\$5{\n{$placeholderField}: String\n}",
375364
$graphQlSchemaContent
376365
);
377366

367+
//add placeholder in empty enums
368+
$graphQlSchemaContent = preg_replace(
369+
"/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
370+
"\$1\$2\$3\$4\$5{\n{$placeholderField}\n}",
371+
$graphQlSchemaContent
372+
);
378373
return $graphQlSchemaContent;
379374
}
380375

0 commit comments

Comments
 (0)