Socket
Book a DemoInstallSign in
Socket

graphql-aql-generator

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-aql-generator

query graphql with only a graphql idl schema

latest
Source
npmnpm
Version
2.1.0
Version published
Maintainers
1
Created
Source

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

'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.

Keywords

graphql

FAQs

Package last updated on 12 Jul 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts