Vincit / objection-graphql

GraphQL schema generator for objection.js
MIT License
307 stars 34 forks source link

'builder.tableRefFor is not a function' #12

Closed maxwellsmart84 closed 7 years ago

maxwellsmart84 commented 7 years ago

Objection: 0.7.12 Knex: 0.13.0 MySql: 2.12.0

When trying to execute a graphQL query per the example given in the readME I am getting an error at line 350 of SchemaBuilder.js.

` _filterForSelects(astNode, modelClass) { const relations = modelClass.getRelations(); const selects = [];

for (let i = 0, l = astNode.selectionSet.selections.length; i < l; ++i) {
  const selectionNode = astNode.selectionSet.selections[i];
  const relation = relations[selectionNode.name.value];

  if (!relation) {
    selects.push(selectionNode.name.value);
  }
}

if (selects.length === 0) {
  return null;
}

return (builder) => {
  builder.select(selects.map(it => {
    if (modelClass.jsonSchema.properties[it]) {
      console.log(modelClass.jsonSchema.properties)
      return `${builder.tableRefFor(modelClass)}.${it}`;
    } else {
      return it;
    }
  }));
};

} }`

'builder.tableRefFor is not a function'

Upon inspection that it is looking for this method off of the knex query builder but I do not see this listed inside the object. I went ahead and did a search in my entire project (including node_modules) and could not find this called anywhere. I was just wondering what this is supposed to do and why I can't seem to find it anywhere.

When I take this if logic out and just return the property mapping i get a correct return however since I am not sure what this does and I have not built any complex queries (I am trying to proof of concept this) I am hesitant to remove it.

maxwellsmart84 commented 7 years ago

Additional information - here is my log output of the builder:


   { [Function: knex]
     Promise:
      { [Function: Promise]
        TypeError: [Function: TypeError],
        RangeError: [Function: RangeError],
        CancellationError: [Function: SubError],
        TimeoutError: [Function: SubError],
        OperationalError: [Function: OperationalError],
        RejectionError: [Function: OperationalError],
        AggregateError: [Function: SubError],
        _peekContext: [Function],
        onPossiblyUnhandledRejection: [Function],
        onUnhandledRejectionHandled: [Function],
        longStackTraces: [Function],
        hasLongStackTraces: [Function],
        config: [Function],
        getNewLibraryCopy: [Function],
        is: [Function],
        fromCallback: [Function],
        fromNode: [Function],
        all: [Function],
        cast: [Function],
        fulfilled: [Function],
        resolve: [Function],
        rejected: [Function],
        reject: [Function],
        setScheduler: [Function],
        pending: [Function],
        defer: [Function],
        method: [Function],
        try: [Function],
        attempt: [Function],
        bind: [Function],
        PromiseInspection: [Function: PromiseInspection],
        join: [Function],
        Promise: [Circular],
        version: '3.5.0',
        map: [Function],
        using: [Function],
        delay: [Function],
        coroutine: [Object],
        spawn: [Function],
        promisify: [Function],
        promisifyAll: [Function],
        props: [Function],
        race: [Function],
        reduce: [Function],
        settle: [Function],
        some: [Function],
        _SomePromiseArray: [Function: SomePromiseArray],
        filter: [Function],
        each: [Function],
        mapSeries: [Function: PromiseMapSeries],
        any: [Function],
        noConflict: [Function: noConflict] },
     queryBuilder: [Function: queryBuilder],
     raw: [Function: raw],
     batchInsert: [Function: batchInsert],
     transaction: [Function: transaction],
     initialize: [Function: initialize],
     destroy: [Function: destroy],
     domain: null,
     _events: {},
     _eventsCount: 0,
     _maxListeners: undefined,
     setMaxListeners: [Function: setMaxListeners],
     getMaxListeners: [Function: getMaxListeners],
     emit: [Function: emit],
     addListener: [Function: addListener],
     on: [Function: addListener],
     prependListener: [Function: prependListener],
     once: [Function: once],
     prependOnceListener: [Function: prependOnceListener],
     removeListener: [Function: removeListener],
     removeAllListeners: [Function: removeAllListeners],
     listeners: [Function: listeners],
     listenerCount: [Function: listenerCount],
     eventNames: [Function: eventNames],
     with: [Function],
     select: [Function],
     as: [Function],
     columns: [Function],
     column: [Function],
     from: [Function],
     fromJS: [Function],
     into: [Function],
     withSchema: [Function],
     table: [Function],
     distinct: [Function],
     join: [Function],
     joinRaw: [Function],
     innerJoin: [Function],
     leftJoin: [Function],
     leftOuterJoin: [Function],
     rightJoin: [Function],
     rightOuterJoin: [Function],
     outerJoin: [Function],
     fullOuterJoin: [Function],
     crossJoin: [Function],
     where: [Function],
     andWhere: [Function],
     orWhere: [Function],
     whereNot: [Function],
     orWhereNot: [Function],
     whereRaw: [Function],
     whereWrapped: [Function],
     havingWrapped: [Function],
     orWhereRaw: [Function],
     whereExists: [Function],
     orWhereExists: [Function],
     whereNotExists: [Function],
     orWhereNotExists: [Function],
     whereIn: [Function],
     orWhereIn: [Function],
     whereNotIn: [Function],
     orWhereNotIn: [Function],
     whereNull: [Function],
     orWhereNull: [Function],
     whereNotNull: [Function],
     orWhereNotNull: [Function],
     whereBetween: [Function],
     whereNotBetween: [Function],
     andWhereBetween: [Function],
     andWhereNotBetween: [Function],
     orWhereBetween: [Function],
     orWhereNotBetween: [Function],
     groupBy: [Function],
     groupByRaw: [Function],
     orderBy: [Function],
     orderByRaw: [Function],
     union: [Function],
     unionAll: [Function],
     having: [Function],
     havingRaw: [Function],
     orHaving: [Function],
     orHavingRaw: [Function],
     offset: [Function],
     limit: [Function],
     count: [Function],
     countDistinct: [Function],
     min: [Function],
     max: [Function],
     sum: [Function],
     sumDistinct: [Function],
     avg: [Function],
     avgDistinct: [Function],
     increment: [Function],
     decrement: [Function],
     first: [Function],
     debug: [Function],
     pluck: [Function],
     clearSelect: [Function],
     clearWhere: [Function],
     insert: [Function],
     update: [Function],
     returning: [Function],
     del: [Function],
     delete: [Function],
     truncate: [Function],
     transacting: [Function],
     connection: [Function],
     client:
      Client_MySQL {
        config: [Object],
        connectionSettings: [Object],
        driver: [Object],
        __cid: 'client0',
        pool: [Object],
        valueForUndefined: [Object],
        _events: [Object],
        _eventsCount: 4,
        makeKnex: [Function: makeKnex] } },
  _operations: [],
  _context:
   QueryBuilderContext {
     userContext: {},
     options: InternalOptions { skipUndefined: false, queryProps: null, debug: false },
     knex: null,
     runBefore: [],
     runAfter: [],
     onBuild: [] },
  _modelClass:
   { [Function: Address]
     tableName: 'Addresses',
     jsonSchema: { type: 'object', required: [Object], properties: [Object] },
     relationMappings: { users: [Object] },
     jsonAttributes: [] },
  _explicitRejectValue: null,
  _explicitResolveValue: null,
  _eagerExpression: null,
  _eagerFilterExpressions: [],
  _allowedEagerExpression: null,
  _allowedInsertExpression: null,
  _findOperationOptions: {},
  _eagerOperationOptions: {},
  _findOperationFactory: [Function],
  _insertOperationFactory: [Function],
  _updateOperationFactory: [Function],
  _patchOperationFactory: [Function],
  _relateOperationFactory: [Function],
  _unrelateOperationFactory: [Function],
  _deleteOperationFactory: [Function],
  _eagerOperationFactory: [Function: WhereInEagerAlgorithm] }```
koskimas commented 7 years ago

You need to update to objection 0.8.X

maxwellsmart84 commented 7 years ago

@koskimas ahh I see thanks a bunch! I was putting off updating my models but I guess now is a good time 👍

Edit: Maybe we can put that in the readme.md? I didn't see any mention of it.

koskimas commented 7 years ago

There is a minimum peer dep version in package.json and it is wrong at the moment. I'll fix it.

koskimas commented 7 years ago

Fixed in #13