Last active
May 25, 2017 16:14
-
-
Save RomanHotsiy/f317d952647612ab68e5dbd900d4183c to your computer and use it in GitHub Desktop.
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
import React from 'react'; | |
import gql from 'graphql-tag'; | |
import { gqlLodash } from './gqlLodash'; | |
// data here contains already transformed data | |
function MyComponent({data: {loading, peopleToFilms}}) { | |
if (loading) return (<div> Loading... </div>); | |
let people = Object.keys(peopleToFilms); | |
return ( | |
<dl> | |
{people.map(name => ( | |
<div key={name}> | |
<dt>{name}</dt> | |
<dd> | |
{peopleToFilms[name].map(film => ( | |
<div> {film} </div> | |
))} | |
</dd> | |
</div> | |
))} | |
</dl> | |
); | |
} | |
const query = gql` | |
query { | |
peopleToFilms: allPeople @_(get: "people") { | |
people @_( | |
keyBy: "name" | |
mapValues: "filmConnection.films" | |
) { | |
name | |
filmConnection { | |
films @_(map: "title") { | |
title | |
} | |
} | |
} | |
} | |
} | |
`; | |
export default gqlLodash(query)(MyComponent); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment