Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. import React from 'react';
  2.  
  3. import { Query } from 'react-apollo'
  4. import gql from 'graphql-tag'
  5.  
  6. const countryQuery = gql`
  7. query($id: Int!) {
  8. country(id: $id) {
  9. name
  10. population
  11. }
  12. }
  13. `
  14.  
  15. const FunctionQuery = ({countryId}) => {
  16. const params = {
  17. id: Number(countryId)
  18. }
  19.  
  20. return (
  21. <Query query={countryQuery} variables={params}>
  22. {({ loading, error, data }) => {
  23. if (loading) return <div>Loading...</div>
  24. if (error) return <div>ERRRORRR</div>
  25.  
  26. return (
  27. <>
  28. <h1>Function response:</h1>
  29. <div className='container'>
  30. <p className='container__item'>
  31. <span><b>Country:</b></span>
  32. <span><b>Population:</b></span>
  33. </p>
  34. <p className='container__item' key={data.country.id}>
  35. <span dangerouslySetInnerHTML={{ __html: data.country.name }}></span>
  36. <span dangerouslySetInnerHTML={{ __html: data.country.population }}></span>
  37. </p>
  38. </div>
  39. </>
  40. )
  41. }}
  42. </Query>
  43. )
  44. };
  45.  
  46. export default FunctionQuery;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement