Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
import resolvers from './resources/resolvers';
//Set Port. If environment variable exist use it instead
const GRAPHQL_PORT = process.env.GRAPHQL_PORT || 3000;
// Initialize the HTTP server using express
const server = express();
//Generate the executable schema. Note that makeExecutableSchema expects typeDefs and resolvers as input
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
//Define the GraphQL endpoint using the Apollo GraphQL Server. Note that graphqlExress expects the schema constant
server.use('/graphql', bodyParser.json(), graphqlExpress({
schema
}));
//Implement the Graphiql client available that comes with the Apollo GraphQL Server
server.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}));
// Start the server
server.listen(GRAPHQL_PORT, () => {
console.log('Go to http://localhost:' + GRAPHQL_PORT + '/graphiql to run queries!');
});
schema: hasuraGraphSchema,
link: hasuraLink,
});
const finalSchema = mergeSchemas({
schemas: [
executableWeatherSchema,
executableHasuraSchema,
linkHasuraTypeDefs
],
resolvers: hasuraWeatherResolvers
});
const app = new Express();
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema: finalSchema}));
app.use('/graphiql',graphiqlExpress({endpointURL: '/graphql'}));
app.listen(8080);
console.log('Server running. Open http://localhost:8080/graphiql to run queries.');
} // end of async run
const setupGraphQLServer = () => {
// setup server
const graphQLServer = express()
// /api/graphql
graphQLServer.use(
"/graphql",
bodyParser.json(),
graphqlExpress({ schema, context: {} })
)
// /api/graphiql
graphQLServer.use(
"/graphiql",
graphiqlExpress({ endpointURL: "graphql" })
)
// /api/schema
graphQLServer.use("/schema", (req, res) => {
res.set("Content-Type", "text/plain")
res.send(printSchema(schema))
})
return graphQLServer
}
app.get('/login-callback', ...loginCallbacks.loginCallback)
app.post('/login-callback', ...loginCallbacks.loginCallback)
}
const executableSchema = makeExecutableSchema({
typeDefs: schema,
resolvers,
allowUndefinedInResolve: false
})
addMockFunctionsToSchema({
schema: executableSchema,
mocks,
preserveResolvers: true
})
app.use('/graphql', graphqlExpress((request) => ({
schema: executableSchema,
context: {
loaders: createLoaders(),
user: request.user,
awsContext: request.awsContext || null,
awsEvent: request.awsEvent || null,
remainingMilliseconds: () => (
(request.awsContext && request.awsContext.getRemainingTimeInMillis)
? request.awsContext.getRemainingTimeInMillis()
: 5 * 60 * 1000 // default saying 5 min, no matter what
)
}
})))
app.get('/graphiql', graphiqlExpress({
endpointURL: '/graphql'
}))
module.exports = function (typeDefs, formatError, resolvers) {
const schema = makeExecutableSchema({
typeDefs,
schemaDirectives: { constraint: ConstraintDirective },
resolvers
})
const app = express()
app.use('/graphql', bodyParser.json(), graphqlExpress({ schema, formatError }))
return request(app)
}
function start(done) {
const app = express();
app.use(cors());
app.use(
'/graphql',
bodyParser.json(),
apolloUploadExpress(),
graphqlExpress({
schema,
context: {
lowdb
}
})
);
app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
return app.listen(4000, () => {
if (done) done();
console.log('Go to http://localhost:4000/graphiql to run queries!');
});
}
const schema = makeExecutableSchema({
typeDefs: readFileSync("02-graphql/schema.graphql", "utf8"),
resolvers: {
Query: {
salads: (_, { count }) => get(salads, count),
burgers: (_, { count }) => get(burgers, count)
}
}
});
const app = express();
app.get("/salads", ({ query: { count } }, res) => res.json(get(salads, count)));
app.get("/burgers", ({ query: { count } }, res) =>
res.json(get(burgers, count))
);
app.use("/graphql", bodyParser.json(), graphqlExpress({ schema }));
app.use("/graphiql", graphiqlExpress({ endpointURL: "/graphql" }));
app.listen(4000);
module.exports = app;
const user = await authenticate(req, mongo.Users, SECRET_KEY);
return {
context: {
dataloaders: buildDataLoaders(mongo),
mongo,
user,
SECRET_KEY,
},
schema,
}
}
app.use(morgan('dev'));
app.use('/graphql', bodyParser.json(), graphqlExpress(buildOptions));
app.use('/graphiql', graphiqlExpress({
endpointURL: '/graphql',
passHeader: `'Authorization': '${TESTING_TOKEN}'`,
subscriptionsEndpoint: `ws://localhost:${port}/subscriptions`,
}));
const server = createServer(app);
server.listen(port, () => {
new SubscriptionServer({
execute,
subscribe,
schema,
}, {
server,
path: '/subscriptions',
async function start(): Promise {
const app: express.Application = express();
app.use(cors());
app.use(config.GRAPHQL_ROUTE, bodyParser.json(), graphqlExpress({ schema }));
app.use(config.GRAPHIQL_ROUTE, graphiqlExpress({ endpointURL: config.GRAPHQL_ROUTE }));
return app.listen(config.PORT, () => {
logger.info(`Go to ${config.GRAPHQL_ENDPOINT} to run queries!`);
});
}