本文整理匯總了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);