Skip to content

Commit

Permalink
Migrate kotlin v1.1.1 (#7)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Verachad Wongsawangtham authored Mar 26, 2017
1 parent ff19228 commit 5a1f319
Show file tree
Hide file tree
Showing 21 changed files with 73 additions and 73 deletions.
8 changes: 3 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
language: java
jdk:
- oraclejdk8

cache:
directories:
- $HOME/.gradle

- "$HOME/.gradle"
env:
global:
- secure: E2jm3qJrcyavBwWkBQxqKrLjprl4QRT3vGtX87HyEzCYAveh+bdiY+gvu0q+RoFhAklzSEJnND5vBDbHD4gzV9bx9UdafrPzwKFEWt3ZcVGI70JEYHfcID0jzQ6pI7LismrTOpVkHyUZudBnG3yNh6PxID8890I5IMPHInvvVMUDhJ+jpLtjnn5HnRLVIEOX1A368pQoqiAKvSPuIHmDdFofYbAlgprWEtkrpdLd/1Yp95yrE5EjC6nwjhvG2LHiKTr5FgAWD9/owmemioBnexSxEgZe76cRm38WDQVWpEppp7FHJ7eo0LhtEBXYUXJX2UE6W5A0rRBfRRoOCa8eABmY2kxsm5TajlA7yrxqeQebuvcQzVmSjPJ3t7JLkgcYMI88HbpvKjhA5fFVi8TeThd85wXp58eQkIU/7EoLPaqALUHw8WCAaBOmcQ37MLeSk6oX8SQUS0owo58guh1SN95BpTrMuzvvN4V9LPGNMfnVBxuKjnfOxxPkBWLEsuvgGwdC9pYj3dDYVDD7igrGy5qTwTJ8qTtqud3uUY0JVzpPpN6m3IKI0qxEOYTDS3WrJh14P8flFZXYU/Vot1xkmZPMlAAqYxdRWLnNAjwS+c8VePKqZmIp3FVxFyrs9yJehFWynB0ZYi3ZUtc0UKkoIKLocMi1huHgAmRrJbteN9Y=
- secure: VLdggtNem5VHnUyGPfyrA05wnpmOqAlMbfd6fyNTh0/YpYzwnJ/2kqEcnCdcJn/GsDyubGcEvl7+PXzI4LmCS1fedQgj/9h+/nAFYEx6UInrczXEAKf3d53DH+rSCgTzvilqFBvLl6fJhkCv+/YuvDkOhWvBWN6QqZjBLCNc60Qw4kXsExU8TfG09wnu37TJuo78zmmY51Y85YDtsgnvw0C7mLk7n4R7yBiPEFi2ZAYehVdaN2eyUdl6uQsNm3rTdXMLRo0rQDsUOe7hFJYJz8F1ASMQmsY5xDGRfUpIBG78pV4IpMCTzoxpH3IaaK7Misxj3H5lgDzXEvtPf5t8SpKYfTBz1Pmc2ogVifV9YayRWl2K6bHabundAJQcYzhrBXZMPebpu5Pdi1GompOXdyhLx053x7+3/qhNK+81Tw71vNNt8+vRDNE9bIV00M1TE1YfHFz/GzBgUuPmigAl+CIY14w+PGJABFG7UHVDkjABMkOJHhFtLLwkkwx73CoPr8PzaXR9WzduPAwjiOpu0P69e5S4C5ZM3XxfBma8hW5K5RFvnw1FYSkE9+FEjhgdUX9bpfiHIhRS/3scTzscPhwuy804nmJqJbADjNtYVklVk6QaondMlEBu530uC57OHwRaLWLSDbPCWQwy2PsoBxtHewcld2x6IBGrPFj+qz0=

deploy:
- provider: script
skip_cleanup: true
script: ./gradlew build bintrayUpload -PdryRun=false
script: "./gradlew build bintrayUpload -PdryRun=false"
on:
branch: master
tags: true
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ Adding Kraph to `build.gradle`
}

dependencies {
compile "com.taskworld.kraph:kraph:x.y.z"
compile "me.lazmaid.kraph:kraph:x.y.z"
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
buildscript {
ext {
kotlin_version = '1.0.4'
kotlin_version = '1.1.1'
}
repositories {
mavenCentral()
Expand Down
12 changes: 5 additions & 7 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
buildscript {
ext {
publish_version = '0.4.1'
publish_version = '0.5.0'

bintray_plugin_version = '0.3.4'

spek_version = '1.1.0-beta4'
spek_version = '1.1.0'
hamkrest_version = '1.2.2.0'
junit_version = '4.12'
junit_platform_version = '1.0.0-M3'
Expand All @@ -17,7 +17,6 @@ buildscript {
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.junit.platform:junit-platform-gradle-plugin:$junit_platform_version"
// classpath "org.junit.platform:junit-platform-runner:$junit_platform_version"
classpath "com.novoda:bintray-release:$bintray_plugin_version"
}
}
Expand Down Expand Up @@ -48,15 +47,15 @@ sourceSets {
}

publish {
userOrg = 'tw'
groupId = 'com.taskworld.kraph'
userOrg = 'verachadw'
groupId = 'me.lazmaid.kraph'
artifactId = 'kraph'
bintrayUser = "$System.env.BINTRAY_USER"
bintrayKey = "$System.env.BINTRAY_API_KEY"
publishVersion = "$publish_version"
licences = ['MIT']
desc = 'GraphQL query builder written in Kotlin'
website = 'https://github.com/taskworld/kraph'
website = 'https://github.com/VerachadW/kraph'
}

dependencies {
Expand All @@ -71,5 +70,4 @@ dependencies {
exclude group: 'org.junit.platform'
exclude group: 'org.jetbrains.kotlin'
}
// testCompile "org.junit.platform:junit-platform-runner:$junit_platform_version"
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package com.taskworld.kraph
package me.lazmaid.kraph

import com.taskworld.kraph.lang.*
import com.taskworld.kraph.lang.relay.*
import me.lazmaid.kraph.lang.*
import me.lazmaid.kraph.lang.relay.*

/**
* Created by VerachadW on 9/19/2016 AD.
*/

typealias FieldBlock = Kraph.FieldBuilder.() -> Unit
typealias CursorBlock = Kraph.CursorSelectionBuilder.() -> Unit
typealias NodeBlock = Kraph.NodeBuilder.() -> Unit

class Kraph(f: Kraph.() -> Unit) {

internal lateinit var document: Document
Expand All @@ -15,17 +19,17 @@ class Kraph(f: Kraph.() -> Unit) {
f.invoke(this)
}

fun query(name: String? = null, builder: FieldBuilder.() -> Unit) {
fun query(name: String? = null, builder: FieldBlock) {
val set = createSelectionSet("query", builder)
document = Document(Operation(OperationType.QUERY, selectionSet = set, name = name))
}

fun mutation(name: String? = null, builder: FieldBuilder.() -> Unit) {
fun mutation(name: String? = null, builder: FieldBlock) {
val set = createSelectionSet("mutation", builder)
document = Document(Operation(OperationType.MUTATION, selectionSet = set, name = name))
}

private fun createSelectionSet(name: String, f: FieldBuilder.() -> Unit): SelectionSet {
private fun createSelectionSet(name: String, f: FieldBlock): SelectionSet {
val builder = FieldBuilder().apply(f)
val set = SelectionSet(builder.fields)
if (set.fields.isEmpty()) {
Expand All @@ -37,10 +41,10 @@ class Kraph(f: Kraph.() -> Unit) {
fun toGraphQueryString() = document.operation.print(true, 0)
fun toRequestString() = document.print(false, 0)

inner open class FieldBuilder() {
inner open class FieldBuilder {
internal val fields = arrayListOf<Field>()

fun fieldObject(name: String, args: Map<String, Any>? = null, builder: (FieldBuilder.() -> Unit)) {
fun fieldObject(name: String, args: Map<String, Any>? = null, builder: FieldBlock) {
addField(name, args, builder)
}

Expand All @@ -50,7 +54,7 @@ class Kraph(f: Kraph.() -> Unit) {

fun cursorConnection(name: String, first: Int = -1, last: Int = -1,
before: String? = null, after: String? = null,
builder: (CursorSelectionBuilder.() -> Unit)) {
builder: CursorBlock) {
val argsMap = linkedMapOf<String, Any>()
if (first != -1) argsMap.put("first", first)
if (last != -1) argsMap.put("last", last)
Expand All @@ -67,11 +71,11 @@ class Kraph(f: Kraph.() -> Unit) {
fields += CursorConnection(name, Argument(argsMap), SelectionSet(selection.fields))
}

fun func(name: String, args: Map<String, Any>, builder: FieldBuilder.() -> Unit) {
fun func(name: String, args: Map<String, Any>, builder: FieldBlock) {
fields += Mutation(name, InputArgument(args), createSelectionSet(name, builder))
}

protected fun addField(name: String, args: Map<String, Any>? = null, builder: (FieldBuilder.() -> Unit)? = null) {
protected fun addField(name: String, args: Map<String, Any>? = null, builder: FieldBlock? = null) {
val argNode = args?.let(::Argument)
val selectionSet = builder?.let {
createSelectionSet(name, builder)
Expand All @@ -80,9 +84,9 @@ class Kraph(f: Kraph.() -> Unit) {
}
}

inner class CursorSelectionBuilder() : FieldBuilder() {
inner class CursorSelectionBuilder : FieldBuilder() {

fun edges(builder: NodeBuilder.() -> Unit) {
fun edges(builder: NodeBlock) {
val node = NodeBuilder()
builder.invoke(node)
fields += Edges(node.selectionSet, node.fields)
Expand All @@ -97,7 +101,7 @@ class Kraph(f: Kraph.() -> Unit) {
}
}

inner class NodeBuilder(): FieldBuilder() {
inner class NodeBuilder: FieldBuilder() {
internal lateinit var selectionSet: SelectionSet
fun node(builder: FieldBuilder.() -> Unit) {
selectionSet = createSelectionSet("node", builder)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph
package me.lazmaid.kraph

/**
* Created by VerachadW on 10/4/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 9/19/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.taskworld.kraph.lang
package me.lazmaid.kraph.lang

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.taskworld.kraph.lang.relay
package me.lazmaid.kraph.lang.relay

import com.taskworld.kraph.lang.Argument
import com.taskworld.kraph.lang.Field
import com.taskworld.kraph.lang.SelectionSet
import me.lazmaid.kraph.lang.Argument
import me.lazmaid.kraph.lang.Field
import me.lazmaid.kraph.lang.SelectionSet


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.taskworld.kraph.lang.relay
package me.lazmaid.kraph.lang.relay

import com.taskworld.kraph.lang.Argument
import me.lazmaid.kraph.lang.Argument

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.taskworld.kraph.lang.relay
package me.lazmaid.kraph.lang.relay

import com.taskworld.kraph.lang.Field
import com.taskworld.kraph.lang.SelectionSet
import me.lazmaid.kraph.lang.Field
import me.lazmaid.kraph.lang.SelectionSet


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.taskworld.kraph.lang.relay
package me.lazmaid.kraph.lang.relay

import com.taskworld.kraph.lang.Field
import com.taskworld.kraph.lang.SelectionSet
import me.lazmaid.kraph.lang.Field
import me.lazmaid.kraph.lang.SelectionSet

/**
* Created by VerachadW on 10/2/2016 AD.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.taskworld.kraph.test
package me.lazmaid.kraph.test

import com.natpryce.hamkrest.*
import com.natpryce.hamkrest.assertion.assertThat
import com.taskworld.kraph.Kraph
import com.taskworld.kraph.NoFieldsInSelectionSetException
import com.taskworld.kraph.lang.OperationType
import com.taskworld.kraph.lang.relay.CursorConnection
import com.taskworld.kraph.lang.relay.PageInfo
import me.lazmaid.kraph.Kraph
import me.lazmaid.kraph.NoFieldsInSelectionSetException
import me.lazmaid.kraph.lang.OperationType
import me.lazmaid.kraph.lang.relay.CursorConnection
import me.lazmaid.kraph.lang.relay.PageInfo
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
Expand All @@ -32,13 +32,13 @@ class BuilderSpek : Spek({
assertThat(query.document.operation.type, isA(equalTo(OperationType.QUERY)))
}
it("should have only one field inside query") {
assertThat(query.document.operation.selectionSet.fields, hasSize(equalTo(1)))
assertThat(query.document.operation.selectionSet.fields.size, equalTo(1))
}
it("should have field named notes inside query") {
assertThat(query.document.operation.selectionSet.fields[0].name, equalTo("notes"))
}
it("should have four fields inside note object") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields, hasSize(equalTo(4)))
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields.size, equalTo(4))
}
it("should have field named id inside notes object") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[0].name, equalTo("id"))
Expand All @@ -56,7 +56,7 @@ class BuilderSpek : Spek({
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[3].arguments!!.args["size"] as Int, equalTo(100))
}
it("should have two fields inside author object") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[2].selectionSet!!.fields, hasSize(equalTo(2)))
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[2].selectionSet!!.fields.size, equalTo(2))
}
it("should have field named name inside author object") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[2].selectionSet!!.fields[0].name, equalTo("name"))
Expand Down Expand Up @@ -105,13 +105,13 @@ class BuilderSpek : Spek({
assertThat(query.document.operation.type, isA(equalTo(OperationType.MUTATION)))
}
it("should have only 1 mutation") {
assertThat(query.document.operation.selectionSet.fields, hasSize(equalTo(1)))
assertThat(query.document.operation.selectionSet.fields.size, equalTo(1))
}
it("should have mutation named registerUser") {
assertThat(query.document.operation.selectionSet.fields[0].name, equalTo("registerUser"))
}
it("should have 3 arguments in registerUser mutation") {
assertThat(query.document.operation.selectionSet.fields[0].arguments!!.args.entries, hasSize(equalTo(3)))
assertThat(query.document.operation.selectionSet.fields[0].arguments!!.args.entries.size, equalTo(3))
}
it("should have argument in registerUser mutation with named email and value as [email protected]") {
assertThat(query.document.operation.selectionSet.fields[0].arguments!!.args["email"] as String, equalTo("[email protected]"))
Expand All @@ -123,7 +123,7 @@ class BuilderSpek : Spek({
assertThat(query.document.operation.selectionSet.fields[0].arguments!!.args["age"] as Int, equalTo(30))
}
it("should contains 2 field in registerUser payload") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields, hasSize(equalTo(2)))
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields.size, equalTo(2))
}
it("should have id field in registerUser payload") {
assertThat(query.document.operation.selectionSet.fields[0].selectionSet!!.fields[0].name, equalTo("id"))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.taskworld.kraph.test
package me.lazmaid.kraph.test

import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.taskworld.kraph.lang.*
import com.taskworld.kraph.lang.relay.InputArgument
import com.taskworld.kraph.lang.relay.Mutation
import me.lazmaid.kraph.lang.relay.InputArgument
import me.lazmaid.kraph.lang.relay.Mutation
import me.lazmaid.kraph.lang.*
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.taskworld.kraph.test
package me.lazmaid.kraph.test

import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import com.taskworld.kraph.lang.Argument
import com.taskworld.kraph.lang.Field
import com.taskworld.kraph.lang.SelectionSet
import com.taskworld.kraph.lang.relay.CursorConnection
import com.taskworld.kraph.lang.relay.Edges
import com.taskworld.kraph.lang.relay.InputArgument
import com.taskworld.kraph.lang.relay.PageInfo
import me.lazmaid.kraph.lang.Argument
import me.lazmaid.kraph.lang.Field
import me.lazmaid.kraph.lang.SelectionSet
import me.lazmaid.kraph.lang.relay.CursorConnection
import me.lazmaid.kraph.lang.relay.Edges
import me.lazmaid.kraph.lang.relay.InputArgument
import me.lazmaid.kraph.lang.relay.PageInfo
import org.jetbrains.spek.api.Spek
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/kotlin/KraphExample.kt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import com.taskworld.kraph.Kraph
import me.lazmaid.kraph.Kraph

fun main(args: Array<String>) {

Expand Down
2 changes: 1 addition & 1 deletion sample/src/main/kotlin/StarWarExample.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import com.github.kittinunf.fuel.httpPost
import com.taskworld.kraph.Kraph
import me.lazmaid.kraph.Kraph

fun main(args: Array<String>) {
val url = "http://graphql-swapi.parseapp.com/?"
Expand Down

0 comments on commit 5a1f319

Please sign in to comment.