neo4j-graphql / neo4j-graphql-java

Neo4j Labs Project: Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server.groovy from docs doesn't work

Kubera2017 opened this issue · comments

commented

I'm trying to run:
`// Simplistic GraphQL Server using SparkJava
@Grapes([
@grab('com.sparkjava:spark-core:2.7.2'),
@grab('org.neo4j.driver:neo4j-java-driver:4.1.1'),
@grab('org.neo4j:neo4j-graphql-java:1.1.0'),
@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.*

schema = """
type Person {
name: ID!
born: Int
actedIn: [Movie] @relation(name:"ACTED_IN")
}
type Movie {
title: ID!
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("neo4j://localhost:7687",AuthTokens.basic("neo4j","123"),
Config.builder().withoutEncryption().build())

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);`

In console I have:
$ groovy server.groovy WARNING: An illegal reflective access operation has occurred WARNING: Illegal reflective access by org.codehaus.groovy.reflection.CachedClass (file:/usr/share/groovy/lib/groovy-2.4.17.jar) to method java.lang.Object.finalize() WARNING: Please consider reporting this to the maintainers of org.codehaus.groovy.reflection.CachedClass WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations WARNING: All illegal access operations will be denied in a future release SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder". SLF4J: Defaulting to no-operation (NOP) logger implementation SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details. Oct 04, 2020 8:23:11 PM org.neo4j.driver.internal.logging.JULogger info INFO: Routing driver instance 1777381620 created for server address localhost:7687

But curl returns 500 error:
`curl -XPOST http://localhost:4567/graphql -d'{"query":"{person {name}}"}'

500 Internal Server Error

`

I updated driver version to 4.1.1 because "neo4j://" is needed. OpenJDK 11

Do you get any error message with the 500 error or anything logged on the server?

I think if you use the neo4j:// schema you must not use the config option with encryption disabled. Please try that

commented

Logger was disabled. The error was incorrect query.