adamsoffer/next-apollo

Dynamic fetching based on route

Closed this issue · 1 comments

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?

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));