neo4j-graphql / neo4j-graphql-java

Neo4j Labs Project: Pure JVM translation for GraphQL queries and mutations to Neo4j's Cypher
Apache License 2.0
105 stars 49 forks source link

The basic library example doesn't work #269

Open rullyalves opened 2 years ago

rullyalves commented 2 years ago

I tried this code example:

val schema = """ type Person { name: ID! age: Int }

Optional if you use generated queries

    type Query {
        person : [Person]
    }"""

val query = """ quero { person { age } } """

val schema = SchemaBuilder.buildSchema(idl) val ctx = QueryContext() val (cypher, params) = Translator(schema).translate(query, mapOf(), ctx)

// generated Cypher cypher == "MATCH (p:Person) WHERE p.name = $pName RETURN p {.age} as p"

but i get an error about GraphQLDefaultValueArgument, I would like to know if I am doing something wrong and if this library can be used solely to translate graphql queries into cypher queries.

Andy2003 commented 2 years ago

I cant see any problem with your example:

package demo

import org.neo4j.graphql.QueryContext
import org.neo4j.graphql.SchemaBuilder
import org.neo4j.graphql.Translator

fun main() {
    val idl = """
    type Person {
        name: ID!
        age: Int
    }
    # Optional if you use generated queries
    type Query {
        person : [Person]
    }
    """.trimIndent()

    val query = """ query { person { age } } """

    val schema = SchemaBuilder.buildSchema(idl)
    val ctx = QueryContext()
    val (cypher) = Translator(schema).translate(query, mapOf(), ctx).first()

    // prints: MATCH (person:Person) RETURN person { .age } AS person
    println(cypher)
}