https://github.com/baslr/sgq
schema graphql query – query GraphQL with only a GraphQL IDL schema
https://github.com/baslr/sgq
Last synced: over 1 year ago
JSON representation
schema graphql query – query GraphQL with only a GraphQL IDL schema
- Host: GitHub
- URL: https://github.com/baslr/sgq
- Owner: baslr
- Created: 2017-07-10T10:26:29.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-11T16:08:23.000Z (almost 9 years ago)
- Last Synced: 2024-04-24T14:19:56.076Z (about 2 years ago)
- Language: JavaScript
- Size: 18.6 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# sgq
schema graphql query – query GraphQL with only a GraphQL IDL schema.
Are you tired of writing GraphQL.js schema files?
Then try `sgq`. `sgq` needs only a GraphQL IDL file and generates the GraphQL.js schema automatically.
# Example
```es6
'use strict';
const graphql = require('graphql-sync').graphql;
const sgq = require('sgq');
let typeDefs = [`
type BlogEntry {
_key: String!
authorKey: String!
author: Author @aql(exec: "FOR author in Author filter author._key == @current.authorKey return author")
}
type Author {
_key: String!
name: String
}
type Query {
blogEntry(_key: String!): BlogEntry
}
`]
const schema = sgq(typeDefs);
const query = `
{
blogEntry(_key: "1") {
_key
authorKey
author {
name
}
}
}`;
const result = graphql(schema, query);
print(result);
/*
{
"data" : {
"blogEntry" : {
"_key" : "1",
"authorKey" : "2",
"author" : {
"name" : "Plumbum"
}
}
}
}
*/`
```
In this example two types and a query are defined. `BlogEntry` and `Author`. BlogEntry has a sub attribute Author which is fetched with a @aql directive. The query returns a BlogEntry with the corresponding Author depending on the BlogEntries _key.