-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
453 additions
and
1 deletion.
There are no files selected for viewing
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
9 changes: 9 additions & 0 deletions
9
...urces/io/github/ermadmi78/kobby/generator/kotlin/unknown_parent_with_default.graphqls.txt
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,9 @@ | ||
directive @default on FIELD_DEFINITION | ||
|
||
type Query { | ||
temp: Film | ||
} | ||
|
||
type Film implements DummyParentWithDefault { | ||
title: String! @default | ||
} |
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
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
70 changes: 70 additions & 0 deletions
70
kobby-model/src/test/kotlin/io/github/ermadmi78/kobby/model/DirectiveValidationTest.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,70 @@ | ||
package io.github.ermadmi78.kobby.model | ||
|
||
import org.junit.jupiter.api.Test | ||
import java.io.InputStreamReader | ||
import kotlin.test.assertEquals | ||
|
||
/** | ||
* Created on 30.08.2021 | ||
* | ||
* @author Dmitry Ermakov ([email protected]) | ||
*/ | ||
class DirectiveValidationTest { | ||
@Test | ||
fun testDirectiveRestrictions() { | ||
"default_arguments_and_return_type".shouldViolate( | ||
"Restriction violated [Query.first]: The [@primaryKey] directive can only be applied to a field with no arguments.", | ||
"Restriction violated [Query.first]: The [@primaryKey] directive can only be applied to a field that returns a scalar or enum type.", | ||
"Restriction violated [Query.second]: The [@required] directive can only be applied to a field with no arguments.", | ||
"Restriction violated [Query.second]: The [@required] directive can only be applied to a field that returns a scalar or enum type.", | ||
"Restriction violated [Query.third]: The [@default] directive can only be applied to a field with no arguments.", | ||
"Restriction violated [Query.third]: The [@default] directive can only be applied to a field that returns a scalar or enum type." | ||
) | ||
|
||
"default_cannot_override".shouldViolate( | ||
"Restriction violated [Country.id]: The [@primaryKey] directive cannot be applied to overridden fields. Please, apply [@primaryKey] directive to [IBase.id] field.", | ||
"Restriction violated [Country.name]: The [@required] directive cannot be applied to overridden fields. Please, apply [@required] directive to [IBase.name] field.", | ||
"Restriction violated [Country.description]: The [@default] directive cannot be applied to overridden fields. Please, apply [@default] directive to [IBase.description] field." | ||
) | ||
|
||
"default_can_override".shouldViolate() | ||
"default_override".shouldViolate() | ||
"default_enum".shouldViolate() | ||
|
||
"default_mix".shouldViolate( | ||
"Restriction violated [Query.first]: The field is marked with several directives at once - @default, @required, @primaryKey, the behavior of the Kobby Plugin is undefined!", | ||
"Restriction violated [Query.second]: The field is marked with several directives at once - @default, @required, @primaryKey, the behavior of the Kobby Plugin is undefined!", | ||
"Restriction violated [Query.third]: The field is marked with several directives at once - @default, @required, @primaryKey, the behavior of the Kobby Plugin is undefined!", | ||
"Restriction violated [Query.fourth]: The field is marked with several directives at once - @default, @required, @primaryKey, the behavior of the Kobby Plugin is undefined!" | ||
) | ||
|
||
"selection_no_optional".shouldViolate( | ||
"Restriction violated [Query.first]: The @selection directive can only be applied to a field that contains optional arguments - nullable arguments or arguments with default value.", | ||
"Restriction violated [Query.second]: The @selection directive can only be applied to a field that contains optional arguments - nullable arguments or arguments with default value.", | ||
"Restriction violated [Query.fourth]: The @selection directive can only be applied to a field that contains optional arguments - nullable arguments or arguments with default value." | ||
) | ||
|
||
"selection_optional".shouldViolate() | ||
|
||
"selection_cannot_override".shouldViolate( | ||
"Restriction violated [Country.base]: The [@selection] directive cannot be applied to overridden fields. Please, apply [@selection] directive to [Base.base] field." | ||
) | ||
"selection_can_override".shouldViolate() | ||
"selection_override".shouldViolate() | ||
|
||
"resolve_cannot_override".shouldViolate( | ||
"Restriction violated [Country.base]: The [@resolve] directive cannot be applied to overridden fields. Please, apply [@resolve] directive to [Base.base] field." | ||
) | ||
"resolve_can_override".shouldViolate() | ||
"resolve_override".shouldViolate() | ||
} | ||
|
||
private fun String.shouldViolate(vararg warnings: String) { | ||
val schema = parseSchema( | ||
emptyMap(), | ||
InputStreamReader(this@DirectiveValidationTest.javaClass.getResourceAsStream("$this.graphqls.txt")!!) | ||
) | ||
|
||
assertEquals(listOf(*warnings), schema.validate()) | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
.../resources/io/github/ermadmi78/kobby/model/default_arguments_and_return_type.graphqls.txt
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,14 @@ | ||
directive @primaryKey on FIELD_DEFINITION | ||
directive @required on FIELD_DEFINITION | ||
directive @default on FIELD_DEFINITION | ||
|
||
type Query { | ||
first(arg: Int): [Country!]! @primaryKey | ||
second(arg: Boolean! = false): Country! @required | ||
third(arg: String!): Country @default | ||
} | ||
|
||
type Country { | ||
id: ID! | ||
name: String! | ||
} |
25 changes: 25 additions & 0 deletions
25
...odel/src/test/resources/io/github/ermadmi78/kobby/model/default_can_override.graphqls.txt
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 @@ | ||
directive @primaryKey on FIELD_DEFINITION | ||
directive @required on FIELD_DEFINITION | ||
directive @default on FIELD_DEFINITION | ||
|
||
type Query { | ||
countries: [Country!]! | ||
} | ||
|
||
interface IBase { | ||
id: ID! @primaryKey | ||
name: String! @required | ||
description: String @default | ||
} | ||
|
||
interface ICountry implements IBase { | ||
id: ID! | ||
name: String! | ||
description: String | ||
} | ||
|
||
type Country implements ICountry & IBase { | ||
id: ID! @primaryKey | ||
name: String! @required | ||
description: String @default | ||
} |
25 changes: 25 additions & 0 deletions
25
...l/src/test/resources/io/github/ermadmi78/kobby/model/default_cannot_override.graphqls.txt
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 @@ | ||
directive @primaryKey on FIELD_DEFINITION | ||
directive @required on FIELD_DEFINITION | ||
directive @default on FIELD_DEFINITION | ||
|
||
type Query { | ||
countries: [Country!]! | ||
} | ||
|
||
interface IBase { | ||
id: ID! | ||
name: String! | ||
description: String | ||
} | ||
|
||
interface ICountry implements IBase { | ||
id: ID! | ||
name: String! | ||
description: String | ||
} | ||
|
||
type Country implements ICountry & IBase { | ||
id: ID! @primaryKey | ||
name: String! @required | ||
description: String @default | ||
} |
Oops, something went wrong.