我正在使用Typescript开发一个带有graphql和express的后端API。我正在使用webpack来管理项目开发和构建过程。
我使用raw-loader从文件中将graphql架构和sql查询作为字符串加载。
目前我正面临一些我不太了解的问题。
webpack.config.js
CONTENT_TYPE
server.ts
const path = require('path');
module.exports = {
target: 'node',
entry: {
server: path.resolve(__dirname, 'server.ts'),
},
output: {
filename: 'server.js',
path: path.resolve(__dirname, 'dist'),
},
devtool: 'source-map',
module: {
rules: [
{
test: /\.(gql|sql)$/,
loader: 'raw-loader',
},
{
test: /\.ts$/,
loader: 'ts-loader',
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
watch: {
ignored: /node_modues/,
},
};
错误:
import express from 'express';
import morgan from 'morgan';
import bodyParser from 'body-parser';
import graphqlHTTP from 'express-graphql';
import { affairSchema } from './src/schemas';
import affairRoot from './src/resolvers/affairs';
const app = express();
app.use(morgan('combined'));
app.use(bodyParser.json());
app.use(
'/graphql',
graphqlHTTP({
schema: affairSchema,
rootValue: affairRoot,
graphiql: true,
})
);
const port = process.env.PORT || 4000;
app.listen(port, () => console.log('Server waiting on ', port));
答案 0 :(得分:1)
您可以使用webpack-node-externals
来阻止捆绑节点模块。这可以消除这些错误,但在运行应用程序时当然也需要function MYMODULE_my_custom_submit_handler($form, &$form_state) {
$nid = $form_state['values']['nid'];
$node = node_load($nid);
// to debug:
// var_dump($form_state['values'], $node);die;
// check diff
$to_publish = false ;
if ($node->title != $form_state['values']['title']) $to_publish = true;
if ($node->body['und'][0]['value'] != $form_state['values']['body']['und'][0]['value']) $to_publish = true ;
// and so on...
if ($to_publish) {
// force the status to 1.
$form_state['values']['status'] = 1;
}
}
。