Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add very early initial draft of plugins #83

Merged
merged 6 commits into from
Apr 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
],
"roots": [
"generator/src",
"create-graphql/src"
"create-graphql/src",
"create-graphql-core/src",
"create-graphql-plugin-mongoose/src",
"create-graphql-plugin-type/src"
],
"rootDir": "./packages/",
"verbose": true
Expand Down
10 changes: 8 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@
"jest-cli": "^19.0.2",
"lerna": "2.0.0-beta.38",
"lerna-changelog": "^0.4.0",
"nodemon": "^1.11.0",
"rimraf": "^2.6.1",
"yeoman-assert": "^3.0.0",
"yeoman-test": "^1.6.0"
"yeoman-test": "^1.6.0",
"reify": "^0.6.8",
"repl-promised": "^0.1.0",
"repl.history": "^0.1.4",
"babel-polyfill": "^6.23.0"
},
"scripts": {
"bootstrap": "lerna bootstrap",
Expand All @@ -34,6 +39,7 @@
"lint": "eslint \"packages/*/src/**/*.js\" \"packages/*/__tests__\"",
"prepublish": "npm run build",
"test": "jest --config jest.json",
"watch": "lerna exec -- npm run watch"
"watch": "lerna exec -- npm run watch",
"repl": "nodemon --config ./repl/nodemon.json ./repl.js --exec babel-node"
}
}
3 changes: 3 additions & 0 deletions packages/create-graphql-core/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}
3 changes: 3 additions & 0 deletions packages/create-graphql-core/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src
npm-debug.log
coverage
22 changes: 22 additions & 0 deletions packages/create-graphql-core/fixtures/mongoose-type/.graphqlrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"plugins": [
"mongoose",
"type"
],
"paths": {
"directories": {
"source": "src",
"connection": "connection",
"loader": "loader",
"model": "model",
"mutation": "mutation",
"mutation_test": "mutation/__tests__",
"type": "type",
"type_test": "type/__tests__",
"interface": "interface"
},
"files": {
"schema": "schema"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import mongoose from 'mongoose';

import User from './User';
const { ObjectId } = mongoose.Schema.Types;

const Schema = new mongoose.Schema({
title: {
type: String,
maxlength: 120,
required: true,
},
user: {
type: ObjectId,
ref: 'User',
description: 'User that created this post',
required: true,
},
slug: {
type: String,
indexed: true,
description: 'Used for SEO',
},
}, {
timestamps: {
createdAt: 'createdAt',
updatedAt: 'updatedAt',
},
collection: 'post',
});

export default mongoose.model('Post', Schema);
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// @flow
import mongoose from 'mongoose';

const Schema = new mongoose.Schema({
name: {
type: String,
description: 'user name',
required: true,
},
password: {
type: String,
description: 'hashed user password',
hidden: true,
},
email: {
type: String,
required: false,
description: 'user email',
index: true,
},
active: {
type: Boolean,
default: true,
},
}, {
collection: 'user',
});

export default mongoose.model('User', Schema);
56 changes: 56 additions & 0 deletions packages/create-graphql-core/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "create-graphql-core",
"description": "Create GraphQL core",
"version": "1.1.16",
"author": {
"name": "Lucas Bento",
"email": "lucas.bsilva@outlook.com",
"url": "https://github.com/lucasbento"
},
"bugs": "https://github.com/lucasbento/create-graphql/issues",
"dependencies": {
"babel-generator": "^6.24.0",
"babel-polyfill": "^6.20.0",
"babel-template": "^6.23.0",
"babel-types": "^6.23.0",
"babylon": "^6.16.1",
"chalk": "^1.1.3",
"colors": "^1.1.2",
"es-module-loader": "^2.1.4",
"lodash.merge": "^4.6.0",
"ora": "^0.4.0",
"pkg-dir": "^1.0.0",
"pluralize": "^3.1.0",
"ramda": "^0.22.1",
"recast": "^0.12.2",
"semver": "^5.1.0",
"shelljs": "^0.7.4",
"yeoman-generator": "^1.0.1"
},
"devDependencies": {},
"homepage": "https://github.com/lucasbento/create-graphql#readme",
"keywords": [
"apollo",
"create",
"generator",
"graphql",
"koa",
"relay",
"server",
"yeoman",
"yo",
"yeoman-generator"
],
"license": "MIT",
"preferGlobal": true,
"repository": {
"type": "git",
"url": "https://github.com/lucasbento/create-graphql"
},
"scripts": {
"build": "npm run clear && babel src --ignore *.spec.js --out-dir dist",
"clear": "rimraf ./dist",
"test": "jest",
"watch": "babel -w -d ./dist ./src --copy-files"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`should call getFields of first plugin, and generateTemplate from the second one 1`] = `
Array [
"export default new GraphQLObjectType({
name: \\"User\\",
description: 'Represents NAME',
fields: () => ({
id: globalIdField('NAME'),
example: {
type: GraphQLString,
description: 'My example field',
resolve: obj => obj.example
}
}),
interfaces: () => [NodeInterface]
});",
]
`;
24 changes: 24 additions & 0 deletions packages/create-graphql-core/src/__tests__/core.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import path from 'path';
import core from '../index';

/**
* Get a fixture path
* @param name {string} Name of the file of the fixture
* @returns {string} The path of the fixture
*/
const getFixturePath = name => path.join(__dirname, `../../fixtures/${name}`);

it('should call getFields of first plugin, and generateTemplate from the second one', async () => {
const testName = 'mongoose-type';
const testPath = getFixturePath(testName);

const opts = {
plugins: ['mongoose', 'type'],
name: 'User',
schema: 'User',
};

const templates = await core(testPath, opts);

expect(templates).toMatchSnapshot();
});
18 changes: 18 additions & 0 deletions packages/create-graphql-core/src/graphqlrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"paths": {
"directories": {
"source": "src",
"connection": "connection",
"loader": "loader",
"model": "model",
"mutation": "mutation",
"mutation_test": "mutation/__tests__",
"type": "type",
"type_test": "type/__tests__",
"interface": "interface"
},
"files": {
"schema": "schema"
}
}
}
Loading