简体   繁体   中英

Meteor apollo graphql query with react using props

So far I managed to set up the schema and resolvers, apollo seems to be up and running. All that is left is to tie in my react component.

I am not totally sure the syntax or procedure to call the query

Say I have the following schema defined on the server:

  type Query {
    itemById(_id: String) : Item
  }

  schema {
    query: Query
  }

  type Item {
    _id: String!
    text: String!
  }

And the following component:

const Item = ({data}) => {
  return <div>{data.text}</div>;
}

Item.propTypes = {
  _id: PropTypes.string.isRequired,
}

How do I decorate Item to get the item data, with the property "_id" taken from an external source such as session variable or url parameter?

Pass the _id as a variable, like avatarSize in the docs:

http://dev.apollodata.com/react/queries.html#graphql-options

( Profile is a component defined at top )

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM