本文整理汇总了TypeScript中graphql-server-express.graphiqlExpress函数的典型用法代码示例。如果您正苦于以下问题:TypeScript graphiqlExpress函数的具体用法?TypeScript graphiqlExpress怎么用?TypeScript graphiqlExpress使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了graphiqlExpress函数的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);
});
}
示例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}`)
})
}
示例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 */
示例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',
});
})
示例5: GraphiQL
export function GraphiQL() {
return graphiqlExpress({
endpointURL: '/graphql'
});
}
示例6: 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);
});
示例7: is
import { graphiqlExpress } from 'graphql-server-express';
import * as url from 'url';
import { GRAPHQL_ROUTE } from '../ENDPOINTS';
import * as express from 'express';
import { SETTINGS } from '../config';
import { logger } from '@sample-stack/utils';
const subscriptionUrl = (SETTINGS.GRAPHQL_URL).replace(/^http/, 'ws');
logger.debug('subscriptionUrl used is (%s)', subscriptionUrl);
export const graphiqlExpressMiddleware =
graphiqlExpress({
endpointURL: GRAPHQL_ROUTE,
subscriptionsEndpoint: subscriptionUrl,
query:
'{\n' +
' count {\n' +
' amount\n' +
' }\n' +
'}',
});