https://github.com/baslr/graphql-aql-generator
query GraphQL with only GraphQL IDL. Super simple.
https://github.com/baslr/graphql-aql-generator
Last synced: 8 months ago
JSON representation
query GraphQL with only GraphQL IDL. Super simple.
- Host: GitHub
- URL: https://github.com/baslr/graphql-aql-generator
- Owner: baslr
- Created: 2017-07-12T13:16:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-02-25T18:06:31.000Z (about 8 years ago)
- Last Synced: 2025-06-29T19:41:03.095Z (8 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 17
- Watchers: 1
- Forks: 3
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# graphql-aql-generator
schema graphql query – query GraphQL with only a GraphQL IDL schema.
Are you tired of writing GraphQL.js schema files?
Then try `graphql-aql-generator`. `graphql-aql-generator` needs only a GraphQL IDL file and generates the GraphQL.js schema automatically.
# Example
```es6
'use strict';
const graphql = require('graphql-sync').graphql;
const generator = require('graphql-aql-generator');
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 = generator(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"
}
}
}
}
*/`
// or use it with a GraphQLRouter
'use strict';
const createRouter = require('@arangodb/foxx/router');
const router = createRouter();
module.context.use(router);
const createGraphQLRouter = require('@arangodb/foxx/graphql');
const graphql = require('graphql-sync').graphql;
const sgq = require('sgq');
const 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);
router.use('/graphql', createGraphQLRouter({
schema: schema,
graphiql: true,
graphql: require('graphql-sync')
}));
```
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.