Apollo官网的教程如下:
npm install @apollo/client graphql
在载入文件里如下操作
import {
ApolloClient,
InMemoryCache,
ApolloProvider,
useQuery,
gql
} from "@apollo/client";
const client = new ApolloClient({
uri: 'https://48p1r2roz4.sse.codesandbox.io',
cache: new InMemoryCache()
});
client
.query({
query: gql`
query GetRates {
rates(currency: "USD") {
currency
}
}
`
})
.then(result => console.log(result));
会出现如下问题: 解决方案:
const client = new ApolloClient({
uri: 'https://first-sculpin-26.hasura.app/v1/graphql',
cache: new InMemoryCache(),
headers: {
"content-type": "application/json",
"x-hasura-admin-secret":"your x-hasura-admin-secret" ,
}
})
|