Vincit / objection-graphql

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

Allow for use of instance of Objection QueryBuilder #32

Closed Trellian closed 6 years ago

Trellian commented 6 years ago

In implementing Mutations, I am trying to call insertAndFetchByID and updateAndFetchByID, to satisy the GraphQL requirements to perform a Mutation and retrieve the results in a single trip, but the QueryBuilder throws an error, saying that these operations are only available on an actual instance of the QueryBuilder, and as a result I have to use the standard insert and update methods.

I am adding the fields requested as update/insert (data, ['returning']) to the calls as required for passing them to Knex. Knex accepts them and performs the operation without complaining, but I still only get an Integer in return, indicating number of records updated.

I am guessing that objection-graphql is using Objection.js's static QueryBuilder methods in composing the calls to objection.js, and that is what is causing this?

Currently, the end result of this problem is that I have to jump through hoops to update my Apollo Store Cache after the mutations, and a full invalidation of the cache is required. Ouch.

Is there a way around this, to get the desired behaviour?

Thanks!

koskimas commented 6 years ago

To answer as vaguely as the question was composed: yes the objection QueryBuilder is used and the insertAndFetchById and updateAndFetchById are there. :smile:

(ps. please add more information about what you are trying to do and where so that I can give you a real answer. Code examples always help alot)

Trellian commented 6 years ago

@koskimas , I have yet again wasted your time... I was missing the 'Id' parameter, and completely misconstruing the error message. My apologies ') It works fine now. Also, please ignore my PR #30 for now , it has two small errors. I will fix it and re-issue.

Thanks