Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/littlstar/gqlc
GraphQL Schema Compiler
https://github.com/littlstar/gqlc
Last synced: about 1 month ago
JSON representation
GraphQL Schema Compiler
- Host: GitHub
- URL: https://github.com/littlstar/gqlc
- Owner: littlstar
- License: mit
- Created: 2016-01-12T13:15:00.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2016-01-15T21:39:05.000Z (almost 9 years ago)
- Last Synced: 2024-11-13T12:45:02.638Z (about 2 months ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# gqlc
GraphQL Schema Compiler
**GraphQLC** (or GQLC) is built on
[GraphQL.js](https://github.com/graphql/graphql-js) and
leverages the schema language parser built into GraphQL. GQLC allows users
to define their schemas using the language defined by the [GraphQL
Spec](https://facebook.github.io/graphql), bind implementations for
routines for resolving data, and get a `GraphQLSchema` object to pass
directly to the `graphql()` function. This allows authors to focus on the
implementation details of their graph data set.## Supported schema language features
* InterfaceTypeDefinition
* ObjectTypeDefinition
* EnumTypeDefinition
* UnionTypeDefinition
* InputObjectTypeDefinition
* TypeExtensionDefinition## Installation
GQLC is written in ES6 and intended to be used with
[GraphQL.js](https://github.com/graphql/graphql-js) in a Node.js
environment.```sh
$ npm install --save gqlc
```## Hello World
Below is a simple hello world that query the graph for a fixed resolved value.
```js
import { graphql } from 'graphql'
import gqlc from 'gqlc'const implementation = {
Query: {
fields: () => ({
hello: { resolve () { return 'world' } }
})
}
}const Schema = `type Query { hello: String }`
const query = `query { hello }`gqlc(implementation)
.compile(Schema)
.then((schema) => graphql(schema, query))
.then((result) => console.log(result)) // { data: { hello: 'world' } }
.catch((error) => console.error(error))
```## Examples
* [Basic](examples/basic)
* [Advanced](examples/advanced)## Usage
The `gqlc()` function accepts an optional initial state object and a
required implementation object. The return value of the `gqlc()` function
represents the current state of the schema definition. A GraphQL schema can
be compiled by calling the `.compile()` method on the state object returned
by the `gqlc()` function. A `Promise` providing an instance the `GraphQLSchema`
object is returned. It can be used directly with the `graphql()`
function.```js
const state = gqlc([initialState,]implementation)
state.compile(schemaSource).then((schema) => graphql(schema, query))
```## License
MIT