Skip to content

fix: request_body GraphQL implementation #629

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

Merged
merged 7 commits into from
Jul 1, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def _migrate_body_json(self, manifest: ManifestType, key: str) -> None:
if isinstance(manifest[key], str):
self._migrate_value(manifest, key, text_type)
elif isinstance(manifest[key], dict):
if manifest[key].get(query_key) is not None:
if isinstance(manifest[key].get(query_key), str):
self._migrate_value(manifest, key, graph_ql_type)
else:
self._migrate_value(manifest, key, json_object_type)
Expand Down
29 changes: 2 additions & 27 deletions airbyte_cdk/sources/declarative/declarative_component_schema.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2140,30 +2140,6 @@ definitions:
- stream_interval
- stream_partition
- stream_slice
examples:
- type: RequestBodyJsonObject
value:
sort_order: "ASC"
sort_field: "CREATED_AT"
- type: RequestBodyJsonObject
value:
key: "{{ config['value'] }}"
- type: RequestBodyJsonObject
value:
sort:
field: "updated_at"
order: "ascending"
- type: RequestBodyPlainText
value: "plain_text_body"
- type: RequestBodyUrlEncodedForm
value:
param1: "value1"
param2: "{{ config['param2_value'] }}"
- type: RequestBodyGraphQL
value:
query:
param1: "value1"
param2: "{{ config['param2_value'] }}"
error_handler:
title: Error Handler
description: Error handler component that defines how to handle errors.
Expand Down Expand Up @@ -4326,10 +4302,9 @@ definitions:
- query
properties:
query:
type: object
additionalProperties: true
type: string
description: The GraphQL query to be executed
default: {}
default: "query {\n \n}"
additionalProperties: true
DpathValidator:
title: Dpath Validator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1554,7 +1554,7 @@ class RequestBodyGraphQlQuery(BaseModel):
class Config:
extra = Extra.allow

query: Dict[str, Any] = Field(..., description="The GraphQL query to be executed")
query: str = Field(..., description="The GraphQL query to be executed")


class ValidateAdheresToSchema(BaseModel):
Expand Down Expand Up @@ -2595,34 +2595,6 @@ class HttpRequester(BaseModelWithDeprecations):
] = Field(
None,
description="Specifies how to populate the body of the request with a payload. Can contain nested objects.",
examples=[
{
"type": "RequestBodyJsonObject",
"value": {"sort_order": "ASC", "sort_field": "CREATED_AT"},
},
{
"type": "RequestBodyJsonObject",
"value": {"key": "{{ config['value'] }}"},
},
{
"type": "RequestBodyJsonObject",
"value": {"sort": {"field": "updated_at", "order": "ascending"}},
},
{"type": "RequestBodyPlainText", "value": "plain_text_body"},
{
"type": "RequestBodyUrlEncodedForm",
"value": {"param1": "value1", "param2": "{{ config['param2_value'] }}"},
},
{
"type": "RequestBodyGraphQL",
"value": {
"query": {
"param1": "value1",
"param2": "{{ config['param2_value'] }}",
}
},
},
],
title="Request Body",
)
error_handler: Optional[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _resolve_request_body(self) -> None:
if self.request_body.type == "RequestBodyUrlEncodedForm":
self.request_body_data = self.request_body.value
elif self.request_body.type == "RequestBodyGraphQL":
self.request_body_json = {"query": self.request_body.value.query}
self.request_body_json = self.request_body.value.dict(exclude_none=True)
elif self.request_body.type in ("RequestBodyJsonObject", "RequestBodyPlainText"):
self.request_body_json = self.request_body.value
else:
Expand Down
18 changes: 6 additions & 12 deletions unit_tests/manifest_migrations/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,10 +740,8 @@ def manifest_with_request_body_json_and_data_to_migrate_to_request_body() -> Dic
# the `request_body_json` is expected to be migrated to the `request_body` key,
# this example holds the GraphQL query object.
"request_body_json": {
"query": {
"field": "{{ config['query_field'] }}",
"value": "{{ config['query_value'] }}",
}
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
"variables": {"arg1": "test"},
},
},
"record_selector": {
Expand Down Expand Up @@ -975,10 +973,8 @@ def expected_manifest_with_migrated_to_request_body() -> Dict[str, Any]:
"request_body": {
"type": "RequestBodyGraphQL",
"value": {
"query": {
"field": "{{ config['query_field'] }}",
"value": "{{ config['query_value'] }}",
}
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
"variables": {"arg1": "test"},
},
},
},
Expand Down Expand Up @@ -1138,10 +1134,8 @@ def expected_manifest_with_migrated_to_request_body() -> Dict[str, Any]:
"request_body": {
"type": "RequestBodyGraphQL",
"value": {
"query": {
"field": "{{ config['query_field'] }}",
"value": "{{ config['query_value'] }}",
}
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
"variables": {"arg1": "test"},
},
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,11 @@ def test_interpolated_request_json(test_name, input_request_json, expected_reque
RequestBodyGraphQL(
type="RequestBodyGraphQL",
value=RequestBodyGraphQlQuery(
query={"query_key": "{{ config['option'] }}", "query_key_2": "value"}
query="query { {{ config['option'] }} }",
variables={"startDate": "{{ stream_interval['start_date'] }}"},
),
),
{"query": {"query_key": "OPTION", "query_key_2": "value"}},
{"query": "query { OPTION }", "variables": {"startDate": "2020-01-01"}},
),
],
)
Expand Down
Loading