diff --git a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php index 199dc97fbc2eb..5347bcbb1387b 100644 --- a/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php +++ b/lib/internal/Magento/Framework/GraphQlSchemaStitching/GraphQlReader.php @@ -337,19 +337,24 @@ private function addPlaceHolderInSchema(string $graphQlSchemaContent) :string $typeDefinitionPattern = '([^\{]*)(\{[\s\t\n\r^\}]*\})'; $spacePattern = '([\s\t\n\r]+)'; - //add placeholder in empty types + // TODO review this workaround + // Replace enums before types, there is a bug in which some enums are caught by the type regex + // If we process them first they will have their placeholder inserted appropriately without the :String suffix + // This means they will not be caught by the following preg_replace + //add placeholder in empty enums $graphQlSchemaContent = preg_replace( - "/{$typesKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im", - "\$1\$2\$3\$4\$5{\n{$placeholderField}: String\n}", + "/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im", + "\$1\$2\$3\$4\$5{\n{$placeholderField}\n}", $graphQlSchemaContent ); - //add placeholder in empty enums + //add placeholder in empty types $graphQlSchemaContent = preg_replace( - "/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im", - "\$1\$2\$3\$4\$5{\n{$placeholderField}\n}", + "/{$typesKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im", + "\$1\$2\$3\$4\$5{\n{$placeholderField}: String\n}", $graphQlSchemaContent ); + return $graphQlSchemaContent; }