Socket
Socket
Sign inDemoInstall

graphql-genie

Package Overview
Dependencies
8
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-genie


Version published
Weekly downloads
6
increased by200%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

GraphQL Genie Logo

GraphQL Genie

npm version Dependency Status devDependency Status npm

Write a GraphQL Type Schema and GraphQL Genie automatically generates a fully featured GraphQL API with referential integrity and inverse updates that can be used client side or server side. You can use all the features of the type schema, including interfaces and unions. Add subscriptions with the plugin. The schema uses best practices and is compliant with the Relay GraphQL Server Specification.

Demo

See the fully featured demo. Create a schema (or use the default provided) and a fully featured api is created. Click the search icon to use GraphiQL to view docs and create or mock data. See graphql genie client on github for more info on the demo.

Or for a server demo see the graphql yoga redis example (no external db setup required as it uses a mock redis) or graphql yoga postgres example

Installation

npm install graphql-genie fortune graphql graphql-tools lodash

or

yarn add graphql-genie fortune graphql graphql-tools lodash

Getting started

  1. Create your type definitions. These are GraphQL Type definitions, GraphQL Genie does have some additional directives which may be useful (unique, relations, timestamps, default values). Documentation in docs/sdl.md
  2. Setup fortune options with your adapter and other settings. See example below or fortune docs and documentation for your adapter
  3. Create the schema using genie.
    1. Create a new GraphQLGenie object
    2. call genie.init() (returns a promise)
    3. call genie.getSchema() to get the GraphQLSchema
import { FortuneOptions, GraphQLGenie } from 'graphql-genie';
import mongodbAdapter from 'fortune-mongodb';

//adapter: configuration array for the data store. The default type is the memory adapter. See below for other adapter options
const fortuneOptions: FortuneOptions = {
    adapter: [
        mongodbAdapter,
        {
            // options object, URL is mandatory.
            url: config.mongodbURL
        }
    ],
    settings: { enforceLinks: true }
};
// Instantiate Genie with your type defintions as a string
const typeDefs = `[TYPEDEFS]`
const genie = new GraphQLGenie({ 
    typeDefs: typeDefs, 
    fortuneOptions: fortuneOptions
});

// init genie, this sets up all the new types and resolvers, init returns a promise so use await or .then()
await genie.init();

// get the schema and use it with any other tools you want
const schema: GraphQLSchema = genie.getSchema();

Data Store

GraphQLGenie uses FortuneJS for accessing the data store. This means any fortune adapter will work, plugins currently exist for memory (example), IndexedDB (example), MongoDB (example), Postgres (example), Redis, Google Cloud Datastore, NeDB and File System. Or you could write your own.

Subscriptions

GraphQL Genie also supports subscriptions with the subscriptions plugin.

GraphQLGenie API

The api documentation can be found in the docs folder

Authentication

Work is in progress on a plugin to make it extremely easy to add Authentication to a schema created with GraphQL Genie. There are a lot of ways to have some sort of authentication with a GraphQL API and Genie gives you the flexibility to do it any way you want or integrate into services such as Auth0 or Firebase.

Some options to add authentication

  • At the schema level using the addSchemaLevelResolveFunction from graphql-tools
  • At the resolver level use a tool like graphql-resolvers to combine a resolver with authentication logic with the resolvers that GraphQL Genie created
  • At the data level create an input hook and add it to the DataResolver (returned by getDataResolver) and throw an error if not authorized

How do I do/add [thing]

You can use the methods on the GraphQLSchemaBuilder (returned by getSchemaBuilder()) to add types and resolvers to the generated schema. Or since it is just a normal schema you can use any tool you want (such as graphql-tools) to alter the schema in any way. Including adding resolvers, mocking, stitching, transforming, etc.

If you want guidance feel free to open an issue and label it as a question.

Additional documentation is in development, see examples and tests for implementation examples.

Features/Advantages/Differences

GraphQL Genie is inspired by Prisma GraphQL and the resulting API has a lot of similarities but they have different goals. Because GraphQL Genie gives you a fully functioning graphql api but is not opinionated about anything else you have the flexibility to use that schema wherever you want and integrate it with any existing services you use.

  • Bi-directional relationships in any database with a GraphQL API
  • Portable storage options, use anywhere for any purpose which is essential for some applications.
  • Export/Import/Merge data between data sources
  • Share GraphQL data model on server and client
  • You can use The Apollo Platform, Relay, GraphQL Bindings or any of the many other tools in the growing GraphQL ecosystem.
  • You can use your existing authentication methods or one provided by an outside service.
  • The api stays the same regardless of data source, so you are never locked into one database or even server/client side
  • You can make your api logic completely serverless

TODO

  • API Documentation
  • Authentication Example
Thanks/Credit

Prisma GraphQL / Graphcool for inspiration

FortuneJS for CRUD adapters

Logo Icon made by Freepik from www.flaticon.com is licensed by CC 3.0 BY

FAQs

Last updated on 12 Jul 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc