diff --git a/airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py b/airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py index c63066953..9ff2e9018 100644 --- a/airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py +++ b/airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py @@ -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) diff --git a/airbyte_cdk/sources/declarative/declarative_component_schema.yaml b/airbyte_cdk/sources/declarative/declarative_component_schema.yaml index 305b351bc..e1a2532b0 100644 --- a/airbyte_cdk/sources/declarative/declarative_component_schema.yaml +++ b/airbyte_cdk/sources/declarative/declarative_component_schema.yaml @@ -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. @@ -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 diff --git a/airbyte_cdk/sources/declarative/models/declarative_component_schema.py b/airbyte_cdk/sources/declarative/models/declarative_component_schema.py index d7328d0ce..f0f2d5966 100644 --- a/airbyte_cdk/sources/declarative/models/declarative_component_schema.py +++ b/airbyte_cdk/sources/declarative/models/declarative_component_schema.py @@ -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): @@ -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[ diff --git a/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py b/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py index 97ef78d48..cc961fae7 100644 --- a/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py +++ b/airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py @@ -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: diff --git a/unit_tests/manifest_migrations/conftest.py b/unit_tests/manifest_migrations/conftest.py index 14caf8865..638d5dc9a 100644 --- a/unit_tests/manifest_migrations/conftest.py +++ b/unit_tests/manifest_migrations/conftest.py @@ -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": { @@ -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"}, }, }, }, @@ -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"}, }, }, }, diff --git a/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py b/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py index b112791e7..786807aa6 100644 --- a/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py +++ b/unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py @@ -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"}}, ), ], )