Advertisement
Guest User

Untitled

a guest
May 24th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. import React from 'react';
  2. import gql from 'graphql-tag';
  3. import { gqlLodash } from './utils';
  4.  
  5. // The data prop, which is provided by the wrapper below contains,
  6. // a `loading` key while the query is in flight and posts when it is ready
  7. function MyComponent({data: {loading, peopleToFilms}}) {
  8. if (loading) return (<div> Loading... </div>);
  9. let people = Object.keys(peopleToFilms);
  10. return (
  11. <dl>
  12. {people.map(name => (
  13. <div key={name}>
  14. <dt>{name}</dt>
  15. <dd>
  16. {peopleToFilms[name].map(film => (
  17. <div> {film} </div>
  18. ))}
  19. </dd>
  20. </div>
  21. ))}
  22. </dl>
  23. );
  24. }
  25.  
  26. const query = gql`
  27. query {
  28. peopleToFilms: allPeople @_(get: "people") {
  29. people @_(
  30. keyBy: "name"
  31. mapValues: "filmConnection.films"
  32. ) {
  33. name
  34. filmConnection {
  35. films @_(map: "title") {
  36. title
  37. }
  38. }
  39. }
  40. }
  41. }
  42. `;
  43.  
  44. export default gqlLodash(query)(MyComponent);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement