Vincit / objection-graphql

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

Added basic support for Mutations #30

Closed Trellian closed 6 years ago

Trellian commented 6 years ago

I've added really basic Mutation support -

The following operations are available:

`createXXXX`
`updateXXXX`    - For whole record updates
`patchXXXX` - For partial record Updates
`deleteXXXX`

An example mutation:

    mutation regionUpdate ($Id: Int!, $CountryId: Int!, $Name: String!) {
      updateIwRegion (idEq: $Id, country_id: $CountryId, name: $Name) {
        country_id
        name
      }
    }

The selector fields which select which record(s) are to be updated must use the extra field operation syntax in the parameters for the mutation.

eg: idEq: $Id from the example above.

Other plain parameters are the fields that will be used to update the record fields.

eg: country_id: $CountryId and name: $Name from the example above.

The only result returned at this point is the number of rows affected. An extra query is required to return the updated recordset.

Damn, I also just realised that I also added the pluralizer package in the same PR. This fixes my schema so that for eg. Country gets pluralized as Countries, not as Countrys

timhuff commented 6 years ago

I'm going to go ahead and close this, as there are conflicts. Also, I'm not sure how I feel about introducing a CRUD-specific API to a GraphQL interface as one of the motivations of GraphQL was to get away from CRUD-centric mutations.