Skip to content

Commit

Permalink
feat(server): Allow to customize the gsg call.
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentdesmares committed Jan 3, 2020
1 parent 2d24fc6 commit f91afd9
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
29 changes: 20 additions & 9 deletions lib/graphql/getApolloServer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
"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 };
};
Expand All @@ -8,20 +19,22 @@ var models_1 = __importDefault(require("../models"));
var job_1 = __importDefault(require("./job"));
var batch_1 = __importDefault(require("./batch"));
var pipeline_1 = __importDefault(require("./pipeline"));
function getApolloServer(dbConfig) {
/**
* @param dbConfig Sequelize database configuration object
* @param gsgParams Params from graphql-sequelize-generator that overwrite the default ones.
*/
function getApolloServer(dbConfig, gsgParams) {
if (gsgParams === void 0) { gsgParams = {}; }
var models = models_1["default"](dbConfig);
var types = graphql_sequelize_generator_1.generateModelTypes(models);
var graphqlSchemaDeclaration = {
job: job_1["default"](types, models),
batch: batch_1["default"](types, models),
pipeline: pipeline_1["default"](types, models)
};
return graphql_sequelize_generator_1.generateApolloServer({
graphqlSchemaDeclaration: graphqlSchemaDeclaration,
return graphql_sequelize_generator_1.generateApolloServer(__assign({ graphqlSchemaDeclaration: graphqlSchemaDeclaration,
types: types,
models: models,
globalPreCallback: function () { },
apolloServerOptions: {
models: models, globalPreCallback: function () { }, apolloServerOptions: {
playground: true,
//context: addDataloaderContext,
// extensions: [
Expand All @@ -30,8 +43,6 @@ function getApolloServer(dbConfig) {
// ],
// Be sure to enable tracing
tracing: false
},
customMutations: {}
});
}, customMutations: {} }, gsgParams));
}
exports["default"] = getApolloServer;
9 changes: 7 additions & 2 deletions src/graphql/getApolloServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import job from './job'
import batch from './batch'
import pipeline from './pipeline'

export default function getApolloServer(dbConfig: any) {
/**
* @param dbConfig Sequelize database configuration object
* @param gsgParams Params from graphql-sequelize-generator that overwrite the default ones.
*/
export default function getApolloServer(dbConfig: any, gsgParams: any = {}) {
const models = getModels(dbConfig)

const types = generateModelTypes(models)
Expand All @@ -34,6 +38,7 @@ export default function getApolloServer(dbConfig: any) {
// Be sure to enable tracing
tracing: false
},
customMutations: {}
customMutations: {},
...gsgParams
})
}
5 changes: 4 additions & 1 deletion tests/server.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { getApolloServer } = require('./../lib/index')
const express = require('express')
const http = require('spdy')
const { PubSub } = require('graphql-subscriptions')
const config = require('./sqliteTestConfig.js')
const app = express()

Expand All @@ -10,7 +11,9 @@ var options = {
}
}

const server = getApolloServer(config)
const pubSubInstance = new PubSub()

const server = getApolloServer(config, { pubSubInstance })

/**
* This is the test server.
Expand Down

0 comments on commit f91afd9

Please sign in to comment.