Please i need your help graphql queries and mutations won’t work. So i’ve been following the tutorials provided by shopify devs to create my first shopify app . And no matter what tutorial i follow i always get this error “[Network error]: ServerParseError: Unexpected token I in JSON at position” .
Here’s my code:(i’m using react and node)
index.js:
import { useCallback, useMemo, useState } from "react";
import { Button, Card, DataTable, EmptyState, Frame, Heading, Page, Stack, TextField, Toast } from "@shopify/polaris";
import { ResourcePicker } from "@shopify/app-bridge-react";
import { useMutation } from "react-apollo";
import { ProductUpdateMutation } from "../graphql/productUpdate";
const Index = () => {
const [appendToTitle, setAppendToTitle] = useState('');
const [appendToDescription, setAppendToDescription] = useState('');
const [products, setProducts] = useState([]);
const [showToast, setShowToast] = useState(false);
const [pickerOpen, setPickerOpen] = useState(false);
const [updateProduct] = useMutation(ProductUpdateMutation);
const productPickerHandler = useCallback(() => setPickerOpen(true), []);
const productTableDisplayData = useMemo(() => products.map((product) => [
product.id,
product.title,
`${product.title}${appendToTitle}`,
product.descriptionHtml,
`${product.descriptionHtml}${appendToDescription}`
]), [products, appendToTitle, appendToDescription]);
const submitHandler = useCallback(() => {
let count = 0;
const runMutation = (product) => {
updateProduct({
variables: {
input: {
descriptionHtml: `${product.descriptionHtml}${appendToDescription}`,
title: `${product.title}${appendToTitle}`,
id: product.id
}
}
}).then((data) => {
console.log('update Product', count, data);
count++;
if (products[count]) runMutation(products[count])
else {
console.log('Updates Complete');
setShowToast(true);
}
})
}
runMutation(products[count]);
},[products, appendToTitle, appendToDescription]);
const toastMarkup = showToast ?
and here is my **graphql** file:
```javascript
import { gql } from "apollo-boost";
export const ProductUpdateMutation = gql `
mutation updateProduct($input: ProductInput!){
productUpdate(input: $input){
product{
id
description
title
}
userErrors{
message
field
}
}
}
`;