I have a Chrome extension made initially with create-react-app. This extension needs to get data via a GraphQL query, and the resulting data needs to be used in my content script.
Using the 'react-boost' package in my src/index.js
file works perfectly as follows.
import ApolloClient, { gql } from 'apollo-boost';
const client = new ApolloClient({
uri: 'https://mygraphqlurl/graphql',
headers: {
'access-key': '123',
},
});
client
.query({
query: gql`
{
merchant {
id
retailer {
name
}
}
}
`,
})
.then(result => console.log(result));
However, if I try to use this code in my content.js
script in my public
folder, I get an error on the import line:
Uncaught SyntaxError: Unexpected identifier '
import ApolloClient, { gql } from 'apollo-boost';
How can I use this functionality in my content script?