Gqlify / gqlify

An API integration framework using GraphQL
https://www.gqlify.com
Apache License 2.0
178 stars 16 forks source link

Encapsulate payload in update passed to dataSource #36

Open wwwy3y3 opened 5 years ago

wwwy3y3 commented 5 years ago

Is your feature request related to a problem? Please describe. For issues below:

Also for future possible features like:

Describe the solution you'd like We should somehow encapsulate the payload that passed to create/update methods in dataSource.

Implementaion detail

enum ArrayOperator {
  set = 'set',
  add = 'add',
  remove = 'remove',
}

interface ArrayUpdateOperation {
  fieldName: string;
  operator:  ArrayOperator
}

interface Mutation {
  getData(): Record<string, any>;
  getArrayOperations(): ArrayUpdateOperation[];
}

interface ListMutable {
  // origin:
  // update(where: Where, payload: any): Promise<any>;
  // new:
  update(where: Where, mutation: Mutation): Promise<any>;
}

API

getData(): Record<string, any>

Should directly replace the original values with payload got from getData()

getArrayOperations(): ArrayUpdateOperation[]

getArrayOperations() will provide atomic operations like add, set, remove to dataSource

wwwy3y3 commented 5 years ago

In v3.0.0(https://github.com/Canner/gqlify/releases/tag/v3.0.0), we add set field to array field of create/update mutation.

Change

Create mutation

Before

createUser(data: {
  members: [{name: 'wwwy3y3'}]
}) {...}

After v3.0.0

createUser(data: {
  members: {
    set: [{name: 'wwwy3y3'}]
  }
}) {...}

Update mutation

Before

updateUser(data: {
  members: [{name: 'wwwy3y3'}]
}) {...}

After v3.0.0

updateUser(data: {
  members: {
    set: [{name: 'wwwy3y3'}]
  }
}) {...}