-
Notifications
You must be signed in to change notification settings - Fork 339
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Throw exception on multi-level interface
Resolves #419 According to the spec, an interface can not implement another interface. This is not caught by our schema generator but instead just returns the first level interface as the type in the schema. We are now throwing an exception to help translate this understanding of GraphQL through the Kotlin code
- Loading branch information
Showing
5 changed files
with
99 additions
and
1 deletion.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...enerator/src/main/kotlin/com/expediagroup/graphql/exceptions/InvalidInterfaceException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright 2019 Expedia, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.expediagroup.graphql.exceptions | ||
|
||
/** | ||
* Thrown when a interface implements another interface or abstract class that is not exluded from the schema. | ||
* | ||
* This is an invalid schema until the GraphQL spec is updated | ||
* https://github.com/ExpediaGroup/graphql-kotlin/issues/419 | ||
*/ | ||
class InvalidInterfaceException : GraphQLKotlinException("Interfaces can not have any superclasses") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...tor/src/test/kotlin/com/expediagroup/graphql/test/integration/InterfaceOfInterfaceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2019 Expedia, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.expediagroup.graphql.test.integration | ||
|
||
import com.expediagroup.graphql.TopLevelObject | ||
import com.expediagroup.graphql.exceptions.InvalidInterfaceException | ||
import com.expediagroup.graphql.testSchemaConfig | ||
import com.expediagroup.graphql.toSchema | ||
import org.junit.jupiter.api.Test | ||
import kotlin.test.assertFailsWith | ||
|
||
class InterfaceOfInterfaceTest { | ||
|
||
@Test | ||
fun `interface of interface`() { | ||
val queries = listOf(TopLevelObject(InterfaceOfInterfaceQuery())) | ||
|
||
assertFailsWith(InvalidInterfaceException::class) { | ||
toSchema(queries = queries, config = testSchemaConfig) | ||
} | ||
} | ||
|
||
interface FirstLevel { | ||
val id: String | ||
} | ||
|
||
interface SecondLevel : FirstLevel { | ||
val name: String | ||
} | ||
|
||
class MyClass(override val id: String, override val name: String) : SecondLevel | ||
|
||
class InterfaceOfInterfaceQuery { | ||
fun getClass() = MyClass(id = "1", name = "fooBar") | ||
} | ||
} |