GraphQL adapter for Ember Data
When resolving an ember model object graph, objects that contain relationships that itself contain relationships with the same name do not get resolved. Example:
+-- industry
+-- id
+-- title
+-- details
+-- geographies
| +-- id
| +-- name
| +-- code
+-- companies
| +-- id
| +-- name
+-- subIndustries
+-- id
+-- title
+-- details
+-- geographies (missing)
| +-- id
| +-- name
| +-- code
+-- companies (missing)
+-- id
+-- name
Given the industry object graph above, an industry's relationships (geographies, companies) are missing from the response of an industry's graphql query.
The ember-graphql-adapter
keeps track of visited
relationships by the relationship name. If it encounters the same relationship name again, it will not walk down that path when parsing and building the ember object graph. This results in a generated graphql query with child relationships missing relationships.
Extend the options of the ember model definition with resolveAlways
. When the parser encounters this option, it will traverse this relationship even if it has already been visited
.
E.g. Given a model:
import DS from 'ember-data';
export default DS.Model.extend({
comment: DS.belongsTo('comment', { async: false })
});
When calling .save()
on an instance of this model, the query would be serialized like this by ember-graphql-adapter
:
mutation post_update (id: "1", comment: "object Object") { id comments { id body } }
To allow the usage of async: false
and to allow your GraphQL schema to accept objects as arguments, the adapter will now serialize the above example like so:
mutation post_update(id: "1", comment: { id: "2", body: "bar" }) { id comments { id body } }
Something dodgy happened publishing 1.0.2 😅
errors
key is present on the response. This behaviour was inadvertently removed in v0.4.0E.g. Given a model:
import DS from 'ember-data';
export default DS.Model.extend({
comments: DS.hasMany('comments', { async: false })
});
When calling .save()
on an instance of this model, the query would be serialized like this by ember-graphql-adapter:
mutation post_update (id: "1", comments: "[object Object]") { id comments { id body } }
To allow the usage of async: false
and to allow your GraphQL schema to accept arrays of objects as arguments, the adapter will now serialize the above example like so:
mutation post_update(id: "1", comments: [{ id: "1", body: "foo"}, { id: "2", body: "bar" }]) { id comments { id body } }