Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamic fetching based on route #33

Closed
Vadorequest opened this issue Apr 17, 2019 · 1 comment
Closed

Dynamic fetching based on route #33

Vadorequest opened this issue Apr 17, 2019 · 1 comment

Comments

@Vadorequest
Copy link

How would you handle dynamic fetching based on the url path?

I have a simple use case where /page/item1 is my route, and need to fetch the right item data (change the gql query), but since the query is somehow "pre-written", it doesn't seem like dynamic data are possible. Or did I missed something?

@Vadorequest
Copy link
Author

const organisation = gql`
  query organisation($organisation: String!){
    organisation(where: {
      name: $organisation
    }){
      name
    }
  }
`;

The solution is to use variables

export default graphql(organisation, {
  options: (props) => {
    console.log(props)
    return {
      variables: {
        organisation: resolveSanitizedGroupName(),
      },
    }
  },
  props: ({ data }) => {
    return ({
      data,
    });
  },
})(
  compose(
    connect(mapStateToProps),
  )(Footer));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant