Skip to content

Instantly share code, notes, and snippets.

@emanuelet
Created March 4, 2021 08:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emanuelet/fe4ca539977b900f5f55a7088cebf594 to your computer and use it in GitHub Desktop.
Save emanuelet/fe4ca539977b900f5f55a7088cebf594 to your computer and use it in GitHub Desktop.
Jit bug reproduction
'use strict'
const environment = process.env.NODE_ENV || 'development'
const isProd = environment.includes('production')
const config = require('config')
const path = require('path')
const AutoLoad = require('fastify-autoload')
const mercurius = require('mercurius')
const gqSchema = require('./graphql/schema')
const fastify = require('fastify')({
logger: !isProd ? logger.log : false,
})
fastify
.register(mercurius, {
schema: gqSchema,
graphiql: 'playground',
jit: 1
})
const start = async () => {
try {
let address = await fastify.listen(
process.env.PORT || config.port,
'0.0.0.0'
)
logger.info(
`server listening on ${address}. Login page at ${address}/login. GraphQl Playground ${address}/playground. ${
!isProd ? `Docs at ${address}/documentation` : ''
}`
)
} catch (err) {
logger.error(err)
process.exit(1)
}
}
if (process) {
process.on('SIGINT', async () => {
logger.log('stopping fastify server')
await fastify.close()
process.exit(0)
})
process.once('SIGUSR2', async () => {
logger.log('stopping fastify server SIGUSR2')
await fastify.close()
process.exit(0)
})
process.once('SIGHUP', async () => {
logger.log('stopping fastify server SIGHUP')
await fastify.close()
process.exit(0)
})
}
start()
module.exports = fastify
'use strict'
const { Model } = require('sequelize')
module.exports = (sequelize, DataTypes) => {
class provider extends Model {
/**
* Helper method for defining associations.
* This method is not a part of Sequelize lifecycle.
* The `models/index` file will call this method automatically.
*/
static associate(models) {
// define association here
provider.belongsTo(models.vendors, {
foreignKey: 'vendor_id',
})
}
}
provider.init(
{
id: {
allowNull: false,
primaryKey: true,
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV4,
},
name: DataTypes.STRING,
vendor_id: DataTypes.UUID,
meta: DataTypes.JSONB,
},
{
sequelize,
modelName: 'provider',
}
)
return provider
}
const options = {
authorizer: function authorizer(source, args, context, info) {
const { fieldName } = info
const { isAuthenticated } = context
if (!isAuthenticated)
return Promise.reject(
`The resource ${fieldName} require proper authentication`
)
return Promise.resolve()
},
}
const { GraphQLSchema } = require('graphql'),
{ generateSchema } = require('sequelize-graphql-schema')(options),
models = require('../db/models'),
{ makeExecutableSchema } = require('@graphql-tools/schema'),
{ stitchSchemas } = require('@graphql-tools/stitch')
const dbSchema = new GraphQLSchema(generateSchema(models))
module.exports = stitchSchemas({
mergeTypes: true,
subschemas: [dbSchema],
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment