Skip to content

Instantly share code, notes, and snippets.

@RomanHotsiy
Last active May 25, 2017 16:14
Show Gist options
  • Save RomanHotsiy/f317d952647612ab68e5dbd900d4183c to your computer and use it in GitHub Desktop.
Save RomanHotsiy/f317d952647612ab68e5dbd900d4183c to your computer and use it in GitHub Desktop.
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