File tree Expand file tree Collapse file tree 1 file changed +13
-31
lines changed Expand file tree Collapse file tree 1 file changed +13
-31
lines changed Original file line number Diff line number Diff line change 2
2
< head >
3
3
< script src ="../graphql.js "> </ script >
4
4
< script >
5
- var graph = graphql ( "https://example.com/ graphql" , {
5
+ var graph = graphql ( "https://graphql-pokemon.now.sh " , {
6
6
alwaysAutodeclare : true ,
7
7
asJSON : true ,
8
8
debug : true
9
9
} )
10
10
11
- var postId = 123
11
+ var name = "pikachu"
12
12
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
18
16
}
19
- } ` )
17
+ ` )
20
18
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
27
22
}
28
- }` )
29
-
30
- // This won't send a request.
31
- fetchPost . merge ( 'buildPage' , { id : postId } ) . then ( function ( post ) {
32
- console . log ( post )
33
- } )
23
+ ` )
34
24
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' )
46
28
</ script >
47
29
</ head >
48
30
< body >
You can’t perform that action at this time.
0 commit comments