0

I've attached a query to my React Native component like so:

let getNearbyStoriesQuery = gql`{
  getStoriesNearbyByGeoHash(geoHash: "8k"){
      id
  }
}`;

export default graphql(getNearbyStoriesQuery,
  {
    props: (props) => {
      debugger;
      let storiesNearby = props.data.getStoriesNearbyByGeoHash.map((story) => {
        return {
          id: story.id,
        }
      });
      return {storiesNearby};
    },
    variables: {
      geoHash: mockGeoHash
    }
  })(Home);  // Home is the React Native Component

I'm able to retrieve data from using this technique as long as I hardcode a value in for geoHash in the query; in this case I used "8k". However, when I attempt to modify the query so that I can puss in a variable like so:

let getNearbyStoriesQuery = gql`{
      getStoriesNearbyByGeoHash($geoHash: String!){
          id
      }
    }`;

I get an error saying Expected Name, found $. This method of passing variables to queries is repeated across multiple sources. What am I doing wrong here?

Marco Daniel
  • 5,467
  • 5
  • 28
  • 36
reggie3
  • 1,018
  • 2
  • 15
  • 22

1 Answers1

1

Should be:

query GetStoriesNearbyByGeoHash($geoHash: String!) {
    getStoriesNearbyByGeoHash(geoHash: $geoHash){
         id
    }
}

Have a look on how to use variables in graphql: http://graphql.org/learn/queries/#variables

Andreas Köberle
  • 106,652
  • 57
  • 273
  • 297