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

Issue with JSONAPISource #140

Closed
brancusi opened this issue Apr 26, 2015 · 2 comments
Closed

Issue with JSONAPISource #140

brancusi opened this issue Apr 26, 2015 · 2 comments

Comments

@brancusi
Copy link

Hi,

Backend: Rails + JSONAPI::Resources
Frontend: Ember

Had trouble getting ember-orbit to store to localstorage using LocalStorageSource. Seems to only live in memory

Trying to work directly with orbit now. Just playing around within an initializer doing the following:

import Ember from 'ember';
import Orbit from 'orbit';
import LocalStorageSource from 'orbit-common/local-storage-source';
import MemorySource from 'orbit-common/memory-source';
import JSONAPISource from 'orbit-common/jsonapi-source';
import OC from 'orbit-common'
import config from '../config/environment';

export var initialize = function(container, application) {
  Orbit.Promise = Ember.RSVP.Promise;
  Orbit.ajax = Ember.$.ajax;

  // Create data sources with a common schema
  var schema = new OC.Schema({
    keys: {
      __id: { primaryKey: true, defaultValue: Orbit.uuid }
    },
    models: {
      contact: {
        attributes: {
          firstName: {type: 'string'},
          lastName: {type: 'string'}
        }
      }
    }
  });

  var memorySource = new MemorySource(schema);
  var restSource = new JSONAPISource(schema);
  var localSource = new LocalStorageSource(schema);

  var memToLocalConnector = new Orbit.TransformConnector(memorySource, localSource);
  var memToRestConnector = new Orbit.TransformConnector(memorySource, restSource);
  var restToMemConnector = new Orbit.TransformConnector(restSource, memorySource);

  // Add a record to the memory source
  memorySource.add('contact', {firstName: 'Tom', lastName: 'Jones'}).then(
    function(contact) {
      console.log('Contact added - ', contact.firtName, '(id:', contact.id, ')');
    }
  );
};

export default {
  name: 'inject-store',
  initialize: initialize
};

So the localStorage works now, I see the data getting stored, but when it tries to sync to the jsonapi source, it tries to post the following json:

{
    "contacts": {
        "id": "a45a01f2-4964-4547-bbf5-3af76da8aa2a",
        "firstName": "Tom",
        "lastName": "Jones"
    }
}

using the modelType as key instead of what jsonapi resource has listed in the docs:

{
    "data": {
        "id": "a45a01f2-4964-4547-bbf5-3af76da8aa2a",
        "type": "contacts",
        "firstName": "John",
        "lastName": "Doe"
    }
}
//JR responds with
{
    "errors": [
        {
            "title": "Missing Parameter",
            "detail": "The required parameter, data, is missing.",
            "id": null,
            "href": null,
            "code": 106,
            "path": null,
            "links": null,
            "status": "bad_request"
        }
    ]
}

On a side note, it would be super helpful I think to list the version of json-api spec that the clients conform to. Both Orbit and JR. I see JR has a note stating "implements latest json-api" in one of the commit notes, but it would be great to have it in the readme with the version number.

Thanks to all of you for the amazing work. It's such an exciting project!

@dgeb
Copy link
Member

dgeb commented May 4, 2015

I'm working on bringing the JSONAPISource up to date with the spec this week, and will be tracking progress via #113. My goal is complete compliance by the JSON API 1.0 release date - May 21.

@dgeb
Copy link
Member

dgeb commented Jun 19, 2015

JSON API 1.0 compliance added via #156.

Thanks for your patience! Please open new issues as needed.

@dgeb dgeb closed this as completed Jun 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants