當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript graphql-yoga.GraphQLServer類代碼示例

本文整理匯總了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;未經允許,請勿轉載。