Skip to content
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
1 change: 1 addition & 0 deletions changelog/+escape-hfid.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed issue with improperly escaped special characters in `hfid` fields and other string values in GraphQL mutations by implementing proper JSON-style string escaping
5 changes: 4 additions & 1 deletion infrahub_sdk/graphql.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import json
from enum import Enum
from typing import Any

Expand All @@ -18,7 +19,9 @@ def convert_to_graphql_as_string(value: Any, convert_enum: bool = False) -> str:
return convert_to_graphql_as_string(value=value.value, convert_enum=True)
return value.name
if isinstance(value, str):
return f'"{value}"'
# Use json.dumps() to properly escape the string according to JSON rules,
# which are compatible with GraphQL string escaping
return json.dumps(value)
if isinstance(value, bool):
return repr(value).lower()
if isinstance(value, list):
Expand Down