Git Product home page Git Product logo

simpl-to-graphql-schema's Introduction

Simpl To GraphQL Schema

This is new updated and improved fork of # Simple Schema - GraphQL Schema Bridge except it doesn't build your resolvers.

Change only your Meteor Simple Schema: GraphQL schema are updated automatically.

Define your Simple Schemas for your collection and let simpl-to-graphql-schema do the tedious work of defining the schema's basic fields and resolvers, for you.

This tool works with Meteor Framework.

  • Installation

npm install --save simpl-to-graphql-schema

  • Your simple schema
import SimpleSchema from 'simpl-schema';
import { Mongo } from 'meteor/mongo';

// Define your collection
const Items = new Mongo.Collection('items');

//build your schema with SimpleSchema as usual
const Schemas = new SimpleSchema({
  _id: {
    type: String,
  },
  name: {
    type: String,
    label: "Item name",
  },
  ownerId: {
    type: String,
    label: "Owner identification",
  },
  createdAt: {
    type: String,
    label: "Item creation date",
  },
  updatedAt: {
    type: String,
    label: "Item last update",
  },
});

export default Schemas;
Items.attachSchema(Schemas);
  • Your GraphQL schema
import SimpleToGraphql from 'simpl-to-graphql';
import Schemas from './items';

const schemaGql = SimpleToGraphql.schema({ 
	// Your simple schema
	schema: Schemas, 
	// your grapqhl schema name
	name: 'Items', 
	// SimpleToGraphql options
	options: {
		// create schema only for those fields in an Array
		fields: ['name', 'ownerId', 'createdAt'],
		// insert scalars in an Array	
		scalar: ['Date'],
		// create schema except for those fields in an Array
        except: ['updatedAt'],
        // change fields type
        custom: {
            createdAt: "Date",
            updatedAt: "Date"
        },
		// add fields to your generated schema
		additional: [
			'checked: Boolean'
			'usersList: [Users]'
    ],
		// console.log() your generated schema
		print: true, //default false
	}
});
export default schemaGql;
  • Your resolvers
//in case your want to use the built in Date scalar
import { DateScalar } from 'simpl-to-graphql';
// collections
import Items from '/imports/api/pages/pages'

export default {
    Query: {
      item: (root, args, { userId }) => Items.findOne({ ownerId: userId }),
      items: (root, args, { userId }) => Items.find({ ownerId: userId }).fetch(),
    },
    // you can put it here or in your merge of resolvers with DateScalar
    Date: DateScalar.Date
  };

simpl-to-graphql-schema's People

Contributors

nehtt avatar nehhtt avatar

Watchers

James Cloos avatar Marco Wettstein avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.