Skip to content

fix(dataconnect): Refactor CRUD helpers to use GraphQL variables and @allow directive#3182

Open
stephenarosaj wants to merge 12 commits into
mainfrom
rosa/enum-serialization
Open

fix(dataconnect): Refactor CRUD helpers to use GraphQL variables and @allow directive#3182
stephenarosaj wants to merge 12 commits into
mainfrom
rosa/enum-serialization

Conversation

@stephenarosaj

Copy link
Copy Markdown
Contributor

Description

✨ Refactored Data Connect CRUD operations to execute parameterized GraphQL mutations with query variables and @allow directives. This fixes the bug described by Issue #3041 where enums would not be serialized properly by the [insert,upsert](many) APIs.

To verify this fix and harden integration tests, refactored tests so that before checking for equality between the expected and actual input query strings, they are normalized.

Also updated integration testing instructions and .gitignore.

Changes

  • Removed objectToString inline GraphQL serializer
  • Added getTableNames, getObjectKeys, and getArrayObjectsKeys helpers
  • Refactored CRUD operations (insert, insertMany, upsert, upsertMany) to use GraphQL variables and @allow directives
  • Added Data Connect emulator test instructions in CONTRIBUTING.md
  • Updated ignored emulator debug logs in .gitignore so that no matter where they show up, they are properly ignored. This makes it so that even when running integration tests from the root of the SDK repo they are not tracked.

Testing

  • Added expectNormalizedExecuteGraphqlCall test helper
  • Updated CRUD unit tests to verify parameterized mutations and variables
  • Added unit tests for enum field serialization and @allow directives
  • Updated string serialization tests to check equality between normalized expected and actual query strings

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the Data Connect API client to use GraphQL variables and the @allow(fields: ...) directive for insert, insertMany, upsert, and upsertMany operations, replacing the previous manual JSON-to-GraphQL-string serialization. It also updates the unit tests to validate this new variable-based execution and adds Data Connect emulator testing instructions to the contribution guide. The review feedback highlights potential GraphQL injection vulnerabilities and syntax errors due to direct interpolation of table names and object keys into the mutation strings, recommending validation against standard GraphQL identifier patterns.

Comment thread src/data-connect/data-connect-api-client-internal.ts Outdated
Comment thread src/data-connect/data-connect-api-client-internal.ts
Comment thread src/data-connect/data-connect-api-client-internal.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant