currently I'm facing a problem while querying my Nexus GraphQL backend. In my frontend I use Apollo-boost (Apollo Client) to run queries. I tried to get data from backend in a simple example but it's not working and I can't find the problem. Am I doing something wrong? Here is my Code:
TypeError: Object(...) is not a function
353 |
354 | function useBaseQuery(query, options, lazy) {
355 | if (lazy === void 0) { lazy = false; }
> 356 | var context = useContext(getApolloContext());
357 | var _a = useReducer(function (x) { return x + 1; }, 0), tick = _a[0], forceUpdate = _a[1];
358 | var updatedOptions = options ? __assign(__assign({}, options), { query: query }) : { query: query };
359 | var queryDataRef = useRef();
400 | }
401 |
402 | function useQuery(query, options) {
> 403 | return useBaseQuery(query, options, false);
404 | }
405 |
406 | function useLazyQuery(query, options) {
import React from 'react';
import ReactDOM from 'react-dom';
import registerServiceWorker from './registerServiceWorker';
import { BrowserRouter } from 'react-router-dom';
import ApolloClient, { gql } from 'apollo-boost';
import { ApolloProvider, Query } from 'react-apollo';
const client = new ApolloClient({
uri: 'http://localhost:4000/graphql',
});
const GET_ALL_GENRES = gql`
{
getAllGenres {
genre_id
title
}
}
`;
const ExchangeRates = () => (
<Query query={GET_ALL_GENRES}>
{({ loading, error, data }) => {
if (loading) return <p>Loading...</p>;
if (error) return <p>Error :(</p>;
console.log(data);
return <p>Succeed</p>;
}}
</Query>
);
ReactDOM.render(
<ApolloProvider client={client}>
<BrowserRouter>
<ExchangeRates />
</BrowserRouter>
</ApolloProvider>,
document.getElementById('root'),
);
registerServiceWorker();
Or is this a known issue? react-apollo gql, TypeError: Object(...) is not a function
I tried all of the solutions but it still not working. Also the examples are from the official documentation. The only way which succeed was this approach:
client
.query({
query: gql`
{
getAllGenres {
genre_id
title
}
}
`,
})
.then((result) => console.log(result));