Skip to content

Commit

Permalink
Fix Syntax Error: Expected Name found :
Browse files Browse the repository at this point in the history
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
  • Loading branch information
convenient committed May 13, 2021
1 parent 6772386 commit 15bad09
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 15bad09

Please sign in to comment.