Skip to content
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

Make passing in the params by model api identifier optional #178

Merged
merged 1 commit into from
Jun 1, 2023

Conversation

jasong689
Copy link
Contributor

This PR makes it optional to wrap your model params for create/update in the model api identifier. The only exception is if there is a field with the same api identifier as the model, then the params must be wrapped in the model api identifier; this is because there's no way to tell if the consumer is passing in model params or field value.

It would be nice to be able to test that the correct query/variables are called but the mutations rely on transactions via ws. This is a bit difficult to mock I think without adding some interfaces so that we can create a mock transaction, not sure if that was worth adding here.

PR Checklist

  • Important or complicated code is tested
  • Any user facing changes are documented in the Gadget-side changelog
  • Any immediate changes are slated for release in Gadget via a generated package dependency bump
  • Versions within this monorepo are matching and there's a valid upgrade path

@thegedge
Copy link
Contributor

Nice. This deals with the internal API. Do we have plans to do something similar for the public API?

@jasong689
Copy link
Contributor Author

We certainly do! https://github.com/gadget-inc/gadget/pull/6455

@jasong689 jasong689 force-pushed the optional-api-identifier branch 3 times, most recently from f083e9d to 95da719 Compare April 28, 2023 19:08
@jasong689 jasong689 force-pushed the optional-api-identifier branch 2 times, most recently from f018847 to bd350a3 Compare May 11, 2023 17:47
@jasong689
Copy link
Contributor Author

ready for another review. this was updated to throw an error if the flat style is used and the model has ambiguous identifiers

@jasong689 jasong689 requested a review from thegedge May 11, 2023 17:55
@jasong689
Copy link
Contributor Author

poke @airhorns @thegedge. when you get a chance 👀

Copy link
Contributor

@airhorns airhorns left a comment

Choose a reason for hiding this comment

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

LGTM!

packages/api-client-core/src/InternalModelManager.ts Outdated Show resolved Hide resolved
packages/api-client-core/src/InternalModelManager.ts Outdated Show resolved Hide resolved
}

if (this.apiIdentifier in record) {
recordData = recordData[this.apiIdentifier];
Copy link
Contributor

Choose a reason for hiding this comment

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

👍 looks like we don't have any codepath that could have extra params in the internal API right now, but we'll have to remember that if that changes in the future this would potentially break (since it would clobber those params). Very likely we'd catch that kind of change in CI.

packages/api-client-core/src/InternalModelManager.ts Outdated Show resolved Hide resolved
) {
this.capitalizedApiIdentifier = camelize(apiIdentifier);
}

private validateRecord(record: RecordData) {
if (!this.options || !this.options.hasAmbiguousIdentifiers) {
Copy link
Contributor

Choose a reason for hiding this comment

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

🙌

@jasong689 jasong689 merged commit 2fc5671 into main Jun 1, 2023
@jasong689 jasong689 deleted the optional-api-identifier branch June 1, 2023 16:29
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.

3 participants