简体   繁体   中英

Dynamic relations based on graph info

Is there a library out there that would be able to figure out which relations to add to a typeorm repository query that would link a request related graphql field?

I created a one-off method for one of my resolvers that does something like this, but I am looking for an overall solution.

      orgRelations(info) {
        const validRelations = ['createdBy', 'ownedBy'];
        const fields = _.chain(info.fieldNodes)
          .map(a => a.selectionSet).flatten()
          .map(i => i.selections).flatten()
          .map(i => i.name.value).value()
        return _.intersection(validRelations, fields);
      }

Vesper Framework has support for automatic relations loading.

You shouldn't compile the sql on the root query level as you might support args or access level on fields (relations), so it will be super hard to maintain in that architecture (duplicate control logic in every root query).

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