-
Notifications
You must be signed in to change notification settings - Fork 101
/
index.js
33 lines (29 loc) · 1.13 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const {createClient} = require('..');
const client = createClient({
endpoint: 'https://graphqurl-demo.hasura.app/v1/graphql',
});
console.dir("Executing query 'query { menu_items { name } }': ");
client.query(
{
query: 'query { menu_items { name } }',
},
).then(response => console.log(JSON.stringify(response)))
.catch(error => console.error(error));
console.dir("Executing mutation: 'mutation {delete_menu_items(where: {name: {_eq: \"pasta\"}}){ returning { name }}}'");
client.query(
{
query: 'mutation ($name: String) {delete_menu_items(where: {name: {_eq: $name}}) {returning {name}}}',
variables: {name: 'pizza'},
},
).then(() => console.log('Successfully executed delete mutation.'))
.catch(error => console.error(error));
console.dir("Executing insert mutation: 'mutation {insert_menu_items(objects: {name: \"pasta\",}) {returning {name}}}'");
client.query(
{
query: 'mutation ($name: String) {insert_menu_items(objects: {name: $name}) {returning {name}}}',
variables: {
name: 'pasta',
},
},
).then(() => console.log('Successfully executed insert mutation'))
.catch(error => console.error(error));