Skip to content

Commit 5d9da98

Browse files
committed
refactor: rename SiteDataPush to UserDataPush
1 parent 732bca2 commit 5d9da98

File tree

7 files changed

+107
-55
lines changed

7 files changed

+107
-55
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ repos:
1717
- id: pre-commit-update
1818

1919
- repo: https://github.com/astral-sh/ruff-pre-commit
20-
rev: v0.14.4
20+
rev: v0.14.5
2121
hooks:
2222
- id: ruff-check
2323
args: [--fix]

terraso_backend/apps/graphql/schema/schema.graphql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,9 +1682,9 @@ type Mutations {
16821682
deleteUserFromProject(input: ProjectDeleteUserMutationInput!): ProjectDeleteUserMutationPayload!
16831683
updateUserRoleInProject(input: ProjectUpdateUserRoleMutationInput!): ProjectUpdateUserRoleMutationPayload!
16841684
markProjectSeen(input: ProjectMarkSeenMutationInput!): ProjectMarkSeenMutationPayload!
1685-
updateSoilData(input: SoilDataUpdateMutationInput!): SoilDataUpdateMutationPayload! @deprecated(reason: "Use push_site_data instead.")
1686-
updateDepthDependentSoilData(input: DepthDependentSoilDataUpdateMutationInput!): DepthDependentSoilDataUpdateMutationPayload! @deprecated(reason: "Use push_site_data instead.")
1687-
pushSoilData(input: SoilDataPushInput!): SoilDataPushPayload! @deprecated(reason: "Use push_site_data instead.")
1685+
updateSoilData(input: SoilDataUpdateMutationInput!): SoilDataUpdateMutationPayload! @deprecated(reason: "Use push_user_data instead.")
1686+
updateDepthDependentSoilData(input: DepthDependentSoilDataUpdateMutationInput!): DepthDependentSoilDataUpdateMutationPayload! @deprecated(reason: "Use push_user_data instead.")
1687+
pushSoilData(input: SoilDataPushInput!): SoilDataPushPayload! @deprecated(reason: "Use push_user_data instead.")
16881688

16891689
"""
16901690
To enable offline functionality.
@@ -1694,10 +1694,10 @@ type Mutations {
16941694
16951695
Partial updates are possible, if failure happens at the level of a sub-mutation, or more granularly within the sub-mutation.
16961696
"""
1697-
pushSiteData(input: SiteDataPushInput!): SiteDataPushPayload!
1698-
updateSoilDataDepthInterval(input: SoilDataUpdateDepthIntervalMutationInput!): SoilDataUpdateDepthIntervalMutationPayload! @deprecated(reason: "Use push_site_data instead.")
1699-
deleteSoilDataDepthInterval(input: SoilDataDeleteDepthIntervalMutationInput!): SoilDataDeleteDepthIntervalMutationPayload! @deprecated(reason: "Use push_site_data instead.")
1700-
updateSoilMetadata(input: SoilMetadataUpdateMutationInput!): SoilMetadataUpdateMutationPayload! @deprecated(reason: "Use push_site_data instead.")
1697+
pushUserData(input: UserDataPushInput!): UserDataPushPayload!
1698+
updateSoilDataDepthInterval(input: SoilDataUpdateDepthIntervalMutationInput!): SoilDataUpdateDepthIntervalMutationPayload! @deprecated(reason: "Use push_user_data instead.")
1699+
deleteSoilDataDepthInterval(input: SoilDataDeleteDepthIntervalMutationInput!): SoilDataDeleteDepthIntervalMutationPayload! @deprecated(reason: "Use push_user_data instead.")
1700+
updateSoilMetadata(input: SoilMetadataUpdateMutationInput!): SoilMetadataUpdateMutationPayload! @deprecated(reason: "Use push_user_data instead.")
17011701
updateProjectSoilSettings(input: ProjectSoilSettingsUpdateMutationInput!): ProjectSoilSettingsUpdateMutationPayload!
17021702
updateProjectSoilSettingsDepthInterval(input: ProjectSoilSettingsUpdateDepthIntervalMutationInput!): ProjectSoilSettingsUpdateDepthIntervalMutationPayload!
17031703
deleteProjectSoilSettingsDepthInterval(input: ProjectSoilSettingsDeleteDepthIntervalMutationInput!): ProjectSoilSettingsDeleteDepthIntervalMutationPayload!
@@ -2436,7 +2436,7 @@ Pushes at least one of the following sub-mutations:
24362436
24372437
Partial updates are possible, if failure happens at the level of a sub-mutation, or more granularly within the sub-mutation.
24382438
"""
2439-
type SiteDataPushPayload {
2439+
type UserDataPushPayload {
24402440
errors: GenericScalar
24412441
soilDataResults: [SoilDataPushEntry!]
24422442
soilMetadataResults: [SoilMetadataPushEntry!]
@@ -2464,7 +2464,7 @@ enum SoilMetadataPushFailureReason {
24642464
INVALID_DATA
24652465
}
24662466

2467-
input SiteDataPushInput {
2467+
input UserDataPushInput {
24682468
soilDataEntries: [SoilDataPushInputEntry!] = null
24692469
soilMetadataEntries: [SoilMetadataPushInputEntry!] = null
24702470
clientMutationId: String

terraso_backend/apps/graphql/schema/schema.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
SiteNoteDeleteMutation,
3333
SiteNoteUpdateMutation,
3434
)
35-
from apps.soil_id.graphql.site_data.push_mutation import SiteDataPush
3635
from apps.soil_id.graphql.soil_data.mutations import (
3736
DepthDependentSoilDataUpdateMutation,
3837
SoilDataDeleteDepthIntervalMutation,
@@ -47,6 +46,7 @@
4746
ProjectSoilSettingsUpdateDepthIntervalMutation,
4847
ProjectSoilSettingsUpdateMutation,
4948
)
49+
from apps.soil_id.graphql.sync.push_mutation import UserDataPush
5050

5151
from .commons import TerrasoRelayNode
5252
from .data_entries import (
@@ -193,21 +193,21 @@ class Mutations(graphene.ObjectType):
193193
update_user_role_in_project = ProjectUpdateUserRoleMutation.Field()
194194
mark_project_seen = ProjectMarkSeenMutation.Field()
195195
update_soil_data = SoilDataUpdateMutation.Field(
196-
deprecation_reason="Use push_site_data instead."
196+
deprecation_reason="Use push_user_data instead."
197197
)
198198
update_depth_dependent_soil_data = DepthDependentSoilDataUpdateMutation.Field(
199-
deprecation_reason="Use push_site_data instead."
199+
deprecation_reason="Use push_user_data instead."
200200
)
201-
push_soil_data = SoilDataPush.Field(deprecation_reason="Use push_site_data instead.")
202-
push_site_data = SiteDataPush.Field()
201+
push_soil_data = SoilDataPush.Field(deprecation_reason="Use push_user_data instead.")
202+
push_user_data = UserDataPush.Field()
203203
update_soil_data_depth_interval = SoilDataUpdateDepthIntervalMutation.Field(
204-
deprecation_reason="Use push_site_data instead."
204+
deprecation_reason="Use push_user_data instead."
205205
)
206206
delete_soil_data_depth_interval = SoilDataDeleteDepthIntervalMutation.Field(
207-
deprecation_reason="Use push_site_data instead."
207+
deprecation_reason="Use push_user_data instead."
208208
)
209209
update_soil_metadata = SoilMetadataUpdateMutation.Field(
210-
deprecation_reason="Use push_site_data instead."
210+
deprecation_reason="Use push_user_data instead."
211211
)
212212
update_project_soil_settings = ProjectSoilSettingsUpdateMutation.Field()
213213
update_project_soil_settings_depth_interval = (

terraso_backend/apps/graphql/views.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,68 @@
1313
# You should have received a copy of the GNU Affero General Public License
1414
# along with this program. If not, see https://www.gnu.org/licenses/.
1515

16+
import re
17+
18+
import structlog
1619
from django.views.generic import TemplateView
1720
from graphene_django.views import GraphQLView
1821

1922
from apps.auth.mixins import AuthenticationRequiredMixin
2023

24+
logger = structlog.get_logger(__name__)
25+
2126

2227
class TerrasoGraphQLView(AuthenticationRequiredMixin, GraphQLView):
2328
def get_auth_enabled(self):
2429
return False
2530

31+
def _extract_operation_name(self, query, operation_name):
32+
"""Extract operation name from query string if not explicitly provided"""
33+
if operation_name:
34+
return operation_name
35+
36+
if not query:
37+
return "unnamed"
38+
39+
query = query.strip()
40+
41+
# Try to find named operation: mutation OperationName or query OperationName
42+
match = re.search(r"(?:mutation|query)\s+(\w+)", query)
43+
if match:
44+
return match.group(1)
45+
46+
# Try to find field name in anonymous operation: mutation { fieldName or query { fieldName
47+
match = re.search(r"(?:mutation|query)\s*\{\s*(\w+)", query)
48+
if match:
49+
return match.group(1)
50+
51+
# For simple queries without mutation/query keyword: { fieldName
52+
match = re.search(r"^\{\s*(\w+)", query)
53+
if match:
54+
return match.group(1)
55+
56+
return "unnamed"
57+
58+
def execute_graphql_request(
59+
self, request, data, query, variables, operation_name, show_graphiql=False
60+
):
61+
"""Override to log GraphQL operation names before execution"""
62+
63+
# Extract operation name from query if not provided
64+
extracted_operation = self._extract_operation_name(query, operation_name)
65+
66+
# Log the GraphQL operation
67+
logger.info(
68+
"GraphQL operation",
69+
operation_name=extracted_operation,
70+
is_mutation=query.strip().startswith("mutation") if query else False,
71+
)
72+
73+
# Call parent implementation
74+
return super().execute_graphql_request(
75+
request, data, query, variables, operation_name, show_graphiql
76+
)
77+
2678

2779
class TerrasoGraphQLDocs(TemplateView):
2880
template_name = "docs.html"

terraso_backend/apps/soil_id/graphql/soil_metadata/push_mutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SoilMetadataPushInputEntry(graphene.InputObjectType):
6060

6161
class SoilMetadataPush(BaseWriteMutation):
6262
"""
63-
Note: as of 2025-10 this mutation is not exposed on its own; it is only used as part of SiteDataPush (similar to how SiteDataPush uses SoilDataPush).
63+
Note: as of 2025-10 this mutation is not exposed on its own; it is only used as part of UserDataPush (similar to how UserDataPush uses SoilDataPush).
6464
"""
6565

6666
results = graphene.Field(graphene.List(graphene.NonNull(SoilMetadataPushEntry)), required=True)

terraso_backend/apps/soil_id/graphql/site_data/push_mutation.py renamed to terraso_backend/apps/soil_id/graphql/sync/push_mutation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
logger = structlog.get_logger(__name__)
3333

3434

35-
class SiteDataPush(BaseWriteMutation):
35+
class UserDataPush(BaseWriteMutation):
3636
"""
3737
To enable offline functionality.
3838
Pushes at least one of the following sub-mutations:

0 commit comments

Comments
 (0)