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

Conversation

lmossman
Copy link
Contributor

@lmossman lmossman commented Jun 30, 2025

When working on the Builder UI, I noticed that the GraphQL option of the new request_body field wasn't correct - it marked the query property as an object, but it is supposed to be a string, as GraphQL queries look something like:

query {
  resource {
    field
  }
}

which is not a valid json object.

I therefore went through the CDK implementation of request_body and its associated migration logic and switched query to a string field.

I also ensured that if there are sibling properties to query (like variables, common in graphql), those are also carried through when converting to request_body_json, and added checks for this to the unit tests.


I also updated the declarative_component_schema to have a default value for query with the desired default for the Builder UI, and removed the examples from the request_body field since those were confusing in the Builder UI.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of GraphQL request bodies to ensure the "query" field is treated as a string, not an object.
  • Documentation

    • Removed example payloads from the request body documentation for clarity.
  • Refactor

    • Updated GraphQL request body structure and default values to use string queries.
    • Adjusted related tests to reflect the new string-based query format and improved variable handling.

Copy link

github-actions bot commented Jun 30, 2025

PyTest Results (Fast)

3 676 tests  ±0   3 665 ✅ ±0   6m 31s ⏱️ +15s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 9ff5e26. ± Comparison against base commit 5824a5e.

♻️ This comment has been updated with latest results.

Copy link

github-actions bot commented Jun 30, 2025

PyTest Results (Full)

3 679 tests  ±0   3 668 ✅ ±0   18m 9s ⏱️ +9s
    1 suites ±0      11 💤 ±0 
    1 files   ±0       0 ❌ ±0 

Results for commit 9ff5e26. ± Comparison against base commit 5824a5e.

♻️ This comment has been updated with latest results.

@lmossman lmossman changed the title Lmossman/fix request body graphql fix: request_body GraphQL implementation Jul 1, 2025
@lmossman lmossman marked this pull request as ready for review July 1, 2025 00:44
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR corrects the GraphQL implementation of the request_body field by treating query as a string and preserving sibling properties like variables.

  • Changed RequestBodyGraphQlQuery.query from an object to a str and removed confusing examples.
  • Updated YAML and Pydantic schema defaults for query to a string template.
  • Refined migration logic to detect GraphQL only when query is a string and updated tests accordingly.

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
unit_tests/.../test_interpolated_request_options_provider.py Updated GraphQL tests to expect a string query and include variables.
unit_tests/manifest_migrations/conftest.py Adjusted fixtures for request_body_json migration to use string query and variables.
airbyte_cdk/.../interpolated_request_options_provider.py Switched GraphQL branch to use value.dict() so siblings like variables are included.
airbyte_cdk/.../declarative_component_schema.py Changed query field type to str and removed outdated examples.
airbyte_cdk/.../declarative_component_schema.yaml Updated query property to type: string, set a string default, and removed examples.
airbyte_cdk/manifest_migrations/.../http_requester_request_body_json_data_to_request_body.py Refined detection to treat GraphQL only when query is a string.
Comments suppressed due to low confidence (2)

airbyte_cdk/sources/declarative/declarative_component_schema.yaml:4307

  • [nitpick] The default GraphQL query string contains indentation and empty lines; consider using a more concise placeholder like "query { }" to avoid confusing users.
        default: "query {\n    \n}"

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

  • [nitpick] Add a test case for a GraphQL request body without variables to verify that request_body.value.dict() correctly handles queries when no additional fields are present.
)

…erpolated_request_options_provider.py

Co-authored-by: Copilot <[email protected]>
@github-actions github-actions bot added bug Something isn't working security labels Jul 1, 2025
Copy link
Contributor

coderabbitai bot commented Jul 1, 2025

📝 Walkthrough

Walkthrough

This update changes the handling of GraphQL request bodies in the Airbyte CDK. The query field is now expected as a string instead of an object, and related schema, migration logic, and tests are updated accordingly. Example payloads in documentation and schema definitions are also removed or revised.

Changes

File(s) Change Summary
airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py Refined migration logic to check if the "query" key is a string before migrating to RequestBodyGraphQL.
airbyte_cdk/sources/declarative/declarative_component_schema.yaml Changed query type from object to string in RequestBodyGraphQlQuery; updated default; removed examples.
airbyte_cdk/sources/declarative/models/declarative_component_schema.py Changed query field type from dict to string; removed examples from request_body in HttpRequester.
airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py Changed GraphQL request body serialization to use full object dict, not just the query field.
unit_tests/manifest_migrations/conftest.py Updated test fixtures to use string GraphQL queries and added variables dictionary.
unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py Updated test to use string GraphQL query and variables; adjusted expected output accordingly.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ManifestMigration
    participant Schema
    participant RequestOptionsProvider

    User->>ManifestMigration: Provide manifest with request_body_json
    ManifestMigration->>ManifestMigration: Check if "query" is string
    alt "query" is string
        ManifestMigration->>ManifestMigration: Migrate to RequestBodyGraphQL (query as string)
    else
        ManifestMigration->>ManifestMigration: Migrate to RequestBodyJsonObject
    end
    ManifestMigration->>Schema: Update schema (query as string)
    RequestOptionsProvider->>RequestOptionsProvider: Serialize GraphQL request body as dict
Loading

Possibly related PRs

  • airbytehq/airbyte-python-cdk#521: Refactored the _migrate_body_json method for type-based migration handling of request bodies, including GraphQL queries. This PR directly builds on that logic.

Suggested labels

airbyte-python-cdk, manifest, migrations

Suggested reviewers

  • darynaishchenko

Would you like to add a note in the migration guide about the new expectation for GraphQL queries to be strings, just in case users are upgrading from older manifests—wdyt?

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py (1)

103-103: Perfect implementation of the complete GraphQL request body serialization!

This change correctly serializes the entire GraphQL request body object rather than just extracting the query field. Using .dict(exclude_none=True) ensures that optional fields like variables are only included when they have values, which is exactly what was suggested in the previous review. This preserves all sibling properties as mentioned in the PR objectives - great job implementing this enhancement!

🧹 Nitpick comments (2)
unit_tests/manifest_migrations/conftest.py (1)

740-746: Use POST instead of GET for GraphQL payloads?

These fixtures now include a RequestBodyGraphQL payload but still specify "http_method": "GET".
Bodies on GET are ignored by many servers and some CDK logic may short-circuit when the method isn’t POST/PUT/PATCH, so the test might not exercise the actual serialization path. Swapping the method to "POST" would better reflect real-world GraphQL usage and guard against regressions—wdyt?

Also applies to: 974-980, 1135-1140

airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1)

4305-4307: Default GraphQL query placeholder might be invalid – reconsider the value?

"query {\n \n}" is not a syntactically valid GraphQL document because an empty selection set is forbidden. Could we switch the default to something harmless but valid, e.g.

default: |
  query {
    __typename
  }

so that users (or the Builder UI) don’t hit parser errors when the default is used unmodified—wdyt?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5824a5e and 9ff5e26.

📒 Files selected for processing (6)
  • airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py (1 hunks)
  • airbyte_cdk/sources/declarative/declarative_component_schema.yaml (1 hunks)
  • airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1 hunks)
  • airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py (1 hunks)
  • unit_tests/manifest_migrations/conftest.py (3 hunks)
  • unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py (1 hunks)
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
Learnt from: pnilan
PR: airbytehq/airbyte-python-cdk#0
File: :0-0
Timestamp: 2024-12-11T16:34:46.319Z
Learning: In the airbytehq/airbyte-python-cdk repository, the `declarative_component_schema.py` file is auto-generated from `declarative_component_schema.yaml` and should be ignored in the recommended reviewing order.
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.
airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py (3)
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/spec.json:9-15
Timestamp: 2024-11-15T00:59:08.154Z
Learning: When code in `airbyte_cdk/cli/source_declarative_manifest/` is being imported from another repository, avoid suggesting modifications to it during the import process.
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.
airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py (1)
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
airbyte_cdk/sources/declarative/declarative_component_schema.yaml (4)

undefined

<retrieved_learning>
Learnt from: ChristoGrab
PR: #58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the YamlDeclarativeSource class in airbyte_cdk/sources/declarative/yaml_declarative_source.py, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
</retrieved_learning>

<retrieved_learning>
Learnt from: pnilan
PR: airbytehq/airbyte-python-cdk#0
File: :0-0
Timestamp: 2024-12-11T16:34:46.319Z
Learning: In the airbytehq/airbyte-python-cdk repository, the declarative_component_schema.py file is auto-generated from declarative_component_schema.yaml and should be ignored in the recommended reviewing order.
</retrieved_learning>

<retrieved_learning>
Learnt from: aaronsteers
PR: #58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in airbyte_cdk/cli/source_declarative_manifest/, including _run.py, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.
</retrieved_learning>

<retrieved_learning>
Learnt from: aaronsteers
PR: #58
File: airbyte_cdk/cli/source_declarative_manifest/spec.json:9-15
Timestamp: 2024-11-15T00:59:08.154Z
Learning: When code in airbyte_cdk/cli/source_declarative_manifest/ is being imported from another repository, avoid suggesting modifications to it during the import process.
</retrieved_learning>

unit_tests/manifest_migrations/conftest.py (2)
Learnt from: ChristoGrab
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the `YamlDeclarativeSource` class in `airbyte_cdk/sources/declarative/yaml_declarative_source.py`, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
Learnt from: aaronsteers
PR: airbytehq/airbyte-python-cdk#58
File: airbyte_cdk/cli/source_declarative_manifest/_run.py:62-65
Timestamp: 2024-11-15T01:04:21.272Z
Learning: The files in `airbyte_cdk/cli/source_declarative_manifest/`, including `_run.py`, are imported from another repository, and changes to these files should be minimized or avoided when possible to maintain consistency.
airbyte_cdk/sources/declarative/models/declarative_component_schema.py (2)

undefined

<retrieved_learning>
Learnt from: pnilan
PR: airbytehq/airbyte-python-cdk#0
File: :0-0
Timestamp: 2024-12-11T16:34:46.319Z
Learning: In the airbytehq/airbyte-python-cdk repository, the declarative_component_schema.py file is auto-generated from declarative_component_schema.yaml and should be ignored in the recommended reviewing order.
</retrieved_learning>

<retrieved_learning>
Learnt from: ChristoGrab
PR: #58
File: airbyte_cdk/sources/declarative/yaml_declarative_source.py:0-0
Timestamp: 2024-11-18T23:40:06.391Z
Learning: When modifying the YamlDeclarativeSource class in airbyte_cdk/sources/declarative/yaml_declarative_source.py, avoid introducing breaking changes like altering method signatures within the scope of unrelated PRs. Such changes should be addressed separately to minimize impact on existing implementations.
</retrieved_learning>

🧬 Code Graph Analysis (1)
airbyte_cdk/sources/declarative/requesters/request_options/interpolated_request_options_provider.py (1)
airbyte_cdk/sources/streams/http/http.py (1)
  • request_body_json (229-240)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Check: source-amplitude
  • GitHub Check: Check: source-intercom
  • GitHub Check: Check: source-pokeapi
  • GitHub Check: Check: source-hardcoded-records
  • GitHub Check: Check: source-shopify
  • GitHub Check: Pytest (Fast)
  • GitHub Check: Pytest (All, Python 3.11, Ubuntu)
  • GitHub Check: Pytest (All, Python 3.10, Ubuntu)
  • GitHub Check: SDM Docker Image Build
🔇 Additional comments (3)
airbyte_cdk/manifest_migrations/migrations/http_requester_request_body_json_data_to_request_body.py (1)

57-57: LGTM! Correct validation for string-based GraphQL queries.

The change from checking is not None to isinstance(..., str) properly validates that GraphQL queries are strings, which aligns perfectly with the PR objectives. This ensures the migration only treats request bodies as GraphQL when the query is actually a string rather than just any truthy value. Nice work!

unit_tests/sources/declarative/requesters/request_options/test_interpolated_request_options_provider.py (1)

242-246: Excellent test update for the new GraphQL format!

The test case now correctly reflects the string-based GraphQL query approach with:

  • query as a string with template interpolation
  • variables as a separate dictionary for GraphQL variables
  • Expected output properly structured with both interpolated query and variables

This perfectly validates the new implementation behavior. The test coverage looks solid - wdyt about adding an edge case where variables is None to ensure the exclude_none=True behavior is tested?

airbyte_cdk/sources/declarative/models/declarative_component_schema.py (1)

1557-1557: LGTM! GraphQL query type correction looks good.

The change from Dict[str, Any] to str for the query field is exactly right - GraphQL queries are indeed string-based rather than JSON objects. This aligns perfectly with the PR objectives to fix the request_body GraphQL implementation. Since this is auto-generated from the YAML schema, the change properly reflects the corrected type definition, wdyt?

Copy link
Contributor

@aldogonzalez8 aldogonzalez8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

APPROVED

@lmossman lmossman merged commit 2e13549 into main Jul 1, 2025
27 checks passed
@lmossman lmossman deleted the lmossman/fix-request-body-graphql branch July 1, 2025 16:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working security
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants