Skip to content

Commit 15bad09

Browse files
committed
Fix Syntax Error: Expected Name found :
There was a bug with the enum placeholder ordering Input like the following ``` interface SomeInterface { product_type: String @doc(description: "The type of product, such as simple, configurable, etc.") } enum SomeEnum { } ``` would have placeholder logic ran against it and end up like ``` interface SomeInterface { product_type: String @doc(description: "The type of product, such as simple, configurable, etc.") } enum SomeEnum { placeholder_graphql_field: String } ``` This caused an error, something in the AST was trying to make it resolve against the word "Type" in the @doc description By fixing the enum so that it does not have `: String` in it the AST is generated successfully, we do this by replacing those empty enums first so that they cannot get caught by the empty type check
1 parent 6772386 commit 15bad09

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,19 +337,24 @@ private function addPlaceHolderInSchema(string $graphQlSchemaContent) :string
337337
$typeDefinitionPattern = '([^\{]*)(\{[\s\t\n\r^\}]*\})';
338338
$spacePattern = '([\s\t\n\r]+)';
339339

340-
//add placeholder in empty types
340+
// TODO review this workaround
341+
// Replace enums before types, there is a bug in which some enums are caught by the type regex
342+
// If we process them first they will have their placeholder inserted appropriately without the :String suffix
343+
// This means they will not be caught by the following preg_replace
344+
//add placeholder in empty enums
341345
$graphQlSchemaContent = preg_replace(
342-
"/{$typesKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
343-
"\$1\$2\$3\$4\$5{\n{$placeholderField}: String\n}",
346+
"/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
347+
"\$1\$2\$3\$4\$5{\n{$placeholderField}\n}",
344348
$graphQlSchemaContent
345349
);
346350

347-
//add placeholder in empty enums
351+
//add placeholder in empty types
348352
$graphQlSchemaContent = preg_replace(
349-
"/{$enumKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
350-
"\$1\$2\$3\$4\$5{\n{$placeholderField}\n}",
353+
"/{$typesKindsPattern}{$spacePattern}{$typeNamePattern}{$spacePattern}{$typeDefinitionPattern}/im",
354+
"\$1\$2\$3\$4\$5{\n{$placeholderField}: String\n}",
351355
$graphQlSchemaContent
352356
);
357+
353358
return $graphQlSchemaContent;
354359
}
355360

0 commit comments

Comments
 (0)