-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
GraphQL Changeset API to rename a type #4211
Comments
Yep, that's the only way to do it currently. Under the hood, the idea that each type has exactly one name is used pretty strongly. However, it might be possible to introduce multiple-names-per-type -- I can take a look in the next couple of days and follow up here. My thought would be to follow the same approach used for the other dynamic schema structure methods: add a So, it seems possible, but it'll require a bit of work 😅 ! |
👍 Well I've already handled this one case the type extension way. It's not too bad. It did take me a while to wrap my head around the fact that to change a mutation's argument, I was not supposed to modify the individual mutation's class (extending GraphQL::Schema::Mutation), but instead modify the argument on the mutation field on the Mutation type 🤯. Some mutation specific pointers on https://graphql-ruby.org/changesets/definition.html wouldn't go amiss. |
I ran into #4564 while working on a solution to this issue. In case it inspires an upstream API to get built heres ours: We built a mixin for all object classes that wraps the built in GraphQL Enterprise Changesets API to make it a bit less laborious to replace a type throughout the entire schema, at once. Renaming a type is done by replacing it with an identical type by a different name, so this Example: renaming an object Bovine to Cow
# Leave your existing type alone, and create a new type with the new name
class BovineType < Types::BaseObject
field :name, String, null: false
end
# Since you want the same logic, you can extend your old type for DRY-ness
class CowType < BovineType
replaces BovineType, in: Changesets::BovineToCowChangeset
end
class QueryType < Types::BaseObject
# Now switch any references to the old type to the new type.
# The framework will see that CowType.replaces is defined, and generate a backwards compatible API.
# Note: If you want to rename the field as well, you're probably better off using plain GraphQL Ent Changesets.
field :best_farm_animal, CowType, null: false
end Under the hood we override |
Is your feature request related to a problem? Please describe.
I am trying to change the
graphql_name
of a type using a Changeset, but the syntax is not validDescribe the solution you'd like
Describe alternatives you've considered
I guess this can also be achieved by creating a new type constant which extends the original, but call
graphql_name
to rename the new constant (or just relies on the new constant's name reflecting what we want thegraphql_name
to be). This seems needlessly laborious to me though.The text was updated successfully, but these errors were encountered: