Created
August 7, 2018 18:25
-
-
Save relwell/96119c186838dd31e07a54d92ea9c6b3 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 { graphql } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
import _ from 'lodash'; | |
class SomeComponent extends React.Component { | |
render() { | |
const someFieldMap = { nctId: 'nct_id', averageRating:'average_rating' }; | |
const fields = _.map(someFieldMap, (value, key) => `${key}:field(name:"${value}")`); | |
const query = gql` | |
query mySearch($q:String! $pageSize:Int $sorts:[String] | |
search(params:{ | |
q:$q pageSize:$pageSize sorts:$sorts | |
}) { | |
data { | |
${fields.join("\n")} | |
} | |
} | |
} | |
` | |
const MyComponent = graphql(query, { | |
options: (params) => ({ | |
variables: ({ q }) => ({ q, ...params }), | |
}), | |
}); | |
return ( | |
<MyComponent {...this.props} /> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment