| 1 |
import React from 'react'; |
| 2 |
import gql from 'graphql-tag'; |
| 3 |
import { Query } from 'react-apollo'; |
| 4 |
import { |
| 5 |
Card, |
| 6 |
ResourceList, |
| 7 |
Stack, |
| 8 |
TextStyle, |
| 9 |
Thumbnail, |
| 10 |
} from '@shopify/polaris'; |
| 11 |
import store from 'store-js'; |
| 12 |
import { Redirect } from '@shopify/app-bridge/actions'; |
| 13 |
import { Context } from '@shopify/app-bridge-react'; |
| 14 |
|
| 15 |
// GraphQL query to retrieve products by IDs. |
| 16 |
// The price field belongs to the variants object because |
| 17 |
// variations of a product can have different prices. |
| 18 |
const GET_PRODUCTS_BY_ID = gql` |
| 19 |
query getProducts($ids: [ID!]!) { |
| 20 |
nodes(ids: $ids) { |
| 21 |
... on Product { |
| 22 |
title |
| 23 |
handle |
| 24 |
descriptionHtml |
| 25 |
id |
| 26 |
images(first: 1) { |
| 27 |
edges { |
| 28 |
node { |
| 29 |
originalSrc |
| 30 |
altText |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
variants(first: 1) { |
| 35 |
edges { |
| 36 |
node { |
| 37 |
price |
| 38 |
id |
| 39 |
} |
| 40 |
} |
| 41 |
} |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
`; |
| 46 |
|
| 47 |
---------------------------------------------------- |
| 48 |
|
| 49 |
[ |
| 50 |
["keyword", "import"], |
| 51 |
" React ", |
| 52 |
["keyword", "from"], |
| 53 |
["string", "'react'"], |
| 54 |
["punctuation", ";"], |
| 55 |
|
| 56 |
["keyword", "import"], |
| 57 |
" gql ", |
| 58 |
["keyword", "from"], |
| 59 |
["string", "'graphql-tag'"], |
| 60 |
["punctuation", ";"], |
| 61 |
|
| 62 |
["keyword", "import"], |
| 63 |
["punctuation", "{"], |
| 64 |
" Query ", |
| 65 |
["punctuation", "}"], |
| 66 |
["keyword", "from"], |
| 67 |
["string", "'react-apollo'"], |
| 68 |
["punctuation", ";"], |
| 69 |
|
| 70 |
["keyword", "import"], |
| 71 |
["punctuation", "{"], |
| 72 |
|
| 73 |
"\r\n Card", |
| 74 |
["punctuation", ","], |
| 75 |
|
| 76 |
"\r\n ResourceList", |
| 77 |
["punctuation", ","], |
| 78 |
|
| 79 |
"\r\n Stack", |
| 80 |
["punctuation", ","], |
| 81 |
|
| 82 |
"\r\n TextStyle", |
| 83 |
["punctuation", ","], |
| 84 |
|
| 85 |
"\r\n Thumbnail", |
| 86 |
["punctuation", ","], |
| 87 |
|
| 88 |
["punctuation", "}"], |
| 89 |
["keyword", "from"], |
| 90 |
["string", "'@shopify/polaris'"], |
| 91 |
["punctuation", ";"], |
| 92 |
|
| 93 |
["keyword", "import"], |
| 94 |
" store ", |
| 95 |
["keyword", "from"], |
| 96 |
["string", "'store-js'"], |
| 97 |
["punctuation", ";"], |
| 98 |
|
| 99 |
["keyword", "import"], |
| 100 |
["punctuation", "{"], |
| 101 |
" Redirect ", |
| 102 |
["punctuation", "}"], |
| 103 |
["keyword", "from"], |
| 104 |
["string", "'@shopify/app-bridge/actions'"], |
| 105 |
["punctuation", ";"], |
| 106 |
|
| 107 |
["keyword", "import"], |
| 108 |
["punctuation", "{"], |
| 109 |
" Context ", |
| 110 |
["punctuation", "}"], |
| 111 |
["keyword", "from"], |
| 112 |
["string", "'@shopify/app-bridge-react'"], |
| 113 |
["punctuation", ";"], |
| 114 |
|
| 115 |
["comment", "// GraphQL query to retrieve products by IDs."], |
| 116 |
|
| 117 |
["comment", "// The price field belongs to the variants object because"], |
| 118 |
|
| 119 |
["comment", "// variations of a product can have different prices."], |
| 120 |
|
| 121 |
["keyword", "const"], |
| 122 |
["constant", "GET_PRODUCTS_BY_ID"], |
| 123 |
["operator", "="], |
| 124 |
" gql", |
| 125 |
["template-string", [ |
| 126 |
["template-punctuation", "`"], |
| 127 |
["graphql", [ |
| 128 |
["keyword", "query"], |
| 129 |
["definition-query", "getProducts"], |
| 130 |
["punctuation", "("], |
| 131 |
["variable", "$ids"], |
| 132 |
["punctuation", ":"], |
| 133 |
["punctuation", "["], |
| 134 |
["scalar", "ID"], |
| 135 |
["operator", "!"], |
| 136 |
["punctuation", "]"], |
| 137 |
["operator", "!"], |
| 138 |
["punctuation", ")"], |
| 139 |
["punctuation", "{"], |
| 140 |
|
| 141 |
["property-query", "nodes"], |
| 142 |
["punctuation", "("], |
| 143 |
["attr-name", "ids"], |
| 144 |
["punctuation", ":"], |
| 145 |
["variable", "$ids"], |
| 146 |
["punctuation", ")"], |
| 147 |
["punctuation", "{"], |
| 148 |
|
| 149 |
["operator", "..."], |
| 150 |
["keyword", "on"], |
| 151 |
["class-name", "Product"], |
| 152 |
["punctuation", "{"], |
| 153 |
|
| 154 |
["property", "title"], |
| 155 |
|
| 156 |
["property", "handle"], |
| 157 |
|
| 158 |
["property", "descriptionHtml"], |
| 159 |
|
| 160 |
["property", "id"], |
| 161 |
|
| 162 |
["property-query", "images"], |
| 163 |
["punctuation", "("], |
| 164 |
["attr-name", "first"], |
| 165 |
["punctuation", ":"], |
| 166 |
["number", "1"], |
| 167 |
["punctuation", ")"], |
| 168 |
["punctuation", "{"], |
| 169 |
|
| 170 |
["object", "edges"], |
| 171 |
["punctuation", "{"], |
| 172 |
|
| 173 |
["object", "node"], |
| 174 |
["punctuation", "{"], |
| 175 |
|
| 176 |
["property", "originalSrc"], |
| 177 |
|
| 178 |
["property", "altText"], |
| 179 |
|
| 180 |
["punctuation", "}"], |
| 181 |
|
| 182 |
["punctuation", "}"], |
| 183 |
|
| 184 |
["punctuation", "}"], |
| 185 |
|
| 186 |
["property-query", "variants"], |
| 187 |
["punctuation", "("], |
| 188 |
["attr-name", "first"], |
| 189 |
["punctuation", ":"], |
| 190 |
["number", "1"], |
| 191 |
["punctuation", ")"], |
| 192 |
["punctuation", "{"], |
| 193 |
|
| 194 |
["object", "edges"], |
| 195 |
["punctuation", "{"], |
| 196 |
|
| 197 |
["object", "node"], |
| 198 |
["punctuation", "{"], |
| 199 |
|
| 200 |
["property", "price"], |
| 201 |
|
| 202 |
["property", "id"], |
| 203 |
|
| 204 |
["punctuation", "}"], |
| 205 |
|
| 206 |
["punctuation", "}"], |
| 207 |
|
| 208 |
["punctuation", "}"], |
| 209 |
|
| 210 |
["punctuation", "}"], |
| 211 |
|
| 212 |
["punctuation", "}"], |
| 213 |
|
| 214 |
["punctuation", "}"] |
| 215 |
]], |
| 216 |
["template-punctuation", "`"] |
| 217 |
]], |
| 218 |
["punctuation", ";"] |
| 219 |
] |
| 220 |
|
| 221 |
---------------------------------------------------- |
| 222 |
|
| 223 |
Checks for tagged template literals containing GraphQL code. |