Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
'use strict';
const { ApolloServer, PubSub } = require('apollo-server-express');
const winston = require('../utils/logger/winston');
const { prisma } = require('../db/prisma');
const { typeDefs, resolvers, fragmentReplacements } = require('../graphql/resolvers');
const pubSub = new PubSub();
const server = new ApolloServer({
typeDefs,
resolvers,
tracing: true, // Add tracing or cacheControl meta data to the GraphQL response @url https://www.apollographql.com/docs/apollo-server/api/apollo-server.html
subscriptions: {
onConnect: () => winston.info('Connected to websocket'),
onDisconnect: webSocket => winston.info(`Disconnected from websocket ${webSocket}`),
},
context: ({ req }) => ({ //eslint-disable-line
req,
pubSub,
prisma,
}),
fragmentReplacements,
});
const express = require("express");
const { ApolloServer, gql, PubSub } = require("apollo-server-express");
// Construct a schema, using GraphQL schema language
const typeDefs = gql`
type Query {
hello: String
}
type Subscription {
hello: String
}
type Mutation {
hello(test: String): Boolean
}
`;
const pubsub = new PubSub();
const HELLO = 'HELLO';
// Provide resolver functions for your schema fields
const resolvers = {
Query: {
hello: () => "Hello world from ApolloServer on Now 2.0!"
},
Subscription: {
hello: {
// Additional event labels can be passed to asyncIterator creation
subscribe: () => pubsub.asyncIterator([HELLO]),
},
},
Mutation: {
hello(root, args, context) {
pubsub.publish(HELLO, { hello: args });
import { PubSub } from "apollo-server-express";
const pubSub = new PubSub();
// pubSub trigger
export const NEW_NOTIFICATION = "NEW_NOTIFICATION";
export default pubSub;
Mutation,
Parent,
Query,
ResolveProperty,
Resolver,
Subscription,
} from '../../../lib';
import { AuthGuard } from '../common/guards/auth.guard';
import { NewRecipeInput } from './dto/new-recipe.input';
import { RecipesArgs } from './dto/recipes.args';
import { Ingredient } from './models/ingredient';
import { IRecipe, Recipe } from './models/recipe';
import { RecipesService } from './recipes.service';
import { SearchResultUnion } from './unions/search-result.union';
const pubSub = new PubSub();
@Resolver(of => Recipe)
export class RecipesResolver {
constructor(private readonly recipesService: RecipesService) {}
@UseGuards(AuthGuard)
@Query(returns => IRecipe)
async recipe(@Args('id') id: string): Promise {
const recipe = await this.recipesService.findOneById(id);
if (!recipe) {
throw new NotFoundException(id);
}
return recipe;
}
@Query(returns => [SearchResultUnion])
async function start() {
const app = express()
const MONGO_DB = process.env.DB_HOST
const pubsub = new PubSub()
let db
try {
const client = await MongoClient.connect(MONGO_DB, { useNewUrlParser: true })
db = client.db()
} catch (error) {
console.log(`
Mongo DB Host not found!
please add DB_HOST environment variable to .env file
exiting...
`)
process.exit(1)
}
.default;
const { readFileSync } = require("fs");
const { createServer } = require("http");
const cookieParser = require("cookie-parser");
const User = require("./models/User");
const Message = require("./models/Message");
require("dotenv").config();
const typeDefs = gql(
readFileSync("./graphql/schema.graphql", { encoding: "utf-8" })
);
const resolvers = require("./graphql/resolvers");
const app = express();
const port = process.env.PORT || 8000;
const pubsub = new PubSub();
mongoose.Promise = global.Promise;
mongoose
.connect(process.env.MONGO_URI, {
useNewUrlParser: true,
useCreateIndex: true
})
.then(() => console.log(`MongoDB connected at ${process.env.MONGO_URI}`))
.catch(error => console.error(error));
const { ObjectId } = mongoose.Types;
ObjectId.prototype.valueOf = function() {
return this.toString();
};
app.use(cookieParser());
import { Http2Server } from 'http2';
import { createServer as createHttpServer } from 'http';
import { importSchema } from 'graphql-import';
import models from './models';
require('dotenv').config();
interface JwtUser {
userId: string;
role: number;
iat: number;
}
const { PORT = 4000, JWT_SECRET = 'undefined' } = process.env;
const pubsub = new PubSub();
const resolvers = mergeResolvers(
fileLoader(path.join(__dirname, './resolvers')),
);
const getUser = async (token: string, models) => {
const user = jwt.verify(token, JWT_SECRET) as JwtUser;
const currentUser = await models.User.findOne({
where: {
id: user.userId,
},
});
return currentUser;
};
const typeDefs = importSchema('schemas/schema.graphql');
import {PubSub} from "apollo-server-express";
import EventEmitter from "events";
const ee = new EventEmitter();
ee.setMaxListeners(250);
const pubsub = new PubSub({eventEmitter: ee});
export {pubsub};
const {
ApolloServer,
makeExecutableSchema,
PubSub,
} = require('apollo-server-express');
const typeDefs = require('./typeDefs');
const resolvers = require('./resolvers');
const Channels = require('../models/channels');
const { verifyToken } = require('../utils/token');
const pubsub = new PubSub();
const schema = makeExecutableSchema({
typeDefs,
resolvers,
});
const apolloServer = new ApolloServer({
schema,
context: ({ req, connection }) => (connection ? connection.context : ({
user: verifyToken(req.headers['x-auth-token']),
pubsub,
})),
subscriptions: {
onConnect: async ({ token, channelId, isMaster }) => {
const user = token ? verifyToken(token) : null;
const context = {