VulcanJS / vulcan-docs

📖 Docs for React/Apollo/Meteor version of Vulcan
http://docs.vulcanjs.org
42 stars 86 forks source link

Document how to use arrays with field resolvers #144

Closed Neobii closed 4 years ago

Neobii commented 4 years ago

A simple example should be helpful, like this:

  marketPairs: {
    label: "Market Pairs",
    type: String,
    hidden: true,
    optional: true,
    canRead: ['guests','members','admin'],
    resolveAs: {
      fieldName: 'marketPairs',
      type: '[MarketPair]',
      relation: 'hasMany',
      resolver: (coin, args, context) => {
        //change to graphql query later
        let res = context.MarketPairs.find({left: coin.exchangeSymbol}, {sort: {volume24: -1}, limit: 1}); //find latest aggregate
        return res;
      }
    }
  },