-
Notifications
You must be signed in to change notification settings - Fork 651
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
Escape "type" in enums and sealed classes #4144
Conversation
✅ Deploy Preview for apollo-android-docs canceled.
|
@@ -41,7 +42,7 @@ class SchemaBuilder( | |||
private fun typesFieldSpec(): FieldSpec { | |||
val allTypenames = interfaces.map { it.name } + objects.map { it.name } + unions.map { it.name } | |||
val initilizer = allTypenames.sortedBy { it }.map { | |||
CodeBlock.of("$T.type", context.resolver.resolveSchemaType(it)) | |||
CodeBlock.of("$T.$type", context.resolver.resolveSchemaType(it)) |
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.
(Unrelated to this fix, but noticed we didn't use the constant here but we should)
Yea, that'd have been nice but quite hard to do now
Certainly the path forward. Let's do this as a transition helper for 4.0? My favorite short term solution would be throw an error and introduce a # extra.graphqls
extend enum Foo {
bar,
type @targetName(name: "type_")
} That'd make a more general solution if we bump into other situations like this. For posterity, I also asked the question on the kotlinlang slack |
Reverted escaping the enum value |
dd38a0d
to
a65e7f8
Compare
@@ -30,6 +30,21 @@ fun List<GQLDirective>.findExperimentalReason() = firstOrNull { it.name == "expe | |||
?: "Experimental" | |||
} | |||
|
|||
fun List<GQLDirective>.findTargetName() = firstOrNull { it.name == "experimental_targetName" } |
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.
Make this @ApolloInternal
? (I don't think it can be internal
?)
Historically the API in apollo-ast
isn't super well tracked but I'd like to start moving forward
@@ -24,3 +24,5 @@ fun String.escapeKotlinReservedEnumValueNames() : String { | |||
else -> this | |||
} | |||
} | |||
|
|||
fun String.isApolloReservedEnumValueName() = this == "type" |
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.
Same here... Maybe we should just start tracking the public APIs everywhere?
See
apollo-kotlin/build.gradle.kts
Line 206 in 7a56141
ignoredProjects.addAll( |
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.
Done! ✅
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.
Thanks!
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.
👍
a750fba
to
f1e5b8f
Compare
f1e5b8f
to
99209eb
Compare
Escape
type
in enums and sealed classes, because it clashes with thetype: EnumType
constant.This is the easy fix, but may be annoying (expecting to use
.type
in the client code, and realizing you have to use.type_
instead).Maybe we could instead rename the
type
constant (to__type
for instance), buttype
is used when mapping scalars so doing so globally would break client code. Instead maybe we could rename it but only for enums and sealed classes, but then it's not consistent. Instead we could rename it globally but keep a deprecatedtype
on scalars that points to__type
. Not sure if there would be other consequences I'm not seeing :) LMK what you think.Related to #4023 (comment)