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

feat (api): support to custom types #12750

Merged
merged 33 commits into from
Feb 21, 2024
Merged

feat (api): support to custom types #12750

merged 33 commits into from
Feb 21, 2024

Conversation

erickriva
Copy link
Contributor

@erickriva erickriva commented Dec 24, 2023

Description of changes

Added support for custom types in GraphQL API.

Issue #, if available

Refer to aws-amplify/amplify-category-api#2096, but I managed to work modifying this lib.

Description of how you validated changes

Installing locally in a real app project.

Checklist

  • PR description included
  • yarn test passes
  • Tests are changed or added
  • Relevant documentation is changed or added (and PR referenced)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@erickriva
Copy link
Contributor Author

erickriva commented Dec 24, 2023

@svidgen @iartemiev I hope you can help me with it.
Apparently, it is needed a change in types from @aws-amplify/data-schema-types for custom types to work as a fully experience. Can I contribute to it or this is a private package?

Edit: as far i can see, this PR is fully working and ready to merge. I just don't mark it as 'ready for review' because I don't know if makes sense to merge it without TS is fully functional.

@iartemiev
Copy link
Contributor

@erickriva thanks for opening another PR! data-schema-types is indeed in a private repo. We will be migrating the code into https://github.com/aws-amplify/amplify-category-api/ in the near future.

In the meantime we'll work on adding Custom Type support to the custom selection set types. We'll release a new version of that package once that's ready. Most of the team is out on vacation right now, so realistically we should be able to get it out towards the end of next week. I'll let leave a comment here as soon as the new version of the types package has been published.

@iartemiev
Copy link
Contributor

@erickriva btw the type issues appears to be limited to nullable custom type fields specifically.

E.g. if you were to change your field definition to before: a.ref("PregnancyBefore").required()
You can use a selection set like ['before.*', 'before.tryingSince'] without type errors.

We'll work on supporting nullable custom type fields with custom selection set.

@iartemiev
Copy link
Contributor

@erickriva we just published an updated version of data-schema-types@0.6.11

This version includes the correct paths for custom types on nullable fields in the generated custom selection set type, e.g. [ "id", "before.tryingSince" ] should no longer surface a TS error.

To get access to these changes please update the 2 data-schema dependencies in api-graphql/package.json:

"devDependencies": {
  "@aws-amplify/data-schema": "^0.12.13",

and

"dependencies": {
  "@aws-amplify/data-schema-types": "^0.6.11",

@erickriva
Copy link
Contributor Author

@iartemiev Thanks for the answer. Sadly, I have no access to my computer at the moment to test this update, but as soon as I get access I'll be checking if it works well.

@erickriva
Copy link
Contributor Author

@iartemiev Nice! It's working good. Setting it as Ready for review.

@erickriva erickriva marked this pull request as ready for review January 6, 2024 19:03
@erickriva erickriva requested review from a team as code owners January 6, 2024 19:03
@erickriva
Copy link
Contributor Author

@iartemiev I may have found a blocker.

Checking AppSync for schema, props related to custom types are not generated in GraphQL types Model{MODEL_NAME}ConditionInput and Model{MODEL_NAME}FilterInput.

Don't know if this is a bug or a feature not implemented yet. Can you clarify it?

@erickriva erickriva marked this pull request as draft January 13, 2024 18:33
@erickriva erickriva marked this pull request as ready for review January 13, 2024 22:09
@iartemiev
Copy link
Contributor

@erickriva I'm sorry, I missed your updates on this PR. I'll get it reviewed ASAP. Could you please resolve the conflicts when you get a chance?

@iartemiev
Copy link
Contributor

@iartemiev I may have found a blocker.

Checking AppSync for schema, props related to custom types are not generated in GraphQL types Model{MODEL_NAME}ConditionInput and Model{MODEL_NAME}FilterInput.

Don't know if this is a bug or a feature not implemented yet. Can you clarify it?

I believe this is expected behavior at the moment. What are the use cases you have in mind that are blocked by this?

@erickriva
Copy link
Contributor Author

Think of an app which has a 'diary' annotation, which multiple people can edit simultaneously.
It shows only days of a week in a row (initially current week), with a check indicator if there is already an existing annotation.

What if 'Person A' adds an annotation for any day of past week?
'Person B' app would need to get all items in database (probably using a lot more of bandwidth) and re-render UI components because of new data, but past week is not even showing in screen.

Bandwidth and re-renders could be cut, improving user experience without much work (good for a simple app).

@iartemiev
Copy link
Contributor

@erickriva couldn't you just use a model field for that value, which is already filterable? What's the benefit specifically for custom types?

@iartemiev
Copy link
Contributor

Could you please bump the size limit here to 37.50 kB

@erickriva erickriva requested a review from a team as a code owner February 16, 2024 20:25
@erickriva
Copy link
Contributor Author

@erickriva couldn't you just use a model field for that value, which is already filterable? What's the benefit specifically for custom types?

Surely not the best example 🤔. I have created off the top of my head, trying to explain it. Maybe missing some details.
Well, I will check my specific use case later for possibility to use a model. If needed, I can open a new issue. Anyway, I believe this PR is not tied to it.

@iartemiev iartemiev merged commit 7d95fa1 into aws-amplify:main Feb 21, 2024
30 checks passed
@iartemiev
Copy link
Contributor

@erickriva - thank you so much for contributing to Amplify again! These changes have now been published to the latest aws-amplify@unstable version. They'll be included in the next stable release ETA <= 1 week.

@JJK801
Copy link

JJK801 commented Feb 23, 2024

@erickriva 🙏 thank for your fix as it solves a problem on which i spent several hours today (inconsistent returns from observeQuery when using selectionSet)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants