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

Add support for embedded structs #3242

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

adrianlungu
Copy link

@adrianlungu adrianlungu commented Sep 4, 2024

Hello,

This is an attempt at implementing support for embedded types, as also described here.

The current implementation generates a base struct from any interface, which is subsequently embedded in any struct that implements that given interface.

It is quite naive at the moment, i.e. if you have a GraphQL type implementing multiple interfaces sharing the same fields, it will create an ambiguity issue in the getters.

Configuration options have been added to enable this functionality, and it's disabled by default. The Base prefix can also be changed in case someone wants the base structs to not be exported, or prefers a different naming convention.

This is tricky to get right but any feedback and/or support on making this better is welcome!

I have:

  • Added tests covering the bug / feature (see testing)
  • Updated any relevant documentation (see docs)

@adrianlungu adrianlungu changed the title add support for embedded structs when a graphql type implements an in… Add support for embedded structs Sep 4, 2024
Adrian Lungu added 2 commits September 5, 2024 15:00
refactor to use `getObject` to create the base struct to be used in embedding;
add test for embedded structs;
update models.gotpl to not create the `` for tags when there are no tags
@adrianlungu
Copy link
Author

Made an update to:

  • Fix a bug I introduced when moving the code out of MutateConfig into separate getInterface, getObject...
  • Slightly refactor where the model for the base struct used in embedding is created; to improve the code structure
  • Added a test to make sure the code is generated properly

@coveralls
Copy link

coveralls commented Sep 8, 2024

Coverage Status

coverage: 56.774% (+0.1%) from 56.679%
when pulling b07f5e8 on adrianlungu:embed-struct
into 4c4be0a on 99designs:master.

@adrianlungu
Copy link
Author

Security check seems to be failing on something from upstream ? 🤔

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.

2 participants