enables User and Upload graphql CRUD

This commit is contained in:
James
2020-04-12 15:54:21 -04:00
parent cfffe52e88
commit 94fd642e5c
10 changed files with 231 additions and 25 deletions

View File

@@ -7,11 +7,15 @@ const buildBlockType = require('./schema/buildBlockType');
const buildLocaleInputType = require('./schema/buildLocaleInputType');
const buildFallbackLocaleInputType = require('./schema/buildFallbackLocaleInputType');
const registerCollections = require('../collections/graphql/register');
const registerUser = require('../auth/graphql/register');
const registerUpload = require('../uploads/graphql/register');
const buildWhereInputType = require('./schema/buildWhereInputType');
class GraphQL {
constructor(config, collections) {
constructor(config, collections, User, Upload) {
this.config = config;
this.User = User;
this.Upload = Upload;
this.collections = collections;
this.init = this.init.bind(this);
@@ -30,10 +34,14 @@ class GraphQL {
this.buildWhereInputType = buildWhereInputType;
this.buildObjectType = buildObjectType.bind(this);
this.registerCollections = registerCollections.bind(this);
this.registerUser = registerUser.bind(this);
this.registerUpload = registerUpload.bind(this);
}
init() {
this.registerCollections();
this.registerUser();
this.registerUpload();
const query = new GraphQLObjectType(this.Query);
const mutation = new GraphQLObjectType(this.Mutation);

View File

@@ -17,7 +17,7 @@ const combineParentName = require('../utilities/combineParentName');
const withNullableType = require('./withNullableType');
const find = require('../../collections/queries/find');
function buildObjectType(name, fields, parentName, addID) {
function buildObjectType(name, fields, parentName, baseFields = {}) {
const fieldToSchemaMap = {
number: field => ({ type: withNullableType(field, GraphQLFloat) }),
text: field => ({ type: withNullableType(field, GraphQLString) }),
@@ -241,9 +241,6 @@ function buildObjectType(name, fields, parentName, addID) {
},
};
const baseFields = {};
if (addID) baseFields.id = { type: GraphQLString };
const objectSchema = {
name,
fields: () => fields.reduce((schema, field) => {