feathers-plus / generator-feathers-plus

A Yeoman generator to (re)generate a FeathersJS application supporting both REST and GraphQL architectural concepts and their query languages.

Home Page:https://generator.feathers-plus.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

graphQL populates don't support dot notation

mrfrase3 opened this issue · comments

Steps to reproduce

say we have the following line in our schema:

bookings: { type: '[Booking!]', args: true, relation: { ourTable: '_id', otherTable: 'billing.couponIds' } },

Expected behavior

The generated batch loader/service resolvers should detect a . in the name and wrap the field as a string:

    // Coupon.bookings(query: JSON, params: JSON, key: JSON): [Booking!]
    // !<DEFAULT> code: bl-Coupon-bookings
    case 'Coupon.bookings':
      return feathersBatchLoader(dataLoaderName, '[!]', 'billing.couponIds',
        keys => {
          feathersParams = convertArgs(args, content, null, {
            query: { 'billing.couponIds': { $in: keys }, $sort: undefined }, // <== stringify field
            _populate: 'skip', paginate: false
          });
          return bookings.find(feathersParams);
        },
        maxBatchSize // Max #keys in a BatchLoader func call.
      );
      // !end
      // bookings(query: JSON, params: JSON, key: JSON): [Booking!]
      bookings:
        // !<DEFAULT> code: resolver-Coupon-bookings
        (parent, args, content, ast) => {
          const feathersParams = convertArgs(args, content, ast, {
            query: { 'billing.couponIds': parent._id, $sort: undefined }, paginate: false // <== stringify field
          });
          return bookings.find(feathersParams).then(extractAllItems);
        },
        // !end

Actual behavior

No dot check, just adds in the literal string. This throws when the server start/eslint.

          feathersParams = convertArgs(args, content, null, {
            query: { billing.couponIds: { $in: keys }, $sort: undefined },
            _populate: 'skip', paginate: false
          });
          const feathersParams = convertArgs(args, content, ast, {
            query: { billing.couponIds: parent._id, $sort: undefined }, paginate: false
          });