johanatan / Speako
A compiler for GraphQL schema language (written in ClojureScript)
Programming Languages
clojure
4091 projects
clojurescript
191 projects
Projects that are alternatives of or similar to Speako
Swapi Graphql
A GraphQL schema and server wrapping SWAPI.
Stars: ✭ 921 (+11412.5%)
Mutual labels: graphql
Lighthouse Utils
An add-on to Lighthouse to auto-generate CRUD actions from types https://github.com/nuwave/lighthouse
Stars: ✭ 26 (+225%)
Mutual labels: graphql
Graphql Java Codegen Maven Plugin
Maven plugin for graphql-java-codegen
Stars: ✭ 17 (+112.5%)
Mutual labels: graphql
Ezplatform Graphql
GraphQL server for eZ Platform, the open source Symfony CMS.
Stars: ✭ 27 (+237.5%)
Mutual labels: graphql
Merge Graphql Schemas
A utility library to facilitate merging of modularized GraphQL schemas and resolver objects.
Stars: ✭ 935 (+11587.5%)
Mutual labels: graphql
Gatsby Simplefolio
⚡️ A minimal Gatsby portfolio template for Developers
Stars: ✭ 895 (+11087.5%)
Mutual labels: graphql
Swapi Graphql Lambda
A GraphQL schema hosted in AWS Lambda wrapping http://swapi.co/
Stars: ✭ 19 (+137.5%)
Mutual labels: graphql
React Hasura Todo
A react todo app using Hasura Graphql engine
Stars: ✭ 18 (+125%)
Mutual labels: graphql
React Apollo Koa Example
An example app using React, Apollo and Koa
Stars: ✭ 26 (+225%)
Mutual labels: graphql
Diversidad Media
Diversidad Media is a platform to generate more diverse spaces, through Movies, Books, Music, and others. The project is in fast growth and there are many things to do. We are still covering the basics.
Stars: ✭ 17 (+112.5%)
Mutual labels: graphql
Apollo Link Maxage
An Apollo Link to invalidate cached queries
Stars: ✭ 23 (+187.5%)
Mutual labels: graphql
Graphql Spqr
Java 8+ API for rapid development of GraphQL services
Stars: ✭ 843 (+10437.5%)
Mutual labels: graphql
Kikstart Graphql Client
🚀 Small NodeJS Wrapper around apollo-client that provides easy access to running queries, mutations and subscriptions.
Stars: ✭ 27 (+237.5%)
Mutual labels: graphql
speako
A simpler interface to GraphQL
Install
- NPM -
npm install speako
Motivation
GraphQL normally requires a GraphQLSchema
object passed along with each query
you give it to validate, interpret & execute. Typically this schema is constructed
by hand-crafting some verbose & noisy JavaScript.
See: starWarsSchema.js.
The equivalent schema in GraphQL Schema Language is much more concise:
enum Episode { NEWHOPE, EMPIRE, JEDI }
type Human {
id: ID!
name: String
friends: [Character]
appearsIn: [Episode]
homePlanet: String
}
type Droid {
id: ID!
name: String
friends: [Character]
appearsIn: [Episode]
primaryFunction: String
}
union Character = Human | Droid
Given a specification of a data model in GraphQL Schema Language, speako automatically
generates the GraphQLSchema
instance that GraphQL requires and binds its resolve
methods
to a specified set of functions for querying (i.e., selecting) and mutating (i.e., insert,
update and delete mutations).
Example
$ node --harmony-destructuring
> var speako = require('speako');
> var gql = require('graphql');
> var _ = require('lodash');
> var labels = [
... {'id': 1, 'name': 'Apple Records', 'founded': '1968'},
... {'id': 2, 'name': 'Harvest Records', 'founded': '1969'}];
> var albums = [
... {'id': 1, 'name': 'Dark Side Of The Moon', 'releaseDate': 'March 1, 1973',
... 'artist': 'Pink Floyd', 'label': labels[1]},
... {'id': 2, 'name': 'The Beatles', 'releaseDate': 'November 22, 1968',
... 'artist': 'The Beatles', 'label': labels[0]},
... {'id': 3, 'name': 'The Wall', 'releaseDate': 'August 1, 1982',
... 'artist': 'Pink Floyd', 'label': labels[1]}];
> var dataResolver = {"query": function (typename, predicate) {
... console.assert(typename == "Album");
... var parsed = JSON.parse(predicate);
... if (_.isEqual(parsed, {"all": true})) return albums;
... else {
... var pairs = _.toPairs(parsed);
... var filters = pairs.map(function (p) {
... var [field, value] = p;
... if (typeof value === "object") {
... console.assert(field == "label");
... return function(elem) {
... var innerKey = _.first(_.keys(value));
... return elem[field][innerKey] == value[innerKey]; };
... }
... return function(elem) { return elem[field] == value; };
... });
... return albums.filter(function(elem) { return filters.every(function(f) { return f(elem); }); });
... }
... }, "create": function (typename, inputs) {
... inputs.id = albums.length + 1;
... albums.push(inputs);
... return inputs;
... }};
> var schema = speako.getSchema(dataResolver,
... "type Album { id: ID! name: String releaseDate: String artist: String }");
> var schema =
... speako.getSchema(dataResolver,
... ["type Label { id: ID! name: String founded: String album: Album } ",
... "type Album { id: ID! name: String releaseDate: String artist: String label: Label }"].join(" "));
> var printer = function(res) { console.log(JSON.stringify(res, null, 2)); };
> gql.graphql(schema,
... "{ Album(artist: \"Pink Floyd\", label: { name: \"Harvest Records\" }) { name artist releaseDate } }") .then(printer);
{
"data": {
"Album": [
{
"name": "Dark Side Of The Moon",
"artist": "Pink Floyd",
"releaseDate": "March 1, 1973"
},
{
"name": "The Wall",
"artist": "Pink Floyd",
"releaseDate": "August 1, 1982"
}
]
}
}
> gql.graphql(schema, "{ Album(artist: \"Pink Floyd\") { name artist releaseDate } }").then(printer);
{
"data": {
"Album": [
{
"name": "Dark Side Of The Moon",
"artist": "Pink Floyd",
"releaseDate": "March 1, 1973"
},
{
"name": "The Wall",
"artist": "Pink Floyd",
"releaseDate": "August 1, 1982"
}
]
}
}
> gql.graphql(schema, "{ Album(artist: \"Pink Floyd\", name: \"The Wall\") { name artist releaseDate } }").then(printer);
{
"data": {
"Album": [
{
"name": "The Wall",
"artist": "Pink Floyd",
"releaseDate": "August 1, 1982"
}
]
}
}
> gql.graphql(schema, "{ Album(id: 2) { name artist releaseDate } }").then(printer);
{
"data": {
"Album": [
{
"name": "The Beatles",
"artist": "The Beatles",
"releaseDate": "November 22, 1968"
}
]
}
}
> gql.graphql(schema, "{ Albums { name artist releaseDate } }").then(printer);
{
"data": {
"Albums": [
{
"name": "Dark Side Of The Moon",
"artist": "Pink Floyd",
"releaseDate": "March 1, 1973"
},
{
"name": "The Beatles",
"artist": "The Beatles",
"releaseDate": "November 22, 1968"
},
{
"name": "The Wall",
"artist": "Pink Floyd",
"releaseDate": "Auguest 1, 1982"
}
]
}
}
> gql.graphql(schema, "mutation m { createAlbum(name:\"The Division Bell\", releaseDate: \"March 28, 1994\", artist:\"Pink Floyd\") { id name } }").then(printer);
{
"data": {
"createAlbum": {
"id": "4",
"name": "The Division Bell"
}
}
}
Copyright (c) 2015 Jonathan L. Leonard
Note that the project description data, including the texts, logos, images, and/or trademarks,
for each open source project belongs to its rightful owner.
If you wish to add or remove any projects, please contact us at [email protected].