relay-tools/react-router-relay

Unable to get variable in fragment

nikhildaga opened this issue · 2 comments

index.js

import React, { PropTypes } from 'react';
import Relay from 'react-relay';
import app from './app';

const queries = {
  viewer: (Component, variables) => Relay.QL`
    query {
      viewer{
        ${Component.getFragment('viewer', variables)}
      }
    }
  `,
};

module.exports = {
  path: 'post/:id',
  queries,
  getComponent(nextState, cb) {
    require.ensure([], () => {
      cb(null, app);
    });
  },
};

app.js

const App = Relay.createContainer(AppComponent, {
  initialVariables: {
    id: null,
  },
  fragments: {
    viewer: (variables) => Relay.QL `
      fragment on viewer {
        post(id: $id) {
          title,
        }  
      }
    `,
  },
});

This doesn't work. What am I doing wrong here? I have gone through readme and tried several things but still have not been able to get it to work.

Please help. :)

taion commented

See multiple previous issues: #53, #57, #58, &c.

Thanks. I found out the problem. Not sure if its related to those issues.

If the path is post/1 , the variable passed to fragment is "1"
In my schema I has set the argument id as GraphQLInt.
I changed it to GraphqlString and now its working fine.