Skip to content

Commit 7165366

Browse files
authored
fix(federation): Federation errors should not return invalid locations (#1990)
### 📝 Description Per GraphQL spec error location should only be specified IF it can point to a valid location (i.e. starting with positive column/row). We were incorrectly returning `-1,-1` location. ### 🔗 Related Issues
1 parent 17159d9 commit 7165366

File tree

3 files changed

+6
-7
lines changed

3 files changed

+6
-7
lines changed

generator/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/generator/federation/exception/FederatedRequestFailure.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ class FederatedRequestFailure(private val errorMessage: String, private val erro
2929

3030
override fun getErrorType(): ErrorClassification = ErrorType.DataFetchingException
3131

32-
override fun getLocations(): List<SourceLocation> = listOf(SourceLocation(-1, -1))
32+
override fun getLocations(): List<SourceLocation>? = null
3333

3434
override fun getExtensions(): Map<String, Any>? =
3535
if (error != null) {

generator/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/generator/federation/exception/InvalidFederatedRequest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -29,5 +29,5 @@ class InvalidFederatedRequest(private val errorMessage: String) : GraphQLError {
2929

3030
override fun getErrorType(): ErrorClassification = ErrorType.ValidationError
3131

32-
override fun getLocations(): List<SourceLocation> = listOf(SourceLocation(-1, -1))
32+
override fun getLocations(): List<SourceLocation>? = null
3333
}

generator/graphql-kotlin-federation/src/test/kotlin/com/expediagroup/graphql/generator/federation/exception/FederatedRequestFailureTest.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 Expedia, Inc
2+
* Copyright 2024 Expedia, Inc
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
1717
package com.expediagroup.graphql.generator.federation.exception
1818

1919
import graphql.ErrorType
20-
import graphql.language.SourceLocation
2120
import org.junit.jupiter.api.Test
2221
import kotlin.test.assertEquals
2322
import kotlin.test.assertNull
@@ -38,7 +37,7 @@ internal class FederatedRequestFailureTest {
3837

3938
@Test
4039
fun getLocations() {
41-
assertEquals(expected = listOf(SourceLocation(-1, -1)), actual = simpleFailure.locations)
40+
assertNull(simpleFailure.locations)
4241
}
4342

4443
@Test

0 commit comments

Comments
 (0)