-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathgraphQLType.js
40 lines (40 loc) · 1.76 KB
/
graphQLType.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"use strict";
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
exports.__esModule = true;
var _a = require('graphql'), GraphQLInputObjectType = _a.GraphQLInputObjectType, GraphQLObjectType = _a.GraphQLObjectType;
var attributeFields = require('graphql-sequelize').attributeFields;
var fields_1 = __importDefault(require("../associations/fields"));
/**
* Returns a new `GraphQLObjectType` created from a sequelize model.
*
* It creates a `GraphQLObjectType` object with a name and fields. The
* fields are generated from its sequelize associations.
* @param {*} model The sequelize model used to create the `GraphQLObjectType`
* @param {*} types Existing `GraphQLObjectType` types, created from all the Sequelize models
*/
function generateGraphQLType(model, types, isInput) {
if (isInput === void 0) { isInput = false; }
var GraphQLClass = isInput ? GraphQLInputObjectType : GraphQLObjectType;
var type = new GraphQLClass({
name: isInput ? "".concat(model.name, "Input") : model.name,
fields: function () { return (__assign(__assign({}, attributeFields(model, {
allowNull: !!isInput,
commentToDescription: true
})), (isInput ? (0, fields_1["default"])(model.associations, types) : {}))); }
});
return type;
}
exports["default"] = generateGraphQLType;