-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Alex Alexeev
committed
Aug 1, 2017
1 parent
d19d998
commit f1654c8
Showing
13 changed files
with
558 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,29 @@ | ||
import { QueryRenderer, graphql } from 'react-relay'; | ||
import { | ||
Environment, | ||
Network, | ||
RecordSource, | ||
Store, | ||
RecordSourceInspector, | ||
} from 'relay-runtime'; | ||
import environment from './Environment'; | ||
import LocationsList from './LocationsList'; | ||
|
||
async function fetchQuery(operation, variables) { | ||
const response = await fetch( | ||
'https://mh67geuwe5.execute-api.eu-west-1.amazonaws.com/dev/', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query: operation.text, | ||
variables, | ||
}), | ||
}, | ||
); | ||
|
||
return response.json(); | ||
} | ||
|
||
const source = new RecordSource(); | ||
const inspector = new RecordSourceInspector(source); | ||
const modernEnvironment = new Environment({ | ||
network: Network.create(fetchQuery), | ||
store: new Store(source), | ||
}); | ||
import Login from './Login'; | ||
|
||
export default () => | ||
<QueryRenderer | ||
environment={modernEnvironment} | ||
query={graphql` | ||
query AppQuery { | ||
...LocationsList | ||
} | ||
`} | ||
variables={{}} | ||
render={({ error, props }) => { | ||
if (props) { | ||
return ( | ||
<div> | ||
<LocationsList data={props} /> | ||
</div> | ||
); | ||
} else { | ||
return <div>Loading</div>; | ||
} | ||
}} | ||
/>; | ||
<div> | ||
<QueryRenderer | ||
environment={environment} | ||
query={graphql` | ||
query AppQuery { | ||
...LocationsList | ||
} | ||
`} | ||
variables={{}} | ||
render={({ error, props }) => { | ||
if (props) { | ||
return ( | ||
<div> | ||
<LocationsList data={props} /> | ||
</div> | ||
); | ||
} else { | ||
return <div>Loading</div>; | ||
} | ||
}} | ||
/> | ||
<Login /> | ||
</div>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,5 +21,5 @@ export default createFragmentContainer( | |
name | ||
slug | ||
} | ||
`, | ||
` | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { | ||
Environment, | ||
Network, | ||
RecordSource, | ||
Store, | ||
RecordSourceInspector | ||
} from 'relay-runtime'; | ||
|
||
import Location from './Location'; | ||
import Login from './Login'; | ||
|
||
async function fetchQuery(operation, variables) { | ||
const token = localStorage ? localStorage.getItem('token') : ''; | ||
|
||
const response = await fetch( | ||
'https://mh67geuwe5.execute-api.eu-west-1.amazonaws.com/dev/', | ||
{ | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Authorization: token | ||
}, | ||
body: JSON.stringify({ | ||
query: operation.text, | ||
variables | ||
}) | ||
} | ||
); | ||
|
||
return response.json(); | ||
} | ||
|
||
const source = new RecordSource(); | ||
|
||
export const inspector = new RecordSourceInspector(source); | ||
|
||
const environment = new Environment({ | ||
network: Network.create(fetchQuery), | ||
store: new Store(source) | ||
}); | ||
|
||
export default environment; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,5 +20,5 @@ export default createFragmentContainer( | |
...City | ||
} | ||
} | ||
`, | ||
` | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { Component } from 'react'; | ||
import environment from './Environment'; | ||
import { QueryRenderer, graphql } from 'react-relay'; | ||
import UserInfo from './UserInfo'; | ||
import LoginButton from './LoginButton'; | ||
|
||
export default () => | ||
<QueryRenderer | ||
environment={environment} | ||
query={graphql` | ||
query LoginQuery { | ||
currentUser { | ||
...UserInfo_user | ||
} | ||
} | ||
`} | ||
render={({ error, props }) => { | ||
if (error) { | ||
return ( | ||
<div> | ||
{error.message} | ||
</div> | ||
); | ||
} else if (props && props.currentUser) { | ||
return <UserInfo user={props.currentUser} />; | ||
} | ||
return <LoginButton />; | ||
}} | ||
/>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import React, { Component } from 'react'; | ||
import LoginMutation from './mutations/LoginMutation'; | ||
import environment from './Environment'; | ||
|
||
class LoginButton extends Component { | ||
handleLogin = () => { | ||
LoginMutation.commit(environment, '[email protected]', 'bflmpsvz'); | ||
}; | ||
render() { | ||
return <button onClick={this.handleLogin}>Login</button>; | ||
} | ||
} | ||
|
||
export default LoginButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import React, { Component } from 'react'; | ||
import { createFragmentContainer, graphql } from 'react-relay'; | ||
|
||
class UserInfo extends Component { | ||
render() { | ||
return ( | ||
<div> | ||
Logged in as: {this.props.user.lastName} | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default createFragmentContainer( | ||
UserInfo, | ||
graphql` | ||
fragment UserInfo_user on Identity { | ||
id | ||
lastName | ||
} | ||
` | ||
); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.