-
Notifications
You must be signed in to change notification settings - Fork 353
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(respect-graphqlname-input): GraphQLName Annotation for Input… #1949
feat(respect-graphqlname-input): GraphQLName Annotation for Input… #1949
Conversation
… Type Suffix Suppression
Note that this might potentially cause issues when |
Thanks for your input dariuszkuc, If I have understood your suggestion correctly, is it like we don't append output as a suffix in case of output types? And use of this @GraphQLInputName would be to to have this current logic? If yes, I am liking this approach because if modify the @GraphQLName and when the client would move onto the new version it may potentially be multiple changes for them and @GraphQLInputName would be the independent change. Kindly help with my understanding and I can proceed accordingly. |
I took a look into this further that how we can actually support @GraphQLInputName and this is the class where that logic is to generateInputObject If we introduce @GraphQLInputName annotation, If we directly replace getSimpleName to getInputClassSimpleName (function which we would introduce) it could be breaking change and may force all the clients to add the GraphQLInputName annotation. I was thinking if by having if check in this generateInputObject.kt class based on annotation we can support both? If client is using GraphQLInputName then it won't append the input suffix but if using GraphQLName it would append the Input as suffix thoughts? |
we had an internal discussion about this PR and we believe that keeping Add a second argument of type enum to the @Target(AnnotationTarget.CLASS, AnnotationTarget.VALUE_PARAMETER, AnnotationTarget.PROPERTY, AnnotationTarget.FUNCTION)
annotation class GraphQLName(val value: String, val target: GraphQLNameTarget = GraphQLNameTarget.BOTH)
enum class GraphQLNameTarget {
INPUT,
OUTPUT,
BOTH
}
@GraphQLName(value = "YourType", target = GraphQLName.INPUT)
@GraphQLName(value = "YourType", target = GraphQLName.OUTPUT)
@GraphQLName(value = "YourType", target = GraphQLName.BOTH) // default |
Thanks Samuel, for your input. One thing I've noticed is that currently in our enum, we're using the parameter OUTPUT. However, I believe we're not updating the output class accordingly. We don't need to modify the name of the output class because it's managed automatically by the @GraphQLName annotation. This annotation doesn't append any suffix. Are you suggesting something on output as well? |
…pe' into feat/respect-graphqlname-inputtype
...r/src/main/kotlin/com/expediagroup/graphql/generator/internal/extensions/kClassExtensions.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After thinking about it a little bit more I think there is actually much simpler solution. We already have a mechanism to restrict types to input/output only -> https://opensource.expediagroup.com/graphql-kotlin/docs/8.x.x/schema-generator/customizing-schemas/restricting-input-output so lets use that
@Throws(CouldNotGetNameOfKClassException::class)
internal fun KClass<*>.getSimpleName(isInputClass: Boolean = false): String {
val isInputOnlyLocation = this.findAnnotation<GraphQLValidObjectLocations>().let { it != null && it.locations.size == 1 && it.locations.contains(GraphQLValidObjectLocations.Locations.INPUT_OBJECT) }
val name = this.getGraphQLName()
?: this.simpleName
?: throw CouldNotGetNameOfKClassException(this)
return when {
isInputClass -> if (name.endsWith(INPUT_SUFFIX, true) || isInputOnlyLocation) name else "$name$INPUT_SUFFIX"
else -> name
}
}
So your use case would be solved by applying valid location on types, i.e.
@GraphQLValidObjectLocations([Locations.INPUT_OBJECT])
@GraphQLName("FooBar")
class Foo {
// whatever
}
Can you also update the https://github.com/ExpediaGroup/graphql-kotlin/blob/master/website/docs/schema-generator/customizing-schemas/renaming-fields.md with details about the input type naming behavior.
Sure, I can update this doc but before that I am thinking to close on this PR so that I can link the new documentation if require or if we don't have any existing way.~~ |
Kindly, ignore my previous comment, I got the intention will modify the code accordingly. |
This seems to be working fine? |
Yeah, this change looks good but I was wondering since currently it accepts the list, if one mentions multiple Locations, like INPUT, OUTPUT, In that case it would simply ignore, I was just wondering like previously we discussed to have the better handling for OUTPUT as well, If we want to handle it. |
Currently we validate the location position when generating input/output types -> by default we handle the type as if it is applicable on both locations. So it is not possible to have input only type and generate output type names. When applying custom renaming rules we preserve the names for output types but are appending If your type is applicable for both input and output you need to have some unique discriminator there - it is not possible to use same type name for both input and output type. Location discriminator is the simplest way to allow users to skip the unnecessary suffixes. There is another potential use case that we currently don't handle -> ability to provide custom input AND output type names. In order to support that we would need separate input/output name annotations OR some repeatable annotations with some flags to distinguish between input/output. IMHO that is not a common scenario and we probably shouldn't be supporting it at this point of time. |
makes sense, thanks for the explanation |
I validated the changes which you have made and they are working fine. |
) ### 📝 Description Currently input types are always suffixed with `Input` which is problematic as there are use cases where users might want to provide different custom name. This change adds check whether specified type is input only and if thats the case it does not attempt to add `Input` suffix. ### 🔗 Related Issues Supersedes #1949
Addressed in #1960 |
) ### 📝 Description Currently input types are always suffixed with `Input` which is problematic as there are use cases where users might want to provide different custom name. This change adds check whether specified type is input only and if thats the case it does not attempt to add `Input` suffix. ### 🔗 Related Issues Supersedes #1949
) ### 📝 Description Currently input types are always suffixed with `Input` which is problematic as there are use cases where users might want to provide different custom name. This change adds check whether specified type is input only and if thats the case it does not attempt to add `Input` suffix. ### 🔗 Related Issues Supersedes #1949
… Type Suffix Suppression
Issue Description
While migrating the capability (reviews) to the federated subgraph, it was noticed that in the older supergraph, one field InputLocalizedString was not in standard format, meaning it didn't have the "Input" suffix. However, while using the graphql-kotlin library, it was discovered that it forcefully appends the "Input" suffix in case of input types and making it as a InputLocalizedString, which is the breaking change for the end users/ customers.
Fix Description
In this fix, the idea is to respect the @GraphQLName annotation. Whatever name is provided for input types, it is expected not to modify it. If someone wants to explicitly append "input" suffix in input types, they can include it in the value of the annotation.
Is it the breaking change?
Yes, it could potentially cause a breaking change for clients who are using the @GraphQLName annotation, as it will always append "input" as a suffix. For them, when the schema is compiled, they will need to update the codebase to explicitly append "Input" as a suffix in the @GraphQLName annotation.