Last active
April 29, 2017 15:39
-
-
Save reicheltp/6cf51654ba3e2cae27286bcc330ef246 to your computer and use it in GitHub Desktop.
dgraph-client-sample.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import DgraphClient from 'dgraph-client'; | |
| // create a new client | |
| let client = new DgraphClient('localhost:8080'); | |
| // set objects | |
| let me = {name: 'Paul', size: 1.85, time: Date.now()}; | |
| await client.set(me); | |
| // query objects | |
| let me2 = await client.query(`query { me(id:${me._uid_}) { name, size } }`); | |
| // reponse is {me: {name: 'Paul', size: 1.85} } | |
| // set also works with geojson | |
| let me3 = {name: 'Paul', location: {type: 'Point', coordinates: [13.25, 52.14]}}; | |
| await client.set(me3); | |
| // and with nested objects | |
| let me4 = {name: 'Paul', friends: [{name: 'Max'}, {_uid_: "0xd8450668580bf30f"}]}; | |
| await client.set(me4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment