当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript graphql-server-express.graphqlExpress函数代码示例

本文整理汇总了TypeScript中graphql-server-express.graphqlExpress函数的典型用法代码示例。如果您正苦于以下问题:TypeScript graphqlExpress函数的具体用法?TypeScript graphqlExpress怎么用?TypeScript graphqlExpress使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了graphqlExpress函数的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: main

async function main() {
  const app = express();
  app.use(cors());

  await initAccounts();

  app.use(session({
    secret: 'grant',
    resave: true,
    saveUninitialized: true,
  }));

  app.use(bodyParser.urlencoded({ extended: true }));

  const grant = new Grant(grantConfig);

  app.use(GRANT_PATH, grant);

  app.get(`${GRANT_PATH}/handle_facebook_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=facebook&access_token=${accessToken}`);
  });

  app.get(`${GRANT_PATH}/handle_google_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`);
  });

  initializeOAuthResolver();

  const schema = createSchemeWithAccounts(AccountsServer);

  app.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
    schema,
    context: JSAccountsContext(request),
    debug: true,
  })));

  app.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
  }));

  const server = createServer(app);

  new SubscriptionServer(
    {
      schema,
      execute,
      subscribe,
    },
    {
      path: WS_GQL_PATH,
      server,
    }
  );

  server.listen(PORT, () => {
    console.log('Mock server running on: ' + PORT);
  });
}
开发者ID:RocketChat,项目名称:Rocket.Chat.PWA,代码行数:60,代码来源:index.ts

示例2: startExpress

export function startExpress(graphqlOptions) {
  app.use(bodyParser.json())
  app.use('/graphql', apollo.graphqlExpress(graphqlOptions))
  app.use('/', apollo.graphiqlExpress({endpointURL: '/graphql'}))

  app.listen(expressPort, () => {
      console.log(`Express server is listen on ${expressPort}`)
  })
}
开发者ID:nnance,项目名称:swapi-apollo,代码行数:9,代码来源:express.ts

示例3: createTestData

(async () => {
  const mongoClient = await mongodb.MongoClient.connect(
    'mongodb://127.0.0.1:27017/tyranid_gracl_test',
    { useNewUrlParser: true }
  );

  Tyr.config({
    mongoClient,
    db: mongoClient.db(),
    validate: [
      {
        dir: __dirname,
        fileMatch: 'models.js'
      }
    ]
  });

  await createTestData();

  const GRAPHQL_PORT = 8080;

  const graphQLServer = express();

  graphQLServer.use(
    '/graphql',
    bodyParser.json(),
    graphqlExpress({
      schema: createGraphQLSchema(Tyr)
    })
  );

  graphQLServer.use(
    '/graphiql',
    graphiqlExpress({
      endpointURL: '/graphql'
    })
  );

  /* tslint:disable no-console */
  graphQLServer.listen(GRAPHQL_PORT, () =>
    console.log(
      `GraphQL Server is now running on http://localhost:${GRAPHQL_PORT}/graphiql`
    )
  );
})().catch(err => console.log(err.stack)); /* tslint:enable no-console */
开发者ID:tyranid-org,项目名称:tyranid,代码行数:45,代码来源:server.ts

示例4: graphqlExpress

 .then(() =>{
   // Load all route
   // Server Endpoints
   //this.app.use( new ServerRoutes().routes());
   this.app.get( '/', (req, res) => {
     res.json({
       code: 200,
       message: `${PACKAGE.name} - v.${PACKAGE.version} / ${PACKAGE.description} by ${PACKAGE.author}`
     });
   });
   //GraphQL API Endpoints
   this.app
     // .use(
     //   '/graphql',
     //   expressGraphQL( () => {
     //     return {
     //       graphiql: true,
     //       schema: schemas //GraphQLSchema,
     //     }
     //   })
     // )
     .use('/graphql', graphqlExpress(req=> ({
       schema:schemas,
       context: req
     })))
     .use('/graphiql', graphiqlExpress({
       endpointURL: '/graphql',
       subscriptionsEndpoint: `ws://localhost:8080/subscriptions`,
     }));
     // Real Time SubscriptionServer
     const subscriptionServer = new SubscriptionServer(
       {
         schema: schemas,
         execute,
         subscribe,
       }, {
         server: this.server,
         path: '/subscriptions',
       });
 })
开发者ID:FazioNico,项目名称:nodejs-simple-graphql-ts,代码行数:40,代码来源:index.ts

示例5: graphqlExpress

import { database } from '@sample-stack/graphql-schema';
import { ICounterRepository, TYPES as CounterTypes } from '@sample-stack/store';

const { persons, findPerson, addPerson } = database;
let debug: boolean = false;
if (process.env.LOG_LEVEL && process.env.LOG_LEVEL === 'trace' || process.env.LOG_LEVEL === 'debug' ) {
    debug = true;
}
export const graphqlExpressMiddleware =
    graphqlExpress((request: express.Request, response: express.Response) => {
        try {
            const graphqlOptions: GraphQLOptions = {
                debug,
                schema,
                context: {
                    persons,
                    findPerson,
                    addPerson,
                    Count: counterRepo,
                },
                formatError: error => {
                    logger.error('GraphQL execution error:', error);
                    return error;
                },
            };
            return graphqlOptions;
        } catch (e) {
            logger.error(e.stack);
        }
    });
开发者ID:baotaizhang,项目名称:fullstack-pro,代码行数:30,代码来源:graphql.ts

示例6: GraphQL

export function GraphQL() {
  return graphqlExpress({
    schema: executableSchema
  });
}
开发者ID:kamilkisiela,项目名称:universal-starter-apollo,代码行数:5,代码来源:graphql.ts

示例7: function

app.use(bodyParser.json());

// Serve client
app.use(express.static(__dirname + '/../../../dist'));
app.use(express.static(__dirname + '/../../../'));
app.get('/', function (req, res) {
  res.sendFile(__dirname + '../../../dist/index.html');
});

app.use(bodyParser.urlencoded({
  extended : true
}));


const myGraphQLSchema = makeExecutableSchema({typeDefs : scheme,
  resolvers : Object.assign(resolverMap, trackResolver)});
app.use('/graphql', bodyParser.json(), graphqlExpress({
  schema : myGraphQLSchema,
  debug : true
} as any));
app.use('/graphiql', graphiqlExpress({
  endpointURL : '/graphql',
}));

httpServer.listen(PORT, () => {

  const simulative = new Simulative(io);
  simulative.startSendingSimulativeData();
  console.log('server started on: ' + PORT);
});
开发者ID:CHBaker,项目名称:angular-cesium,代码行数:30,代码来源:main.ts


注:本文中的graphql-server-express.graphqlExpress函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。