本文整理汇总了TypeScript中graphql-yoga.GraphQLServer类的典型用法代码示例。如果您正苦于以下问题:TypeScript GraphQLServer类的具体用法?TypeScript GraphQLServer怎么用?TypeScript GraphQLServer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了GraphQLServer类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。
示例1: PubSub
import { GraphQLServer, PubSub } from 'graphql-yoga';
import { formatError } from 'apollo-errors';
import * as jwt from 'express-jwt';
import * as faker from 'faker/locale/en';
import * as compression from 'compression';
import resolvers from './resolvers';
const { JWT_SECRET } = process.env;
const pubsub = new PubSub();
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
jwtSecret: JWT_SECRET,
faker,
pubsub
})
});
server.express.disable('x-powered-by');
server.express.use(
'/graphql',
jwt({
secret: JWT_SECRET,
credentialsRequired: false
})
);
开发者ID:ruisaraiva19,项目名称:fakerql,代码行数:31,代码来源:index.ts
示例2: GraphQLServer
import { GraphQLServer } from 'graphql-yoga'
import { prisma } from './generated/prisma-client'
import { resolvers } from './resolvers'
const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: {
prisma,
},
} as any)
server.start(() => console.log('Server is running on http://localhost:4000'))
开发者ID:markthink,项目名称:prisma-examples,代码行数:13,代码来源:index.ts
示例3: GraphQLServer
import { GraphQLServer } from "graphql-yoga";
import { default as typeDefs } from './typeDefs'
import { default as resolvers } from './resolvers'
const options = { port: 4004 };
const server = new GraphQLServer({
typeDefs,
resolvers
});
server.start(options, () =>
console.log(`Server is running ⚡ on localhost:${options.port}`))
.catch(err => console.error('connection Error', err));
开发者ID:slimui,项目名称:graphql-yoga,代码行数:14,代码来源:index.ts
示例4: Stripe
formatError,
};
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);
export const db = new Prisma({
endpoint: process.env.PRISMA_ENDPOINT, // the endpoint of the Prisma DB service (value is set in .env)
secret: process.env.PRISMA_SECRET, // taken from database/prisma.yml (value is set in .env)
debug: true, // log all GraphQL queries & mutations
});
export const server = new GraphQLServer({
typeDefs: './src/schema.graphql',
resolvers,
context: req => ({
...req,
db,
mailer,
stripe,
}),
});
server.start(options, () => console.log(`Server is running on http://localhost:4000`));
const rawBodyParser = require('body-parser').raw({ type: '*/*' });
server.express.post('/stripe', rawBodyParser, async (req, res, next) => {
let data;
// Check if webhook signing is configured.
if (process.env.STRIPE_WEBHOOK_SECRET) {
// Retrieve the event by verifying the signature using the raw body and secret.
let event;
开发者ID:Coder108,项目名称:prisma-ecommerce,代码行数:32,代码来源:index.ts
示例5: async
export const startServer = async () => {
const server = new GraphQLServer({
schema : genSchema(),
context: ({ request }) => ({
redis,
url: `${request.protocol}://${request.get("host")}`,
session: request.session // req now has a session to it
})
});
// add express-server middleware
server.express.use(
session({
store: new RedisStore({
client: redis as any
}),
name: "qid",
secret: process.env.SESSION_SECRET as string,
resave: false,
saveUninitialized: false,
cookie: {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
maxAge: 1000 * 60 * 60 * 24 * 7 // 7 days
}
})
);
// server.express.use(
// // session options
// session({
// store: new RedisStore({
// client: redis as any
// }),
// name: "qid",
// secret: 'secret',
// resave: false,
// saveUninitialized: false, // dont store cookie unless data on user needs to be added
// cookie: { // cookie settings
// httpOnly: true, // JS cannot access cookie --> security
// secure: process.env.NODE_ENV === "production",
// maxAge: 1000 * 60 * 60 * 24 * 7 // 7 days
// }
// })
// );
// send a cookie back
const cors = {
credentials: true,
origin: process.env.NODE_ENV === "test"
? '*'
: process.env.FRONTEND_HOST as string // front end server host
}
// REST endpoint for email confirmation link
// Once user clicks on confirmation link
server.express.get("/confirm/:id", confirmEmail);
await createTypeormConn();
const app = await server.start({
cors,
port: process.env.NODE_ENV === 'test' ? 0 : 4000
});
console.log('Server is running on localhost:4000');
return app;
}
开发者ID:itaygolan,项目名称:GraphQL-Typescript-Server,代码行数:67,代码来源:startServer.ts
示例6: GraphQLServer
import { GraphQLServer } from 'graphql-yoga';
const typeDefs = `
type Query {
greet: String
}
`
const resolvers = {
Query: {
greet: () => 'hello world'
}
}
const server = new GraphQLServer({typeDefs, resolvers})
server.start(() => console.log('⚡️ Waiting to greet you at http://localhost:4000'))
开发者ID:Arya04,项目名称:hello-world,代码行数:16,代码来源:hello-world-graphql.ts
注:本文中的graphql-yoga.GraphQLServer类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论