Skip to content

Allow additional types to be added with custom SchemaGenerator #587

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 4 commits into from
Feb 1, 2020

Conversation

smyrick
Copy link
Contributor

@smyrick smyrick commented Jan 31, 2020

📝 Description

This is a patch change to allow additional types to more easily be extended in later PRs. As a side-effect of this change we actually simplify where types are all generated and the main generateSchema function becomes just a little more straight forward.

🔗 Related Issues

This will make #585 a little eaiser to implement

This is a patch change to allow additional types to more easily be extended in later PRs. As a side-effect of this change we actually simplify where types are all generated and the main generateSchema function becomes just a little more straight forward
@smyrick smyrick added changes: patch Changes require a patch version type: refactor Code changes that have no impact on users labels Jan 31, 2020
Copy link
Collaborator

@dariuszkuc dariuszkuc left a comment

Choose a reason for hiding this comment

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

Looks good but I'm wondering whether there should be an easier way to add the additional types, i.e. it still looks like you kind of have to hack it through to add them in. Should we add something akin to what was done for federation and addAdditionalTypesWithAnnotation?

@smyrick
Copy link
Contributor Author

smyrick commented Jan 31, 2020

I am not adding that functionality in this PR. That will be done in #585

As seen there, having a way to dynamically update the additionalTypes would be useful. Are you proposing we add a new method to the SchemaGenerator to just call addAdditionalType from the hooks? That would mean we have a circular dependency on the hooks and the schema generator. I prefer the hooks approach more.

@dariuszkuc
Copy link
Collaborator

I was thinking more along the lines of exposing the functionality so one could extend the SchemaGenerator (similar to what FederatedSchemaGenerator does) and call the method to add the types. We can go with the route of more generic support by adding it through the config.

Shane Myrick added 2 commits January 31, 2020 12:29
After we have fully generated queries,mutations, and subscriptions there are no more type references. We only have this issue when we were adding classes in the middle of generate so this actually reduces logic and branches in the library
@smyrick smyrick changed the title Refactor additional types Allow additional types to be added with custom SchemaGenerator Jan 31, 2020
@smyrick
Copy link
Contributor Author

smyrick commented Jan 31, 2020

@dariuszkuc I updated the PR. Now the method generateAdditionalTypes is protected so someone can call it from a custom schema generator. This will allow them to keep track of any additional state and still have access to the Schema generator properties.

Do not make the function open for outside calling right now. Discussing further with team and we can add the new feature in a separate PR
@smyrick
Copy link
Contributor Author

smyrick commented Feb 1, 2020

I have undone making the new method open for calling in protected scope and instead just made it private. We are still discussing on the team if we do actually want developers to use this custom behaviour or are we going against GraphQL best practices.

If we wanted to open it to protected scope later that is a simple PR.


return generator.config.hooks.willAddGraphQLTypeToSchema(type, graphQLType)
Copy link
Contributor Author

@smyrick smyrick Feb 1, 2020

Choose a reason for hiding this comment

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

We do not want to call the hook with type references. This is now required for the new format

@dariuszkuc dariuszkuc merged commit 5605e24 into ExpediaGroup:master Feb 1, 2020
@smyrick smyrick deleted the additional-types-ktype branch February 1, 2020 04:18
smyrick pushed a commit to smyrick/graphql-kotlin that referenced this pull request Feb 3, 2020
As dicussed in other PRs ExpediaGroup#587 and ExpediaGroup#585 we can allow developers to have more customization of the schema by allowing them to add additional types of their own without having to add it to the schema directly. What they do with this feature will be up to them, but from a libray perspective it is not bad feature to support.
dariuszkuc pushed a commit that referenced this pull request Feb 3, 2020
* Allow updating custom additional types

As dicussed in other PRs #587 and #585 we can allow developers to have more customization of the schema by allowing them to add additional types of their own without having to add it to the schema directly. What they do with this feature will be up to them, but from a libray perspective it is not bad feature to support.

* Make function open
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
…iaGroup#587)

* Refactor additional types

This is a patch change to allow additional types to more easily be extended in later PRs. As a side-effect of this change we actually simplify where types are all generated and the main generateSchema function becomes just a little more straight forward

* Add more unit tests

* Simplify generateAdditionalTypes logic

After we have fully generated queries,mutations, and subscriptions there are no more type references. We only have this issue when we were adding classes in the middle of generate so this actually reduces logic and branches in the library

* Remove new features for now

Do not make the function open for outside calling right now. Discussing further with team and we can add the new feature in a separate PR
dariuszkuc pushed a commit to dariuszkuc/graphql-kotlin that referenced this pull request Aug 5, 2022
* Allow updating custom additional types

As dicussed in other PRs ExpediaGroup#587 and ExpediaGroup#585 we can allow developers to have more customization of the schema by allowing them to add additional types of their own without having to add it to the schema directly. What they do with this feature will be up to them, but from a libray perspective it is not bad feature to support.

* Make function open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changes: patch Changes require a patch version type: refactor Code changes that have no impact on users
Development

Successfully merging this pull request may close these issues.

2 participants