Skip to content

Commit 0dc3750

Browse files
committed
example
1 parent 323415c commit 0dc3750

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

example/index.html

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,29 @@
22
<head>
33
<script src="../graphql.js"></script>
44
<script>
5-
var graph = graphql("https://example.com/graphql", {
5+
var graph = graphql("https://graphql-pokemon.now.sh", {
66
alwaysAutodeclare: true,
77
asJSON: true,
88
debug: true
99
})
1010

11-
var postId = 123
11+
var name = "pikachu"
1212

13-
var fetchPost = graph.query(`{
14-
post(id: $id) {
15-
id
16-
title
17-
text
13+
var pokemonImage = graph.query(`
14+
pokemon(name: $name) {
15+
image
1816
}
19-
}`)
17+
`)
2018

21-
var fetchComments = graph.query(`{
22-
comments(postId: $postId) {
23-
comment
24-
owner {
25-
name
26-
}
19+
var pokemonId = graph.query(`
20+
pokemon(name: $name) {
21+
id
2722
}
28-
}`)
29-
30-
// This won't send a request.
31-
fetchPost.merge('buildPage', { id: postId }).then(function (post) {
32-
console.log(post)
33-
})
23+
`)
3424

35-
// This also won't send a request.
36-
fetchComments.merge('buildPage', { postId: postId }).then(function (comments) {
37-
console.log(comments)
38-
})
39-
40-
// This will send a merged request:
41-
graph.commit('buildPage').then(function (response) {
42-
// All base fields will be in response return.
43-
console.log(response.post)
44-
console.log(response.comments)
45-
})
25+
pokemonId.merge('poke', {name: "Pikachu"})
26+
pokemonImage.merge('poke', {name: "Bulbasaur"})
27+
graph.commit('poke')
4628
</script>
4729
</head>
4830
<body>

0 commit comments

Comments
 (0)