Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/courajs/ember-query-layer
https://github.com/courajs/ember-query-layer
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/courajs/ember-query-layer
- Owner: courajs
- License: mit
- Created: 2018-01-29T00:03:14.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-01-29T14:17:43.000Z (almost 7 years ago)
- Last Synced: 2024-11-07T08:46:18.854Z (about 2 months ago)
- Language: JavaScript
- Size: 71.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# ember-query-layer
An experiment in more declarative data loading.
This is experimental! It doesn't really work yet, and won't have a stable
API for a while.To simplify and get something working, it only supports a very limited
subset of GraphQL queries: a single query for a single root field, with
a single optional `id` argument. The root field must match the name of
an existing Ember Data model. Include the id to fetch a single record,
or omit it to fetch all. No nested fields, mutations, fragments, or
directives are supported.This will be expanding as we figure out how to properly
## Installation
* `ember install ember-query-layer`
## Planned Usage
WAIT! Using `model()` isn't really ideal, since it doesn't always get
called. Was there a new hook called `data()` or something? Or could we
reopen link-to somehow and check whether the target route has a
query-layer model hook?This doesn't work yet! But practicing some README-driven development,
here's what I'm thinking:```js
import { query } from 'ember-query-layer';
export default Route.extend({
model: query`
query PostsRoute {
post {
comments {
author
}
}
}
`
});
```This will have a similar effect to (although without the confusing
semantics of reload, backgroundReload, or async relationships. A single
promise is returned, which resolves with all the data you requested.
Note - you don't need to specify scalar fields (only relationships), because they're already
specified in your DS.Model, and REST endpoints usually return the whole
record anyway)
```js
export default Route.extend({
model() {
return this.store.findAll('post', {
include: 'comments,comments.author'
});
}
});
```You can use
Equivalent to `store.findRecord()`:
```js
import { Route } from '@ember/routing';
import { query } from 'ember-query-layer';export default Route.extend({
model: query`
query PostRoute($post_id: ID) {
post(id: $post_id)
}
`
});
```