File tree 1 file changed +27
-0
lines changed
1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { QueryFetcher } from "gqless" ;
2
+
3
+ /*
4
+ Listener code:
5
+ const listener = m => {
6
+ if (m.data === "DATA_FETCHED") {
7
+ this.$forceUpdate();
8
+ window.removeEventListener("message", listener);
9
+ }
10
+ };
11
+ window.addEventListener("message", listener);
12
+ */
13
+
14
+ const vueFetch : QueryFetcher = async ( endpoint : string ) => {
15
+ return async function ( query : any , variables : any ) {
16
+ const response = await fetch ( endpoint , {
17
+ method : 'POST' ,
18
+ headers : { 'Content-Type' : 'application/json' } ,
19
+ body : JSON . stringify ( { query, variables } ) ,
20
+ mode : 'cors'
21
+ } ) ;
22
+ if ( ! response . ok ) throw new Error ( `Network error, received status code ${ response . status } ` ) ;
23
+ const json = await response . json ( ) ;
24
+ window . postMessage ( "DATA_FETCHED" , window . location . href ) ;
25
+ return json ;
26
+ }
27
+ }
You can’t perform that action at this time.
0 commit comments