Bug: Dataprocessor integration with GraphQL is broken

The GraphQL documentation says that

To save all client-side data changes to server, Webix Dataprocessor is used.

I’ve modified your Dataprocessor sample to show that somewhere along the way, Dataprocessor loses the response from the server. Open the console, click the button in the sample, and notice:

  • the Promise returned by save(...) resolves to undefined instead of the response from the server
  • onAfterSave and onAfterSync don’t actually take the documented arguments
  • onAfterSaveError doesn’t fire, even though there is an error when trying to add a product and the response does contain an errors array, as can be seen in the Network panel of DevTools

Hello,

I can confirm the issue. We will investigate the problem and fix it.
Thank you!

Thank you in advance for the fix! An additional problem is that after saving a record with save, its id needs to be read back from the GraphQL server and set into the table, because the database behind the GraphQL server will generate its own id, while the datatable generates one based on the current time.

How can this (updating the table that owns the Dataprocessor) be done in a generic way, from the insert method of the Dataprocessor?

  1. $$('tableid').updateItem(...) would theoretically work, but that requires hardcoding the id of the table.
  2. Practically, the above doesn’t work, because changing the ID triggers this error: “Attempt to change ID in updateItem”.

updateFromResponse and onAfterInsert suggested in this thread didn’t do anything.

somewhere along the way, Dataprocessor loses the response from the server.

Indeed - the GraphQL proxy simply doesn’t handle the presence of an errors key at all.

Looks like errors are handled by the ajax() call, which relies on the HTTP response status. ApolloServer sends 200 OK for many errors because a response may still be returned even if a resolver returns an error for a particular field. In those cases, Webix loses the error key from the response and only looks at data.

Any updates on this after I’ve submitted the PR to fix error handling?

My GraphQL server-side code returns the response as
{"data":{"createFilter":{"id":"5d5b...b0d"}}}
and according to this part of the documentation, the id of the filter record should be updated automatically:

As it was stated earlier, the new ID from response of an insert request will automatically replace the temporary client-side ID. This is part of default DataProcessor behavior, and no specific actions are required.

What happens is that the automatically generated timestamp-based ID is used for the new record.

I’m using a combo with its suggest.data set to a DataCollection with a save.insert(...) method like this:

save: {
  insert(id, op, filter) {
    return webix.proxy('GraphQL', `
      mutation($filter: FilterInput!) {
        createFilter(filter: $filter) {
          id
        }
      }
    `).save({ filter })
}