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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! This was driving me crazy for a few hours.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.