File tree Expand file tree Collapse file tree 4 files changed +63
-0
lines changed
Expand file tree Collapse file tree 4 files changed +63
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import maintenanceMode from './global/maintenanceMode';
1313import carousel from './common/carousel' ;
1414import loadingProgressBar from './global/loading-progress-bar' ;
1515import svgInjector from './global/svg-injector' ;
16+ import basicGraphQLQuery from './global/basicGraphQLQuery' ;
1617
1718export default class Global extends PageManager {
1819 onReady ( ) {
@@ -28,5 +29,7 @@ export default class Global extends PageManager {
2829 maintenanceMode ( this . context . maintenanceMode ) ;
2930 loadingProgressBar ( ) ;
3031 svgInjector ( ) ;
32+ /* Inject token into function */
33+ basicGraphQLQuery ( this . context . storefrontAPIToken ) ;
3134 }
3235}
Original file line number Diff line number Diff line change 1+ import ApolloClient from 'apollo-boost' ;
2+ import gql from 'graphql-tag' ;
3+
4+
5+ /**
6+ * Run a basic request against the GraphQL Storefront API using Apollo Client and log the results to the browser console
7+ */
8+ export default function ( token ) {
9+ const client = new ApolloClient ( {
10+ headers : { Authorization : `Bearer ${ token } ` } ,
11+ } ) ;
12+
13+ client . query ( {
14+ query : gql `
15+ query MyFirstQuery {
16+ site {
17+ settings {
18+ storeName
19+ }
20+ products {
21+ edges {
22+ node {
23+ name
24+ sku
25+ prices {
26+ retailPrice {
27+ value
28+ currencyCode
29+ }
30+ price {
31+ value
32+ currencyCode
33+ }
34+ }
35+ defaultImage {
36+ url(width:1280)
37+ }
38+ options {
39+ entityId
40+ displayName
41+ values {
42+ entityId
43+ label
44+ }
45+ }
46+ }
47+ }
48+ }
49+ }
50+ }
51+ ` ,
52+ } )
53+ . then ( data => console . log ( data ) )
54+ . catch ( error => console . error ( error ) ) ;
55+ }
Original file line number Diff line number Diff line change 88 "dependencies" : {
99 "@babel/polyfill" : " ^7.4.4" ,
1010 "@bigcommerce/stencil-utils" : " ^4.2.0" ,
11+ "apollo-boost" : " ^0.4.4" ,
1112 "creditcards" : " ^3.0.1" ,
1213 "easyzoom" : " ^2.5.2" ,
1314 "foundation-sites" : " ^5.5.3" ,
15+ "graphql" : " ^14.4.2" ,
16+ "graphql-tag" : " ^2.10.1" ,
1417 "jquery" : " ^3.4.1" ,
1518 "jstree" : " vakata/jstree" ,
1619 "lazysizes" : " 5.1.0" ,
Original file line number Diff line number Diff line change 3434 {{~inject 'secureBaseUrl' settings.secure_base_url}}
3535 {{~inject 'cartId' cart_id}}
3636 {{~inject 'template' template}}
37+ {{!-- Inject Storefront API Token into JS context so we can use it in our JavaScript --}}
38+ {{~inject 'storefrontAPIToken' settings.storefront_api.token}}
3739 </ head >
3840 < body >
3941 < svg data-src ="{{cdn 'img/icon-sprite.svg'}} " class ="icons-svg-sprite "> </ svg >
You can’t perform that action at this time.
0 commit comments