GQLify Open Source
Hi everyone! We are so happy to show you our new open source project - GQLify. After canner released, we spend much time on how to save developer time on building GraphQL projects. Today, we launched a new open source project called "GQLify"! With GQLify, only thing you need to do is define the Data Model and GQLify will generate APIs for you.
GQLify helps you do following things:
- Auto-generate GraphQL Schema
- Support multiple data sources (e.g. Firebase, Firestore, MongoDB, ...)
- Auto-generate APIs for different data sources.
- Auto-generate Query functions
- Auto-generate Mutation functions
- Handle relationship between data model (one-to-one, one-to-many, many-to-many)
- Auto-generate Apollo Server configuration
Learn more Why GQLify.
- ๐ GQLify official site: https://www.gqlify.com
- ๐ GQLify documentation: https://www.gqlify.com/docs/intro
Quick Demo
- Define your schema in
demo.graphql
type User @GQLifyModel(dataSource: "memory", key: "users") {
id: ID! @unique @autoGen # auto generate unique id
username: String!
email: String
books: [Book!]! # User-Book: one-to-many
}
type Book @GQLifyModel(dataSource: "memory", key: "books") {
id: ID! @unique @autoGen # auto generate unique id
name: String!
author: User!
}
- Setup GQLify with Apollo Server in
index.js
const { Gqlify, MemoryDataSource } = require('@gqlify/server')
const { ApolloServer } = require('apollo-server');
// Read datamodel
const sdl = readFileSync(__dirname + '/demo.graphql', { encoding: 'utf8' });
// mock default data
const defaultData = {
users: [
{id: '1', username: 'Alice', email: 'alice@gmail.com'},
{id: '2', username: 'Bob', email: 'bob@gmail.io'},
],
books: [
{id: '1', name: 'book1', userId: '1'},
{id: '2', name: 'book2', userId: '2'},
],
};
// construct gqlify
const gqlify = new Gqlify({
// provide datamodel to gqlify
sdl,
// provide data-sources map to GQLify,
// so GQLify would know how to create data-source for each model
dataSources: {
memory: args => new MemoryDataSource(defaultData[args.key]),
},
});
// GQLify will provide graphql apis & resolvers to apollo-server
const server = new ApolloServer(gqlify.createApolloConfig());
// start server
server.listen().then(({ url }) => {
console.log(`๐ Server ready at ${url}`);
});
- Start server!
$ node index.js
Now, GQLify console your data model and relationship.
Open http://localhost:4000
, and you can enjoy GQLify.
Feedback!
Let us know what you thought! By tweeting to @cannerIO!