Skip to content

Commit

Permalink
Remove the need of a viewer to wrap the query
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasbento committed Oct 23, 2016
1 parent ce4aebf commit 64b1aaa
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 30 deletions.
6 changes: 1 addition & 5 deletions data/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ type PokemonEvolutionRequirement {

# Query any Pokémon by number or name
type Query {
viewer: Viewer
}

# Query any Pokémon by number or name
type Viewer {
query: Query
pokemons(first: Int!): [Pokemon]
pokemon(id: String, name: String): Pokemon
}
17 changes: 3 additions & 14 deletions data/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,17 @@
"description": "Query any Pokémon by number or name",
"fields": [
{
"name": "viewer",
"name": "query",
"description": null,
"args": [],
"type": {
"kind": "OBJECT",
"name": "Viewer",
"name": "Query",
"ofType": null
},
"isDeprecated": false,
"deprecationReason": null
}
],
"inputFields": null,
"interfaces": [],
"enumValues": null,
"possibleTypes": null
},
{
"kind": "OBJECT",
"name": "Viewer",
"description": "Query any Pokémon by number or name",
"fields": [
},
{
"name": "pokemons",
"description": null,
Expand Down
10 changes: 5 additions & 5 deletions src/AppRoute.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import PokemonDetail from './components/Pokemon/PokemonDetail';

const appHistory = useRouterHistory(createHashHistory)({ queryKey: false });

const ViewerQueries = {
viewer: () => Relay.QL`
const RootQuery = {
query: () => Relay.QL`
query {
viewer
query
}
`,
};
Expand All @@ -32,12 +32,12 @@ const AppRoute = () => (
<Route
path="/"
component={PokemonList}
queries={ViewerQueries}
queries={RootQuery}
/>
<Route
path=":id"
component={PokemonDetail}
queries={ViewerQueries}
queries={RootQuery}
/>
</Router>
</App>
Expand Down
6 changes: 3 additions & 3 deletions src/components/Pokemon/PokemonDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class PokemonDetail extends Component {
types,
weaknesses,
evolutions,
} = this.props.viewer.pokemon;
} = this.props.query.pokemon;

return (
<Card>
Expand Down Expand Up @@ -96,8 +96,8 @@ export default Relay.createContainer(withRouter(PokemonDetail), {
id: null,
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
query: () => Relay.QL`
fragment on Query {
pokemon(id: $id) {
number
name
Expand Down
6 changes: 3 additions & 3 deletions src/components/Pokemon/PokemonList.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class PokemonList extends Component {
componentWillUnmount = () => window.removeEventListener('scroll', this.handleScroll)

render() {
const { pokemons } = this.props.viewer;
const { pokemons } = this.props.query;

return (
<div>
Expand All @@ -61,8 +61,8 @@ export default Relay.createContainer(PokemonList, {
count: 20,
},
fragments: {
viewer: () => Relay.QL`
fragment on Viewer {
query: () => Relay.QL`
fragment on Query {
pokemons(first: $count) {
id
${PokemonRow.getFragment('pokemon')}
Expand Down

0 comments on commit 64b1aaa

Please sign in to comment.