This is an experimental package inspired by facebook's GraphQL.
It provides a practical way of declaring data schemas on the server so that data can be queried in a way that's easy to reason about.
npm install graph-data-layer
This package has two concerns only:
- Data schemas, providing all info a query can ask for.
- Data queries, providing all info needed to fulfill it.
Both schemas and queries are just JavaScript objects following an specific structure. We target convention over configuration so we can achieve a simpler syntax for both schemas and queries that are as similar as possible.
import initLayer from 'graph-data-layer';
const layer = initLayer();
const schema = {
resolve() {
return {
names: {
first: 'Lucas',
last: 'Sunsi',
},
occupation: 'Magician',
};
},
firstName(u) {
return user.names.first;
},
hasAwesomeOccupation(u) {
return u.occupation === 'Magician';
},
};
layer.register('ownerUser', schema);
const query = {
ownerUser: {
firstName: true,
},
};
layer.fulfill(query).then(console.log);
// { firstName: 'Lucas' }
MIT