Getting started with apollo client

$ npx create-react-app react-graphql
$ cd react-graphql
$ npm start


npm install apollo-boost react-apollo graphql --save

Copy and paste this in your app.js and you're good to go.


import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
import { ApolloProvider } from "react-apollo";
import ApolloClient from "apollo-boost";
import gql from "graphql-tag"

const client = new ApolloClient({
uri: "http://localhost:4000"
});

client
.query({
query: gql`
{
books {
title
author
}
}
`
})
.then(result => console.log(result));


class App extends Component {
render() {
return (
<div className="App">
<ApolloProvider client={client}>
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</ApolloProvider>

</div>
);
}
}

export default App;














Comments

Popular posts from this blog

The specified initialization vector (IV) does not match the block size for this algorithm