Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CDF-23515] 🤔GraphQL Comment issue #1289

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.cdf-tk.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Changes are grouped as follows:
- `Fixed` for any bug fixes.
- `Security` in case of vulnerabilities.

## TBD

### Fixed

- [alpha feature] Deploying `GraphQL` now correctly ignores end-of-line comments in the `.graphql` file.

## [0.3.20] - 2024-12-10

### Fixed
Expand Down
17 changes: 14 additions & 3 deletions cognite_toolkit/_cdf_tk/utils/graphql_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,23 @@ def _parse(self) -> "list[_Entity]":
parentheses: list[str] = []
directive_tokens: _DirectiveTokens | None = None
is_directive_start = False
is_comment = False
is_multiline_comment = False
is_end_of_line_comment = False
is_in_double_quote = False
is_in_single_quote = False
tokens = self._token_pattern.findall(self.raw)
for no, token in enumerate(tokens):
if no >= 2 and (tokens[no - 2 : no + 1] == ['"'] * 3 or tokens[no - 2 : no + 1] == ["'"] * 3):
is_comment = not is_comment
if is_comment:
is_multiline_comment = not is_multiline_comment
elif token == '"':
is_in_double_quote = not is_in_double_quote
elif token == "'":
is_in_single_quote = not is_in_single_quote
elif token == "#" and not (is_in_double_quote or is_in_single_quote):
is_end_of_line_comment = True
if "\n" in token and is_end_of_line_comment:
is_end_of_line_comment = False
if is_multiline_comment or is_end_of_line_comment:
continue

token = self._multi_newline.sub("\n", token)
Expand Down
25 changes: 25 additions & 0 deletions tests/test_unit/test_cdf_tk/test_utils/test_graphql_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,31 @@
{ViewId("cdf_cdm", "CogniteCADModel", "v1")},
id="Setting custom filter on view",
),
pytest.param(
'''"""
@name Tag (Beta)
@code CTG
@Description Beta version only. Should not be used unless aligned with Celanese Data Governance Owner. Tag is an object designed for performing functional requirements and serving as a specification for equipment.
"""
type TagBeta @view (version: "7#") {
name: String
description: String
aliases: [String]
isActive: Boolean
tagTypes: [TagType]
tagClass: CfihosTagClass
functionalLocation: FunctionalLocation # --> To be deprecated. Use functionalLocations instead
functionalLocations: [FunctionalLocation]
equipment: Equipment # --> To be deprecated. Use equipments instead
equipments: [Equipment]
reportingUnit: ReportingUnit # --> To be deprecated. Use reportingUnits instead
reportingUnits: [ReportingUnit]
}''',
DATA_MODEL,
{ViewId(SPACE, "TagBeta", "7#")},
set(),
id="Type with comments",
),
]

DirectiveTestCases = [
Expand Down
Loading