-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Kotlin Update to 1.3.11 - set version to 1.0.0-M01 - added more docs - added example server - updated readme
- Loading branch information
Showing
8 changed files
with
287 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
.DS_Store | ||
dependency-reduced-pom.xml | ||
docs | ||
*.iml | ||
target | ||
.idea | ||
.idea |
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,41 @@ | ||
// Simplistic GraphQL Server using SparkJava | ||
@Grapes([ | ||
@Grab('com.sparkjava:spark-core:2.7.2'), | ||
@Grab('org.neo4j.driver:neo4j-java-driver:1.7.2'), | ||
@Grab('org.neo4j:neo4j-graphql-java:1.0.0-M01'), | ||
@Grab('com.google.code.gson:gson:2.8.5') | ||
]) | ||
|
||
import spark.* | ||
import static spark.Spark.* | ||
import com.google.gson.Gson | ||
import org.neo4j.graphql.* | ||
import org.neo4j.driver.v1.* | ||
|
||
schema = """ | ||
type Person { | ||
name: String | ||
born: Int | ||
actedIn: [Movie] @relation(name:"ACTED_IN") | ||
} | ||
type Movie { | ||
title: String | ||
released: Int | ||
tagline: String | ||
} | ||
type Query { | ||
person : [Person] | ||
} | ||
""" | ||
|
||
gson = new Gson() | ||
render = (ResponseTransformer)gson.&toJson | ||
def query(value) { gson.fromJson(value,Map.class)["query"] } | ||
|
||
graphql = new Translator(SchemaBuilder.buildSchema(schema)) | ||
def translate(query) { graphql.translate(query) } | ||
|
||
driver = GraphDatabase.driver("bolt://localhost",AuthTokens.basic("neo4j","password")) | ||
def run(cypher) { driver.session().withCloseable { it.run(cypher.query, Values.value(cypher.params)).list{ it.asMap() }}} | ||
|
||
post("/graphql","application/json", { req, res -> run(translate(query(req.body())).first()) }, render); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.