本文整理汇总了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);
});
}
示例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: 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);
}
});
示例6: GraphQL
export function GraphQL() {
return graphqlExpress({
schema: executableSchema
});
}
示例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);
});