-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added alias support for queries and mutations (#26)
* Fix escaped string array (#6) * Update Spek version * Fix print wrong escaped character, Fix #4 * Rewrite the GraphQLPrintSpek for preetty print test * Bump hotfix version * Update build status link * Migrate kotlin v1.1.1 (#7) * bump to kotlin v1.1.1 * Add type alias for more readable code * Change the package name to me.lazmaid.kraph * Fix build failed dur to hamkrest error * Update spek version * Update ENV for release * Update README * Refactor arguments (#9) * WIP * Split the print logic into sealed class * Update UTs * Add exception message * Refactor * Add Test Coverage (#11) * Add Test Coverage * Update spek version * Fix test result path * Add codecov YAML * Add onlyIf * Update config * Fix travis command * Add coverage badge * Fix wrong download badge * Bump version to 0.5.1 * Support boolean type in Argument (#15) * Add support for boolean type * Add Tests * Fix typo in README (#16) missing "h" in the example call to `println(query.toGrapQueryString())` * Added basic fragment support (#17) * improve readme * Allow using field with a block in place of field object * Update readme to include new changes * Cheap implementation of fragment that doesn't use actual GraphQL Fragments * Add fragment docs to readme * Fix tests * Change function to 'defineFragment' * Update Kotlin and library dependcies (#18) * Update .gitignore * Update dependecies * Add secondary constructor for DataEntry.NonDecimalNUmber * Add Test for DataEntry classes * Fix failed UTs * Added partial request printing functions (#19) * improve readme * Allow using field with a block in place of field object * Update readme to include new changes * Cheap implementation of fragment that doesn't use actual GraphQL Fragments * Add fragment docs to readme * Fix tests * Add separate methods to print the different parts of the request separately * Use spaces instead of newlines for request format * Rewrite printing operations to optionally escape quotes * update readme a bit * Change function to 'defineFragment' * Use an enum to choose print format and write tests to cover all formats * Add note about variables * Update version (#20) * add support for variables (#23) * add support for variables * add support for variables * Added alias support for queries and mutations * Checked errors from CI Build and added an example for usage * Resolve error with arguments in RequestSpek.kt * Resolve error in BuilderSpek.kt * Replace /n on """ in the BuilderSpek.kt * Change equalTo to requestString * Change other test mutation with alias * Added documentation about alias for field and fieldObject * Resolved conflicts * Check CI error
- Loading branch information
1 parent
c1e689d
commit 2b39841
Showing
9 changed files
with
108 additions
and
27 deletions.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,23 @@ class BuilderSpek : Spek({ | |
assertThat(query.toGraphQueryString(), equalTo("query getAllNotes {\n notes {\n id\n content\n author {\n name\n email\n }\n avatarUrl (size: 100)\n }\n}")) | ||
} | ||
} | ||
given("sample query with aliases") { | ||
val query = Kraph { | ||
query("getAllNotes") { | ||
fieldObject("notes", alias = "aliasedNotes") { | ||
field("id", alias = "aliasedId") | ||
} | ||
} | ||
} | ||
it("should be able to print the request for network call") { | ||
assertThat( | ||
query.toRequestString(), | ||
equalTo( | ||
"{\"query\": \"query getAllNotes { aliasedNotes: notes { aliasedId: id } }\", \"variables\": null, \"operationName\": \"getAllNotes\"}" | ||
) | ||
) | ||
} | ||
} | ||
given("sample query with no field in selection set") { | ||
it("should throw NoFieldsInSelectionSetException") { | ||
assertThat({ | ||
|
@@ -95,7 +112,7 @@ class BuilderSpek : Spek({ | |
given("sample mutation") { | ||
val query = Kraph { | ||
mutation { | ||
func("registerUser", mapOf("email" to "[email protected]", "password" to "abcd1234", "age" to 30)) { | ||
func("registerUser", args = mapOf("email" to "[email protected]", "password" to "abcd1234", "age" to 30)) { | ||
field("id") | ||
field("token") | ||
} | ||
|
@@ -132,6 +149,22 @@ class BuilderSpek : Spek({ | |
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[1].name, equalTo("token")) | ||
} | ||
} | ||
given("sample mutation with alias") { | ||
val query = Kraph { | ||
mutation { | ||
func("registerUser", alias = "aliasedRegisterUser", args = mapOf("email" to "[email protected]")) { | ||
field("id") | ||
} | ||
} | ||
} | ||
it("should be able to print the request for network call") { | ||
assertThat(query.toRequestString(), | ||
equalTo( | ||
"{\"query\": \"mutation { aliasedRegisterUser: registerUser (input: { email: \\\"[email protected]\\\" }) { id } }\", \"variables\": null, \"operationName\": null}" | ||
) | ||
) | ||
} | ||
} | ||
given("sample mutation with no field in selection set") { | ||
it("should throw NoFieldsInSelectionSetException") { | ||
assertThat({ | ||
|
@@ -205,17 +238,17 @@ class BuilderSpek : Spek({ | |
given("sample query with cursor cursorConnection without arguments") { | ||
it("should throw IllegalArgumentException with message \"There must be at least 1 argument for Cursor Connection\"") { | ||
assertThat({ | ||
Kraph { | ||
query { | ||
cursorConnection("users") { | ||
edges { | ||
node { | ||
field("title") | ||
Kraph { | ||
query { | ||
cursorConnection("users") { | ||
edges { | ||
node { | ||
field("title") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}, throws<IllegalArgumentException>(cursorEmptyArgumentsMessageMatcher)) | ||
} | ||
} | ||
|
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 |
---|---|---|
|
@@ -132,7 +132,7 @@ class GraphQLPrintSpek : Spek({ | |
given("name RegisterUser with email and password and type of registrarion as argument and payload contains id and token") { | ||
val argNode = InputArgument(mapOf("email" to "[email protected]", "password" to "abcd1234", "type" to Type.EMAIL)) | ||
val setNode = SelectionSet(listOf(Field("id"), Field("token"))) | ||
val node = Mutation("RegisterUser", argNode, setNode) | ||
val node = Mutation("RegisterUser", arguments = argNode, selectionSet = setNode) | ||
it("should print correctly in NORMAL mode") { | ||
assertThat(node.print(PrintFormat.NORMAL, 0), equalTo("RegisterUser (input: { email: \"[email protected]\", password: \"abcd1234\", type: EMAIL }) { id token }")) | ||
} | ||
|
@@ -148,7 +148,7 @@ class GraphQLPrintSpek : Spek({ | |
val tests = listOf( | ||
Triple(Field("id"), "name id", Expectation("id", "id", "id")), | ||
Triple( | ||
Field("avatarSize", Argument(mapOf("size" to 20))), | ||
Field("avatarSize", arguments = Argument(mapOf("size" to 20))), | ||
"name avatarSize and size argument with value as 20", | ||
Expectation( | ||
"avatarSize (size: 20)", | ||
|
@@ -166,7 +166,7 @@ class GraphQLPrintSpek : Spek({ | |
) | ||
), | ||
Triple( | ||
Field("user", Argument(mapOf("id" to 10)), SelectionSet(listOf(Field("name"), Field("email")))), | ||
Field("user", arguments = Argument(mapOf("id" to 10)), selectionSet = SelectionSet(listOf(Field("name"), Field("email")))), | ||
"name user and id argument with value as 10 and containing name and email", | ||
Expectation( | ||
"user (id: 10) { name email }", | ||
|
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