代码示例:
import React from 'react'; import { ApolloProvider, ApolloClient, InMemoryCache, useQuery, gql } from '@apollo/client';
const client = new ApolloClient({ uri: 'https://example.com/graphql', cache: new InMemoryCache() });
const QUERY = gql query { exampleData { field1 field2 } }
;
function App() { const { loading, error, data } = useQuery(QUERY);
if (loading) return
Loading...
; if (error) returnError :(
;return (
{data.exampleData.field1}
{data.exampleData.field2}
ReactDOM.render(