Skip to content

update library structure #255

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ before_install:

script:
- ./mvnw install
- ./mvnw -f example/pom.xml verify

deploy:
provider: script
Expand Down
13 changes: 1 addition & 12 deletions .travis/update-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,11 @@ setup_git() {
}

update_version() {

exampleProperty="graphql-kotlin.version"

# Push the new tag with `-SNAPSHOT` as the current version
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set -DnewVersion="${TRAVIS_TAG}-SNAPSHOT"

# Increment the patch version
mvn --settings .travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set -DnextSnapshot=true

# Pull the value from the pom
NEW_VERSION=$(mvn --settings .travis/settings.xml help:evaluate -Dexpression=project.version -q -DforceStdout)

# Update the example version
cd example/
mvn --settings ../.travis/settings.xml org.codehaus.mojo:versions-maven-plugin:2.7:set-property -Dproperty=${exampleProperty} -DnewVersion=${NEW_VERSION}
cd ../
}

commit_files() {
Expand All @@ -32,7 +21,7 @@ commit_files() {
git checkout -b ${NEW_VERSION}

# Stage the modified files
git add pom.xml example/pom.xml
git add pom.xml */pom.xml

# Create a new commit with a custom build message and Travis build number for reference
git commit -m "build: $NEW_VERSION (Travis Build $TRAVIS_BUILD_NUMBER)"
Expand Down
93 changes: 5 additions & 88 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,98 +6,15 @@
[![Javadocs](https://img.shields.io/maven-central/v/com.expedia/graphql-kotlin.svg?label=javadoc&colorB=brightgreen)](https://www.javadoc.io/doc/com.expedia/graphql-kotlin)
[![Awesome Kotlin Badge](https://kotlin.link/awesome-kotlin.svg)](https://github.com/KotlinBy/awesome-kotlin)

Most GraphQL libraries require developers to maintain two sources of truth for their GraphQL API: the schema and the corresponding code (data fetchers or resolvers, and types). Given the similarities between Kotlin and GraphQL, such as the ability to define nullable/non-nullable types, a schema can be generated from Kotlin code without any separate schema specification. `graphql-kotlin` builds upon `graphql-java` to allow code-only, or resolver-first, GraphQL services to be built.
GraphQL Kotlin consists of number of libraries that aim to simplify GraphQL integration for Kotlin applications.

For information on GraphQL, please visit [the GraphQL website](https://graphql.org/).
## Modules

For information on `graphql-java`, please visit [GraphQL Java](https://www.graphql-java.com/documentation/latest/).

## Installation

Using a JVM dependency manager, simply link `graphql-kotlin` to your project.

With Maven:

```xml
<dependency>
<groupId>com.expedia</groupId>
<artifactId>graphql-kotlin</artifactId>
<version>${latestVersion}</version>
</dependency>
```

With Gradle:

```groovy
compile(group: 'com.expedia', name: 'graphql-kotlin', version: "$latestVersion")
```

## Usage


```kotlin
// Your existing Kotlin code

data class Widget(val id: Int, val value: String)

class WidgetService {
fun widgetById(id: Int): Widget? {
// grabs widget from a data source, might return null
}

@Deprecated("Use widgetById")
fun widgetByValue(value: String): Widget? {
// grabs widget from a deprecated data source, might return null
}
}

class WidgetUpdater {
fun saveWidget(value: String): Widget {
// Create and save a new widget, returns non-null
}
}

// Generate the schema

val config = SchemaGeneratorConfig(supportedPackages = listOf("org.example"))
val queries = listOf(TopLevelObject(WidgetService()))
val mutations = listOf(TopLevelObject(WidgetUpdater()))

toSchema(config, queries, mutations)
```

will generate

```graphql
schema {
query: Query
mutation: Mutation
}

type Query {
widgetById(id: Int!): Widget

widgetByValue(vale: String!): Widget @deprecated(reason: "Use widgetById")
}

type Mutation {
saveWidget(value: String!): Widget!
}

type Widget {
id: Int!
value: String!
}
```
* [graphql-kotlin-schema-generator](graphql-kotlin-schema-generator/README.md) - code only GraphQL schema generation for Kotlin
* [graphql-kotlin-spring-example](graphql-kotlin-spring-example/README.md) - example SpringBoot app that uses GraphQL Kotlin schema generator

## Documentation

There are more examples and documention in our [Uncyclo](https://github.com/ExpediaDotCom/graphql-kotlin/wiki) or you can view the [javadocs](https://www.javadoc.io/doc/com.expedia/graphql-kotlin) for all published versions.
Examples and documentation is available on our [Uncyclo](https://github.com/ExpediaDotCom/graphql-kotlin/wiki) or you can view the [javadocs](https://www.javadoc.io/doc/com.expedia/graphql-kotlin) for all published versions.

If you have a question about something you can not find in our wiki or javadocs, feel free to [create an issue](https://github.com/ExpediaDotCom/graphql-kotlin/issues) and tag it with the question label.

## Example

One way to run a GraphQL server is with Spring Boot. A sample Spring Boot app that uses [Spring Webflux](https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html) together with `graphql-kotlin` and [graphql-playground](https://github.com/prisma/graphql-playground) is provided in the [example folder](https://github.com/ExpediaDotCom/graphql-kotlin/tree/master/example). All the examples used in this documentation should be available in the sample app.

In order to run it you can run [Application.kt](https://github.com/ExpediaDotCom/graphql-kotlin/blob/master/example/src/main/kotlin/com.expedia.graphql.sample/Application.kt) directly from your IDE. Alternatively you can also use the Spring Boot maven plugin by running `mvn spring-boot:run` from the command line. Once the app has started you can explore the example schema by opening GraphiQL endpoint at [http://localhost:8080/playground](http://localhost:8080/playground).
139 changes: 0 additions & 139 deletions example/pom.xml

This file was deleted.

91 changes: 91 additions & 0 deletions graphql-kotlin-schema-generator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# GraphQL Kotlin Schema Generator

Most GraphQL libraries require developers to maintain two sources of truth for their GraphQL API: the schema and the corresponding code (data fetchers or resolvers, and types). Given the similarities between Kotlin and GraphQL, such as the ability to define nullable/non-nullable types, a schema can be generated from Kotlin code without any separate schema specification. `graphql-kotlin` builds upon `graphql-java` to allow code-only, or resolver-first, GraphQL services to be built.

For information on GraphQL, please visit [the GraphQL website](https://graphql.org/).

For information on `graphql-java`, please visit [GraphQL Java](https://www.graphql-java.com/documentation/latest/).

## Installation

Using a JVM dependency manager, simply link `graphql-kotlin-schema-generator` to your project.

With Maven:

```xml
<dependency>
<groupId>com.expedia</groupId>
<artifactId>graphql-kotlin-schema-generator</artifactId>
<version>${latestVersion}</version>
</dependency>
```

With Gradle:

```groovy
compile(group: 'com.expedia', name: 'graphql-kotlin-schema-generator', version: "$latestVersion")
```

## Usage


```kotlin
// Your existing Kotlin code

data class Widget(val id: Int, val value: String)

class WidgetService {
fun widgetById(id: Int): Widget? {
// grabs widget from a data source, might return null
}

@Deprecated("Use widgetById")
fun widgetByValue(value: String): Widget? {
// grabs widget from a deprecated data source, might return null
}
}

class WidgetUpdater {
fun saveWidget(value: String): Widget {
// Create and save a new widget, returns non-null
}
}

// Generate the schema

val config = SchemaGeneratorConfig(supportedPackages = listOf("org.example"))
val queries = listOf(TopLevelObject(WidgetService()))
val mutations = listOf(TopLevelObject(WidgetUpdater()))

toSchema(config, queries, mutations)
```

will generate

```graphql
schema {
query: Query
mutation: Mutation
}

type Query {
widgetById(id: Int!): Widget

widgetByValue(vale: String!): Widget @deprecated(reason: "Use widgetById")
}

type Mutation {
saveWidget(value: String!): Widget!
}

type Widget {
id: Int!
value: String!
}
```

## Documentation

There are more examples and documention in our [Uncyclo](https://github.com/ExpediaDotCom/graphql-kotlin/wiki) or you can view the [javadocs](https://www.javadoc.io/doc/com.expedia/graphql-kotlin) for all published versions.

If you have a question about something you can not find in our wiki or javadocs, feel free to [create an issue](https://github.com/ExpediaDotCom/graphql-kotlin/issues) and tag it with the question label.
Loading