當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。