【问题标题】:Is gremlin local variable in match?gremlin 局部变量是否匹配?
【发布时间】:2018-01-24 06:16:59
【问题描述】:

我正在使用 tinkerpop3 图形数据库 (aws neptune) 制作 graphql api 服务器
例如,我想在下面实现graphql

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

然后我像下面这样进行 gremlin 查询

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')

但此查询无法正常工作。因为评论的id 与帖子的id 重叠。

我想在匹配语句中本地使用.as('id')。 有什么解决办法吗?

【问题讨论】:

标签: graphql gremlin local-variables tinkerpop3 amazon-neptune


【解决方案1】:

谢谢@jbmusso

我使用Map Scope解决了问题。
修复了 gremlin 查询是打击,它是 GraphQL 的完美形式。不需要后期处理。

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

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多