Skip to content
This repository has been archived by the owner on Aug 16, 2020. It is now read-only.

Commit

Permalink
DBに入ったユーザ名を表示する
Browse files Browse the repository at this point in the history
  • Loading branch information
kadoyau committed Dec 4, 2019
1 parent e80ee46 commit 9bada04
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 19 deletions.
49 changes: 31 additions & 18 deletions front/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
import React from 'react';
import logo from './logo.svg';
import './App.css';
import {gql} from 'apollo-boost';
import {Query} from 'react-apollo';

const GET_USERS = gql`

This comment has been minimized.

Copy link
@kadoyau

kadoyau Dec 4, 2019

Author Owner

GraphQLのクエリ

query {
user {
name
}
}
`;

const App: React.FC = () => {
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
</div>
);
return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo"/>
<p>
Edit <code>src/App.tsx</code> and save to reload.
</p>
<Query query={GET_USERS}>

This comment has been minimized.

Copy link
@kadoyau

kadoyau Dec 4, 2019

Author Owner

クエリをサーバに投げて

{({loading, error, data}: any) => {
if (loading) return <div>Loading...</div>;
if (error) return <div>Error :(</div>;
return (
<p>
{data.user.name}

This comment has been minimized.

Copy link
@kadoyau

kadoyau Dec 4, 2019

Author Owner

ロードが完了したらここで表示する

</p>
)
}}
</Query>
</header>
</div>
);
}

export default App;
13 changes: 12 additions & 1 deletion front/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,19 @@ import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import * as serviceWorker from './serviceWorker';
import ApolloClient from 'apollo-boost';
import {ApolloProvider} from 'react-apollo';

ReactDOM.render(<App />, document.getElementById('root'));
// Pass your GraphQL endpoint to uri
const client = new ApolloClient({uri: '/graphql'});

const ApolloApp = (AppComponent: React.FC) => (
<ApolloProvider client={client}>
<AppComponent/>
</ApolloProvider>
);

ReactDOM.render(ApolloApp(App), document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
Expand Down

0 comments on commit 9bada04

Please sign in to comment.