Skip to content

Commit 2e13549

Browse files
lmossmanCopilot
andauthored
fix: request_body GraphQL implementation (#629)
Co-authored-by: Copilot <[email protected]>
1 parent 5824a5e commit 2e13549

File tree

6 files changed

+14
-72
lines changed

6 files changed

+14
-72
lines changed

airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _migrate_body_json(self, manifest: ManifestType, key: str) -> None:
5454
if isinstance(manifest[key], str):
5555
self._migrate_value(manifest, key, text_type)
5656
elif isinstance(manifest[key], dict):
57-
if manifest[key].get(query_key) is not None:
57+
if isinstance(manifest[key].get(query_key), str):
5858
self._migrate_value(manifest, key, graph_ql_type)
5959
else:
6060
self._migrate_value(manifest, key, json_object_type)

airbyte_cdk/sources/declarative/declarative_component_schema.yaml

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2140,30 +2140,6 @@ definitions:
21402140
- stream_interval
21412141
- stream_partition
21422142
- stream_slice
2143-
examples:
2144-
- type: RequestBodyJsonObject
2145-
value:
2146-
sort_order: "ASC"
2147-
sort_field: "CREATED_AT"
2148-
- type: RequestBodyJsonObject
2149-
value:
2150-
key: "{{ config['value'] }}"
2151-
- type: RequestBodyJsonObject
2152-
value:
2153-
sort:
2154-
field: "updated_at"
2155-
order: "ascending"
2156-
- type: RequestBodyPlainText
2157-
value: "plain_text_body"
2158-
- type: RequestBodyUrlEncodedForm
2159-
value:
2160-
param1: "value1"
2161-
param2: "{{ config['param2_value'] }}"
2162-
- type: RequestBodyGraphQL
2163-
value:
2164-
query:
2165-
param1: "value1"
2166-
param2: "{{ config['param2_value'] }}"
21672143
error_handler:
21682144
title: Error Handler
21692145
description: Error handler component that defines how to handle errors.
@@ -4326,10 +4302,9 @@ definitions:
43264302
- query
43274303
properties:
43284304
query:
4329-
type: object
4330-
additionalProperties: true
4305+
type: string
43314306
description: The GraphQL query to be executed
4332-
default: {}
4307+
default: "query {\n \n}"
43334308
additionalProperties: true
43344309
DpathValidator:
43354310
title: Dpath Validator

airbyte_cdk/sources/declarative/models/declarative_component_schema.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1554,7 +1554,7 @@ class RequestBodyGraphQlQuery(BaseModel):
15541554
class Config:
15551555
extra = Extra.allow
15561556

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

15591559

15601560
class ValidateAdheresToSchema(BaseModel):
@@ -2595,34 +2595,6 @@ class HttpRequester(BaseModelWithDeprecations):
25952595
] = Field(
25962596
None,
25972597
description="Specifies how to populate the body of the request with a payload. Can contain nested objects.",
2598-
examples=[
2599-
{
2600-
"type": "RequestBodyJsonObject",
2601-
"value": {"sort_order": "ASC", "sort_field": "CREATED_AT"},
2602-
},
2603-
{
2604-
"type": "RequestBodyJsonObject",
2605-
"value": {"key": "{{ config['value'] }}"},
2606-
},
2607-
{
2608-
"type": "RequestBodyJsonObject",
2609-
"value": {"sort": {"field": "updated_at", "order": "ascending"}},
2610-
},
2611-
{"type": "RequestBodyPlainText", "value": "plain_text_body"},
2612-
{
2613-
"type": "RequestBodyUrlEncodedForm",
2614-
"value": {"param1": "value1", "param2": "{{ config['param2_value'] }}"},
2615-
},
2616-
{
2617-
"type": "RequestBodyGraphQL",
2618-
"value": {
2619-
"query": {
2620-
"param1": "value1",
2621-
"param2": "{{ config['param2_value'] }}",
2622-
}
2623-
},
2624-
},
2625-
],
26262598
title="Request Body",
26272599
)
26282600
error_handler: Optional[

airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _resolve_request_body(self) -> None:
100100
if self.request_body.type == "RequestBodyUrlEncodedForm":
101101
self.request_body_data = self.request_body.value
102102
elif self.request_body.type == "RequestBodyGraphQL":
103-
self.request_body_json = {"query": self.request_body.value.query}
103+
self.request_body_json = self.request_body.value.dict(exclude_none=True)
104104
elif self.request_body.type in ("RequestBodyJsonObject", "RequestBodyPlainText"):
105105
self.request_body_json = self.request_body.value
106106
else:

unit_tests/manifest_migrations/conftest.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -740,10 +740,8 @@ def manifest_with_request_body_json_and_data_to_migrate_to_request_body() -> Dic
740740
# the `request_body_json` is expected to be migrated to the `request_body` key,
741741
# this example holds the GraphQL query object.
742742
"request_body_json": {
743-
"query": {
744-
"field": "{{ config['query_field'] }}",
745-
"value": "{{ config['query_value'] }}",
746-
}
743+
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
744+
"variables": {"arg1": "test"},
747745
},
748746
},
749747
"record_selector": {
@@ -975,10 +973,8 @@ def expected_manifest_with_migrated_to_request_body() -> Dict[str, Any]:
975973
"request_body": {
976974
"type": "RequestBodyGraphQL",
977975
"value": {
978-
"query": {
979-
"field": "{{ config['query_field'] }}",
980-
"value": "{{ config['query_value'] }}",
981-
}
976+
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
977+
"variables": {"arg1": "test"},
982978
},
983979
},
984980
},
@@ -1138,10 +1134,8 @@ def expected_manifest_with_migrated_to_request_body() -> Dict[str, Any]:
11381134
"request_body": {
11391135
"type": "RequestBodyGraphQL",
11401136
"value": {
1141-
"query": {
1142-
"field": "{{ config['query_field'] }}",
1143-
"value": "{{ config['query_value'] }}",
1144-
}
1137+
"query": "query { {{ config['query_field'] }} { {{ config['query_value'] }} }}",
1138+
"variables": {"arg1": "test"},
11451139
},
11461140
},
11471141
},

unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,11 @@ def test_interpolated_request_json(test_name, input_request_json, expected_reque
239239
RequestBodyGraphQL(
240240
type="RequestBodyGraphQL",
241241
value=RequestBodyGraphQlQuery(
242-
query={"query_key": "{{ config['option'] }}", "query_key_2": "value"}
242+
query="query { {{ config['option'] }} }",
243+
variables={"startDate": "{{ stream_interval['start_date'] }}"},
243244
),
244245
),
245-
{"query": {"query_key": "OPTION", "query_key_2": "value"}},
246+
{"query": "query { OPTION }", "variables": {"startDate": "2020-01-01"}},
246247
),
247248
],
248249
)

0 commit comments

Comments
 (0)