本文整理汇总了TypeScript中express-graphql.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: require
const express = require("express")
const graphqlHTTP = require("express-graphql")
import { buildSchema } from "graphql"
const schema = buildSchema(`
type Query {
hello: String
}
`)
const root = {
hello: () => "Hello world!",
}
const app = express()
export default app
app.use(
"/graphql",
graphqlHTTP({
graphiql: true,
rootValue: root,
schema,
})
)
export function start(): any {
// tslint:disable:no-console
app.listen(4000, () => console.log("Now browse to localhost:4000/graphql"))
}
示例2: startPublications
export function startPublications() {
const mode = process.env.NODE_ENV || "DEVELOPMENT";
const app = express();
if (mode.toUpperCase() === "DEVELOPMENT") {
const compiler = webpack(webpackConfig as webpack.Configuration);
app.use(
webpackDevMiddleware(compiler, {
publicPath: webpackConfig.output.publicPath,
})
);
app.use(webpackHotMiddleware(compiler));
app.use("/playground", graphqlPlayground({ endpoint: "/graphql" }));
} else {
const publicPath = path.resolve(__dirname, "../public");
app.use(express.static(publicPath));
app.get("*", (req, res) =>
res.sendFile(path.resolve(publicPath, "index.html"))
);
}
app.use(jwt(jwtConfig));
app.use(
"/graphql",
graphqlHttp(request => ({
schema,
context: { user: request.user },
}))
);
app.use(onAuthError);
app.get("/documents/:id/pdf", documentPdfHandler);
app.listen(PORT, () => {
console.log(`Publications started on port ${PORT}.`);
});
}
示例3: function
module.exports = function (app) {
let schema = buildSchema(`
type Query {
hello: String
}
`);
let root = { hello: () => 'Hello world!' };
app.use('/hello', graphqlHTTP({
schema: HelloService.schema,
rootValue: HelloService.rootValue,
graphiql: true,
}));
};
示例4: graphqlHTTP
(async () => {
try {
db = await MongoClient.connect(process.env.MONGO_URL);
app.use('/graphql', graphqlHTTP({
schema,
graphiql: true,
pretty: true,
context: {
db
}
}));
app.get('*', function (req: express.Request, res: express.Response) {
res.sendFile(__dirname + '/public/index.html');
});
app.listen(3000, () => console.log('Listening on port 3000'));
// generate schema.json
let result: GraphQLResult = await graphql(schema, graphqlUtils.introspectionQuery);
if (result.errors) {
console.error(
'ERROR introspecting schema: ', result
);
} else {
fs.writeFile('./data/schema.json', JSON.stringify(result, null, 2), err => {
if (err) {
throw err;
}
console.log('JSON Schema created');
});
}
} catch (error) {
console.log(error);
}
})();
示例5: require
/// <reference path="./express-graphql.d.ts" />
/// <reference path="../express/express.d.ts" />
var express = require("express");
var graphqlHTTP = require("express-graphql");
var app = express();
var schema = {};
app.use("/graphql", graphqlHTTP({ schema: schema, graphiql: true }));
示例6: require
import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from 'graphql';
const pack = require('../package.json');
export const EmptySchema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
description: 'Root query',
fields: {
version: {
type: new GraphQLNonNull(GraphQLString),
resolve: () => pack.version
}
}
})
});
const app = require('express')();
const graphqlHTTP = require('express-graphql');
app.use('/graphql', graphqlHTTP({
schema: EmptySchema,
graphiql: true
}));
app.listen(4000);