I have a component that shows all users tied to a specific type of entity. The component renders with the apollo graphql compose helper. The export of the component looks like this:
export const UsersContainer = compose(
connect(mapStateToProps, mapDispatchToProps),
graphql(gql`
query manager($id: Int!) {
manager(id: $id) {
users {
id
firstName
lastName
email
username
}
}
}`, {
options: (props) => ({
variables: {
id: props.currentOrg.org.id
}
}),
})
)(Users);
This all works fine. The issue I'm facing is that I want to make this component dynamic so it will work with all entity types (ie. manager
, client
, vendor
). So, in the above query: query manager($id: Int!)
would change to: query client($id: Int!)
, and so forth.
How can I access the redux store to pull in data to dynamically build the gql
query? The data is all available in the store. I just need a way to access the props in a way that I can dynamically build the gql query.