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


TypeScript express-graphql.default函數代碼示例

本文整理匯總了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"))
}
開發者ID:pact-foundation,項目名稱:pact-js,代碼行數:30,代碼來源:provider.ts

示例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}.`);
  });
}
開發者ID:carlospaelinck,項目名稱:publications-js,代碼行數:35,代碼來源:index.ts

示例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,
  }));
};
開發者ID:toannvbk93,項目名稱:goemon,代碼行數:15,代碼來源:hello.ts

示例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);
  }

})();
開發者ID:pjayala,項目名稱:labseed,代碼行數:36,代碼來源:server.ts

示例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 }));
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:10,代碼來源:express-graphql-tests.ts

示例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);
開發者ID:2fd,項目名稱:graphdoc,代碼行數:24,代碼來源:empty.ts


注:本文中的express-graphql.default函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。