Search code examples
graphqlgremlinlocal-variablestinkerpop3amazon-neptune

Is gremlin local variable in match?


I am making graphql api server with tinkerpop3 graph database (aws neptune)
for example, I want implementation of graphql below

{
    post {
        id
        title,
        comments {
            id
        }
    }
}

and I make gremlin query like below

g.V().hasLabel('post').match(
    __.id().as('id'),
    __.values('title').as('title'),
    __.union(
        out('has_comment').match(
            __.id().as('id')
        ).select('id')
    ).fold().as('comments')
).select('id', 'title', 'comments')

but this query isn't working correctly. because id of comment is overlap with id of post.

I want use .as('id') locally in match statement. is there any solution?


Solution

  • thank you @jbmusso

    I solved problem using Map Scope.
    fixed gremlin query is blow, it is perfect form for GraphQL. not necessary post process.

    g.V().hasLabel('post').project('id', 'title', 'comments')
        .by(__.id())
        .by(__.values('title'))
        .by(__.out('has_comment').project('id')
            by(__.id()).fold()
        )
        .toList()