Implementation of graphQL with gremlin

715 views
Skip to first unread message

אלה וייס

unread,
Jun 21, 2018, 8:03:09 AM6/21/18
to Gremlin-users

Hi


 :A GraphQL query is a string that is sent to a server to be interpreted and fulfilled, which then returns JSON back to the client.


I want implementation of graphql using gremlin below


Robert Dale

unread,
Jun 21, 2018, 8:33:12 AM6/21/18
to gremli...@googlegroups.com
Without a sample graph, I'm using the modern graph...

graph = TinkerFactory.createModern()
g = graph.traversal()

g.V().has('name','marko').
    project('user','created','friends').
        by(valueMap(true,'name','age')).
        by(out('created').has('lang','java').valueMap('name')).
        by(out('knows').limit(5).valueMap(true,'name').fold())

[user:[id:1,label:person,name:[marko],age:[29]],
 created:[name:[lop]],
 friends:[[id:2,label:person,name:[vadas]],
        [id:4,label:person,name:[josh]]]]

This graph doesn't have anything like 'profilePicture' with 'size' so I used 'created' with 'lang' instead.

Robert Dale


--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/e7c4f91b-8dea-44c6-a772-40fc6aa368d1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

אלה וייס

unread,
Jun 21, 2018, 8:45:44 AM6/21/18
to Gremlin-users

thanks,

but how can I get the totalCount of friends ? 
בתאריך יום חמישי, 21 ביוני 2018 בשעה 15:33:12 UTC+3, מאת Robert Dale:

Robert Dale

unread,
Jun 21, 2018, 9:15:29 AM6/21/18
to gremli...@googlegroups.com
g.V().has('name','marko').
project('person','created','friendConn').
by(valueMap(true,'name','age')).
by(out('created').has('lang','java').valueMap('name')).
by(out('knows').fold().
    project('totalCount','friends').
        by(count(local)).
        by(unfold().limit(5).valueMap(true,'name').fold()))

==>[person:[id:1,label:person,name:[marko],age:[29]],
    created:[name:[lop]],
    friendConn:[totalCount:2,
        friends:[[id:2,label:person,name:[vadas]],
               [id:4,label:person,name:[josh]]]]]


Robert Dale


אלה וייס

unread,
Jun 21, 2018, 10:30:18 AM6/21/18
to Gremlin-users

Thanks 
בתאריך יום חמישי, 21 ביוני 2018 בשעה 16:15:29 UTC+3, מאת Robert Dale:
Reply all
Reply to author
Forward
0 new messages