Best JavaScript code snippet using argos
index.ts
Source:index.ts
1import { IApiStartup } from "../interfaces/IApiStartup";2import { ApiConfig } from "./api-config";3import { ApolloServer, makeExecutableSchema } from "apollo-server-express";4import * as express from "express";5import {6 typeDefs as exampleTypeDefs,7 resolvers as exampleResolvers8} from "../common/default-types";9import "reflect-metadata";10import {11 resolverConvention,12 setGlobOptions,13 getRootDir14} from "./resolver-convention";15import { ClassOf } from "../common/class-of";16import * as path from "path";17import { useContainer } from "type-graphql";18import { Container } from "typedi";19import { MessageBusToken, ApiConfigurationToken } from "../tokens";20import { MessageBus } from "../message-bus";21import { topMostModule } from "../common/top-most-module";22import { IContext } from "../interfaces/IContext";23export type AxonishApiReturnType = (constructor: ClassOf<IApiStartup>) => void;24export type AxonishApolloServer = ApolloServer & { express: express.Express };25useContainer(Container);26/**27 * HACK!! Just for awaiting in Unit tests.28 */29let _initilizingApiPromise: Promise<void> = Promise.resolve();30export async function __AxonishApiAwaitForUnitTest() {31 await _initilizingApiPromise;32}33export function AxonishApi(): AxonishApiReturnType {34 return (constructor: ClassOf<IApiStartup>) => {35 const ApiStartupClass = constructor;36 const instance = new ApiStartupClass();37 _initilizingApiPromise = (async () => {38 const config = new ApiConfig();39 config.services.set(MessageBusToken, new MessageBus());40 config.services.set(ApiConfigurationToken, config);41 const requiring_module =42 getRootDir() || path.dirname(topMostModule(module)!.filename);43 setGlobOptions({44 cwd: requiring_module,45 ignore: ["**/**/*.d.ts", "**/**/*.map", "**/node_modules/", "**/dist/"]46 });47 config.addConvention(resolverConvention);48 const configResult = instance.config(config);49 if (configResult && configResult.then) {50 await configResult;51 }52 for (const convention of config.conventions) {53 const conventionResult = convention(config);54 if (conventionResult && conventionResult.then) {55 await conventionResult;56 }57 }58 const server = new ApolloServer({59 schema:60 config.schema ||61 makeExecutableSchema({62 typeDefs: exampleTypeDefs,63 resolvers: exampleResolvers64 }),65 context: ({ req }: { req: any }) => {66 const ctx: IContext = {67 req,68 config69 };70 return ctx;71 }72 });73 const app = express();74 (server as AxonishApolloServer).express = app;75 const apolloServer: AxonishApolloServer = server as AxonishApolloServer;76 apolloServer.applyMiddleware({ app, path: "/graphql" });77 const oldStop = apolloServer.stop;78 const startingResult = instance.starting(apolloServer);79 if (startingResult && startingResult.then) {80 await startingResult;81 }82 const { port } = config;83 await new Promise(function(resolve) {84 const expressServer = app.listen({ port }, () => {85 apolloServer.stop = () => {86 return new Promise(async function(resolve) {87 await oldStop.apply(apolloServer);88 expressServer.close(resolve);89 });90 };91 resolve();92 });93 });94 const startedResult = instance.started(apolloServer, {95 address: "localhost",96 port97 });98 if (startedResult && startedResult.then) {99 await startedResult;100 }101 })();102 };...
startApolloServer.ts
Source:startApolloServer.ts
1import { ApolloServerPluginDrainHttpServer } from 'apollo-server-core';2import { ApolloServer } from 'apollo-server-express';3import express from 'express';4import { execute, subscribe } from 'graphql';5import { createServer } from 'http';6import { SubscriptionServer } from 'subscriptions-transport-ws';7import logger from '../logger';8import { MetaplexDataSource } from '../reader';9import { Context } from '../types/context';10import { context, schema } from './graphqlConfig';11import expressPlayground from 'graphql-playground-middleware-express';12export async function getServer(13 dataSources: MetaplexDataSource<Context>,14 introspection = false,15) {16 const app = express();17 const httpServer = createServer(app);18 const apolloServer = new ApolloServer({19 schema,20 context,21 dataSources: () => ({ dataSources }),22 introspection,23 plugins: [24 ApolloServerPluginDrainHttpServer({ httpServer }),25 {26 async serverWillStart() {27 return {28 async drainServer() {29 subscriptionServer.close();30 },31 };32 },33 },34 ],35 });36 if (introspection) {37 app.get(38 '/',39 expressPlayground({40 endpoint: apolloServer.graphqlPath,41 subscriptionEndpoint: apolloServer.graphqlPath,42 }),43 );44 }45 const subscriptionServer = SubscriptionServer.create(46 {47 schema,48 execute,49 subscribe,50 onConnect(context: Context) {51 dataSources.initContext(context);52 return context;53 },54 },55 { server: httpServer, path: apolloServer.graphqlPath },56 );57 await apolloServer.start();58 apolloServer.applyMiddleware({59 app,60 path: apolloServer.graphqlPath,61 });62 return { app, httpServer: httpServer, apolloServer };63}64export async function startApolloServer(65 api: MetaplexDataSource<Context>,66 port = process.env.PORT || 4000,67 introspection = !!process.env.INTROSPECTION,68) {69 const { httpServer, apolloServer } = await getServer(api, introspection);70 await new Promise(resolve =>71 httpServer.listen({ port: port }, resolve as any),72 );73 const URL_GRAPHQL = `http://localhost:${port}${apolloServer.graphqlPath}`;74 const URL_GRAPHQL_WS = `ws://localhost:${port}${apolloServer.graphqlPath}`;75 logger.info(`ð Server ready at ${URL_GRAPHQL}`);76 logger.info(`ð Subscription ready at ${URL_GRAPHQL_WS}`);...
Using AI Code Generation
1const { ApolloServer } = require('apollo-server');2const typeDefs = require('./schema');3const resolvers = require('./resolvers');4const server = new ApolloServer({ typeDefs, resolvers });5server.listen().then(({ url }) => {6 console.log(`🚀 Server ready at ${url}`);7});8const { gql } = require('apollo-server');9 type Query {10 }11 type Mutation {12 post(url: String!, description: String!): Link!13 }14 type Link {15 }16`;17module.exports = typeDefs;18const resolvers = {19 Query: {20 info: () => `This is the API of a Hackernews Clone`,21 feed: () => links,22 },23 Mutation: {24 post: (parent, args) => {25 const link = {26 id: `link-${idCount++}`,27 }28 links.push(link)29 },30 },31};32module.exports = resolvers;33{34 "scripts": {35 },36 "dependencies": {37 }38}39const { ApolloServer } = require('apollo-server');40const typeDefs = require('./schema');41const resolvers = require('./resolvers');42const server = new ApolloServer({ typeDefs, resolvers });43server.listen().then(({ url }) => {44 console.log(`🚀 Server ready at ${url}`);45});46const { gql } = require('apollo-server');
Using AI Code Generation
1const { ApolloServer, gql } = require('apollo-server')2 type Query {3 }4const resolvers = {5 Query: {6 hello: () => 'Hello world!'7 }8}9const server = new ApolloServer({ typeDefs, resolvers })10server.listen().then(({ url }) => {11 console.log(`🚀 Server ready at ${url}`)12})
Using AI Code Generation
1const { ApolloServer } = require('apollo-server');2 type Query {3 }4`;5const resolvers = {6 Query: {7 hello: () => 'Hello world!'8 }9};10const server = new ApolloServer({ typeDefs, resolvers });11server.listen().then(({ url }) => {12 console.log('🚀 Server ready at ${url}');13});14const { ApolloServer } = require('apollo-server');15 type Query {16 }17`;18const resolvers = {19 Query: {20 hello: () => 'Hello world!'21 }22};23const server = new ApolloServer({ typeDefs, resolvers });24server.listen().then(({ url }) => {25 console.log('🚀 Server ready at ${url}');26});27const { ApolloServer } = require('apollo-server');28 type Query {29 }30`;31const resolvers = {32 Query: {33 hello: () => 'Hello world!'34 }35};36const server = new ApolloServer({ typeDefs, resolvers });37server.listen().then(({ url }) => {38 console.log('🚀 Server ready at ${url}');39});40const { ApolloServer } = require('apollo-server');41 type Query {42 }43`;44const resolvers = {45 Query: {46 hello: () => 'Hello world!'47 }48};49const server = new ApolloServer({ typeDefs, resolvers });50server.listen().then(({ url }) => {51 console.log('🚀 Server ready at ${url}');52});53const { ApolloServer } = require('apollo-server');54 type Query {55 }56`;57const resolvers = {58 Query: {59 hello: () => 'Hello world!'60 }61};62const server = new ApolloServer({ typeDefs, resolvers });63server.listen().then(({ url }) => {64 console.log('🚀 Server ready at
Using AI Code Generation
1const { ApolloServer } = require('apollo-server');;2 type Query {3 }4 resolvers = {5 hello: () => 'Hello world!',6 },7};8const server = newApolloServer({ typeDefs, resolvers });9server.listen().then(({ url }) => {10 console.log(`🚀 Server ready at ${url}`);11});
Using AI Code Generation
1const { ApolloServer, gql } = require('apollo-server');2const { 3 type Query {4 }5`;6const resolvers = {7 Query: {8 hello: () => 'Hello world!'9 }10};11const server = new ApolloServer({ typeDefs, resolvers });12server.listen().then(({ url }) => {13 console.log('🚀 Server ready at ${url}');14});15const { ApolloServer } = require('apollo-server');16 type Query {17 }18`;19const resolvers = {20 Query: {21 hello: () => 'Hello world!'22 }23};24const server = new ApolloServer({ typeDefs, resolvers });25server.listen().then(({ url }) => {26 console.log('🚀 Server ready at ${url}');27});28const { ApolloServer } = require('apollo-server');29 type Query {30 }31`;32const resolvers = {33 Query: {34 hello: () => 'Hello world!'35 }36};37const server = new ApolloServer({ typeDefs, resolvers });38server.listen().then(({ url }) => {39 console.log('🚀 Server ready at ${url}');40});
Using AI Code Generation
1const { ApolloServer } = require('apollo-server');2const { typeDefs } = require('./schema');3const { resolvers } = require('./resolvers');4const { createStore } = require('./utils');5const isEmail = require('isemail');6const server = new ApolloServer({7 context: async ({ req }) => {8 const auth = (req.headers && req.headers.authorization) || '';9 const email = Buffer.from(auth, 'base64').toString('ascii');10 if (!isEmail.validate(email)) return { user: null };11 const users = await store.users.findOrCreate({ where: { email } });12 const user = users && users[0] ? users[0] : null;13 return { user: { ...user.dataValues } };14 },15 });16 server.listen().then(({ url }) => {17 console.log(o🚀 Server ready at ${url}n);18 });st { ApolloServer } = require('apollo-server');19 type Query {20 }21`;22const resolvers = {23 Query: {24 hello: () => 'Hello world!'25 }26};27const server = new ApolloServer({ typeDefs, resolvers });28server.listen().then(({ url }) => {29 console.log('🚀 Server ready at ${url}');30});31const { ApolloServer } = require('apollo-server');32 type Query {33 }34`;35const resolvers = {36 Query: {37 hello: () => 'Hello world!'38 }39};40const server = new ApolloServer({ typeDefs, resolvers });41server.listen().then(({ url }) => {42 console.log('🚀 Server ready at
Using AI Code Generation
1const { ApolloServer, gql } = require('apollo-server');2 type Query {3 }4`;5const resolvers = {6 Query: {7 hello: () => 'Hello world!',8 },9};10const server = new ApolloServer({ typeDefs, resolvers });11server.listen().then(({ url }) => {12 console.log(`🚀 Server ready at ${url}`);13});
Using AI Code Generation
1const { ApolloServer, gql } = require('apollo-server');2const { buildFederatedSchema } = require('@apollo/federation');3 type User @key(fields: "id") {4 }5 extend type Query {6 }7`;8const resolvers = {9 Query: {10 me: () => {11 return {12 };13 },14 },15 User: {16 __resolveReference(object) {17 return {18 };19 },20 },21};22const server = new ApolloServer({23 schema: buildFederatedSchema([{ typeDefs, resolvers }]),24});25server.listen({ port: 4001 }).then(({ url }) => {26 console.log(`🚀 Server ready at ${url}`);27});28{"data":{"me":{"id":"1","username":"Ada Lovelace"}}}
Using AI Code Generation
1const { ApolloServer } = require('apollo-server');2const { typeDefs, resolvers } = require('./schema');3const { createStore } = require('./utils');4const store = createStore();5const server = new ApolloServer({6 context: () => {7 return { store };8 },9});10server.listen().then(({ url }) => {11 console.log(`🚀 Server ready at ${url}`);12});
Using AI Code Generation
1const { ApolloServer } = require('apollo-server-express');2const typeDefs = require('./schema');3const resolvers = require('./resolvers');4const { createTestClient } = require('apollo-server-testing');5const { ApolloServerPluginDrainHttpServer } = require('apollo-server-core');6const http = require('http');7const { makeExecutableSchema } = require('graphql-tools');8const { testClient } = require('./testClient');9const schema = makeExecutableSchema({10});11const server = new ApolloServer({12 plugins: [ApolloServerPluginDrainHttpServer({ httpServer })],13});14const httpServer = http.createServer(server);15server.installSubscriptionHandlers(httpServer);16const { query, mutate } = createTestClient(server);17testClient(query, mutate);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!