Skip to content

Commit a7c9427

Browse files
authored
Fix scalar rename when used as input type (#717)
1 parent b09ea56 commit a7c9427

6 files changed

Lines changed: 181 additions & 6 deletions

File tree

lib/src/main/java/graphql/nadel/validation/NadelTypeValidation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ internal class NadelTypeValidation(
203203
}
204204

205205
// Ignore scalar renames, refer to test "let jsw do jsw things"
206-
if (type is NadelServiceSchemaElement.Scalar) {
206+
if (type is NadelServiceSchemaElement.Scalar && type.service.name == "jsw") {
207207
return ok()
208208
}
209209

test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things snapshot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ private suspend fun main() {
2222
public class `let jsw do jsw things snapshot` : TestSnapshot() {
2323
override val calls: List<ExpectedServiceCall> = listOf(
2424
ExpectedServiceCall(
25-
service = "service",
25+
service = "jsw",
2626
query = """
2727
| {
2828
| foo

test/src/test/kotlin/graphql/nadel/tests/legacy/renames/let jsw do jsw things.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class `let jsw do jsw things` : NadelLegacyIntegrationTest(
1313
variables = emptyMap(),
1414
services = listOf(
1515
Service(
16-
name = "service",
16+
name = "jsw",
1717
overallSchema = """
1818
type Query {
1919
foo: A
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
package graphql.nadel.tests.next.fixtures.rename
2+
3+
import graphql.nadel.NadelExecutionHints
4+
import graphql.nadel.NadelSchemas
5+
import graphql.nadel.tests.GatewaySchemaWiringFactory
6+
import graphql.nadel.tests.next.NadelIntegrationTest
7+
import graphql.scalars.ExtendedScalars
8+
import graphql.scalars.ExtendedScalars.newAliasedScalar
9+
10+
/**
11+
* The `ConfluenceLegacyPathType` scalar type is renamed and used as an input type.
12+
*
13+
* In the test snapshot we ensure the variable is defined as `PathType`.
14+
*/
15+
class RenamedScalarInputTypeTest : NadelIntegrationTest(
16+
query = """
17+
query {
18+
me {
19+
profilePicture {
20+
path(type: ABSOLUTE)
21+
}
22+
}
23+
}
24+
""".trimIndent(),
25+
services = listOf(
26+
Service(
27+
name = "confluence_legacy",
28+
overallSchema = """
29+
type Query {
30+
me: ConfluenceLegacyUser
31+
}
32+
type ConfluenceLegacyUser @renamed(from: "User") {
33+
profilePicture: ConfluenceLegacyProfilePicture
34+
}
35+
type ConfluenceLegacyProfilePicture @renamed(from: "ProfilePicture") {
36+
path(type: ConfluenceLegacyPathType!): String
37+
}
38+
scalar ConfluenceLegacyPathType @renamed(from: "PathType")
39+
""".trimIndent(),
40+
runtimeWiring = { wiring ->
41+
data class ProfilePicture(
42+
val absolutePath: String,
43+
val relativePath: String,
44+
)
45+
46+
data class User(
47+
val profilePicture: ProfilePicture,
48+
)
49+
50+
wiring
51+
.scalar(
52+
newAliasedScalar("PathType")
53+
.aliasedScalar(ExtendedScalars.Json)
54+
.build()
55+
)
56+
.type("Query") { type ->
57+
type
58+
.dataFetcher("me") { env ->
59+
User(
60+
profilePicture = ProfilePicture(
61+
relativePath = "/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70",
62+
absolutePath = "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70",
63+
),
64+
)
65+
}
66+
}
67+
.type("ProfilePicture") { type ->
68+
type
69+
.dataFetcher("path") { env ->
70+
val pfp = env.getSource<ProfilePicture>()!!
71+
when (val urlType = env.getArgument<String>("type")) {
72+
"ABSOLUTE" -> pfp.absolutePath
73+
"RELATIVE" -> pfp.relativePath
74+
else -> throw IllegalArgumentException(urlType)
75+
}
76+
}
77+
}
78+
},
79+
),
80+
),
81+
) {
82+
override fun makeExecutionHints(): NadelExecutionHints.Builder {
83+
return super.makeExecutionHints()
84+
.allDocumentVariablesHint { true }
85+
}
86+
87+
override fun makeNadelSchemas(): NadelSchemas.Builder {
88+
return super.makeNadelSchemas()
89+
.overallWiringFactory(GatewaySchemaWiringFactory())
90+
}
91+
}
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// @formatter:off
2+
package graphql.nadel.tests.next.fixtures.rename
3+
4+
import graphql.nadel.tests.next.ExpectedNadelResult
5+
import graphql.nadel.tests.next.ExpectedServiceCall
6+
import graphql.nadel.tests.next.TestSnapshot
7+
import graphql.nadel.tests.next.listOfJsonStrings
8+
import kotlin.Suppress
9+
import kotlin.collections.List
10+
import kotlin.collections.listOf
11+
12+
private suspend fun main() {
13+
graphql.nadel.tests.next.update<RenamedScalarInputTypeTest>()
14+
}
15+
16+
/**
17+
* This class is generated. Do NOT modify.
18+
*
19+
* Refer to [graphql.nadel.tests.next.UpdateTestSnapshots]
20+
*/
21+
@Suppress("unused")
22+
public class RenamedScalarInputTypeTestSnapshot : TestSnapshot() {
23+
override val calls: List<ExpectedServiceCall> = listOf(
24+
ExpectedServiceCall(
25+
service = "confluence_legacy",
26+
query = """
27+
| query (${'$'}v0: PathType!) {
28+
| me {
29+
| profilePicture {
30+
| path(type: ${'$'}v0)
31+
| }
32+
| }
33+
| }
34+
""".trimMargin(),
35+
variables = """
36+
| {
37+
| "v0": "ABSOLUTE"
38+
| }
39+
""".trimMargin(),
40+
result = """
41+
| {
42+
| "data": {
43+
| "me": {
44+
| "profilePicture": {
45+
| "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
46+
| }
47+
| }
48+
| }
49+
| }
50+
""".trimMargin(),
51+
delayedResults = listOfJsonStrings(
52+
),
53+
),
54+
)
55+
56+
/**
57+
* ```json
58+
* {
59+
* "data": {
60+
* "me": {
61+
* "profilePicture": {
62+
* "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
63+
* }
64+
* }
65+
* }
66+
* }
67+
* ```
68+
*/
69+
override val result: ExpectedNadelResult = ExpectedNadelResult(
70+
result = """
71+
| {
72+
| "data": {
73+
| "me": {
74+
| "profilePicture": {
75+
| "path": "https://atlassian.net/wiki/aa-avatar/5ee0a4ef55749e0ab6e0fb70"
76+
| }
77+
| }
78+
| }
79+
| }
80+
""".trimMargin(),
81+
delayedResults = listOfJsonStrings(
82+
),
83+
)
84+
}

test/src/test/resources/fixtures/renames/let-jsw-do-jsw-things.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: "let jsw do jsw things"
33
enabled: true
44
# language=GraphQL
55
overallSchema:
6-
service: |
6+
jsw: |
77
type Query {
88
foo: A
99
}
@@ -15,7 +15,7 @@ overallSchema:
1515
scalar D @renamed(from: "Y")
1616
# language=GraphQL
1717
underlyingSchema:
18-
service: |
18+
jsw: |
1919
type Query {
2020
foo: X
2121
}
@@ -30,7 +30,7 @@ query: |
3030
}
3131
variables: { }
3232
serviceCalls:
33-
- serviceName: "service"
33+
- serviceName: "jsw"
3434
request:
3535
# language=GraphQL
3636
query: |

0 commit comments

Comments
 (0)