Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encapsulate payload in update passed to dataSource #36

Open
wwwy3y3 opened this issue Dec 26, 2018 · 1 comment
Open

Encapsulate payload in update passed to dataSource #36

wwwy3y3 opened this issue Dec 26, 2018 · 1 comment
Assignees
Labels
Milestone

Comments

@wwwy3y3
Copy link
Contributor

wwwy3y3 commented Dec 26, 2018

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

Also for future possible features like:

  • Increase/decrease a field value
  • update nested object field without overriding the whole object field

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 wwwy3y3 added enhancement New feature or request data-source graphql labels Dec 26, 2018
@wwwy3y3 wwwy3y3 added this to the v2.0 milestone Dec 26, 2018
@wwwy3y3 wwwy3y3 self-assigned this Dec 26, 2018
@wwwy3y3 wwwy3y3 changed the title Encapsulate payload in update and create passed to dataSource Encapsulate payload in update passed to dataSource Dec 26, 2018
@wwwy3y3
Copy link
Contributor Author

wwwy3y3 commented Feb 5, 2019

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'}]
  }
}) {...}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant