Skip to content

Commit

Permalink
Merge pull request #1295 from manekenpix/issues/552-remove-graphql
Browse files Browse the repository at this point in the history
Closes #552: Remove GraphQL implementation
  • Loading branch information
manekenpix committed Nov 10, 2020
2 parents 464dd74 + 3e83372 commit 87075df
Show file tree
Hide file tree
Showing 10 changed files with 29 additions and 380 deletions.
1 change: 0 additions & 1 deletion docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ docs available for each, including our:

- database [Redis](redis.md)
- frontend framework [GatsbyJS](gatsbyjs.md)
- frontend query language [GraphQL](graphql.md)
- single-sign-on (SSO) [login](login.md) using SAML2
- backend logging framework [Pino](logging.md)
- search engine indexing [Elasticsearch](elasticsearch.md)
Expand Down
41 changes: 0 additions & 41 deletions docs/graphql.md

This file was deleted.

3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@
"@elastic/elasticsearch": "7.9.0",
"@elastic/elasticsearch-mock": "0.3.0",
"@wordpress/wordcount": "2.11.0",
"apollo-server-express": "2.17.0",
"body-parser": "1.19.0",
"bull": "3.18.0",
"bull-board": "0.9.0",
Expand All @@ -80,8 +79,6 @@
"feed": "4.2.1",
"feedparser-promised": "2.0.1",
"git-repo-info": "2.1.1",
"graphql-iso-date": "3.6.1",
"graphql-passport": "0.6.3",
"helmet": "4.1.1",
"highlight.js": "10.2.0",
"http-proxy-middleware": "1.0.5",
Expand Down
2 changes: 1 addition & 1 deletion src/backend/utils/indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ const search = async (textToSearch, filter = 'post') => {

return {
results: hits.total.value,
values: hits.hits.map(({ _id }) => ({ id: _id })),
values: hits.hits.map(({ _id }) => ({ id: _id, url: `/posts/${_id}` })),
};
};

Expand Down
21 changes: 1 addition & 20 deletions src/backend/web/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ const bodyParser = require('body-parser');
const passport = require('passport');
const cors = require('cors');
const helmet = require('helmet');
const { ApolloServer } = require('apollo-server-express');
const RedisStore = require('connect-redis')(session);
const { buildContext } = require('graphql-passport');
const { redis } = require('../lib/redis');

const { typeDefs, resolvers } = require('./graphql');
const logger = require('../utils/logger');
const authentication = require('./authentication');
const router = require('./routes');
Expand All @@ -20,9 +17,6 @@ const app = express();

/**
* Use Helmet to secure our Express server.
* To avoid CSP violations when loading GraphQL's playground,
* 'cdn.jsdelivr.net' and 'unsafe-inline' were added to scriptSrc.
* https://github.com/ctrlplusb/react-universally/issues/253#issuecomment-267669695
*/
app.use(
helmet({
Expand All @@ -35,7 +29,7 @@ app.use(
frameSrc: ["'self'", '*.youtube.com', '*.vimeo.com'],
frameAncestors: ["'self'"],
imgSrc: ["'self'", 'data:', 'https:'],
scriptSrc: ["'self'", 'cdn.jsdelivr.net', "'unsafe-inline'"],
scriptSrc: ["'self'"],
styleSrc: ["'self'", 'https:', "'unsafe-inline'"],
objectSrc: ["'none'"],
upgradeInsecureRequests: [],
Expand Down Expand Up @@ -66,19 +60,6 @@ authentication.init();
app.use(passport.initialize());
app.use(passport.session());

// Add the Apollo server to app and define the `/graphql` endpoint
const server = new ApolloServer({
typeDefs,
resolvers,
context: ({ req, res }) => buildContext({ req, res }),
playground: {
settings: {
'request.credentials': 'same-origin',
},
},
});
server.applyMiddleware({ app, path: '/graphql' });

// Template rendering for legacy "planet" view of posts
app.engine('handlebars', expressHandlebars());
app.set('views', path.join(__dirname, 'planet/views'));
Expand Down
191 changes: 0 additions & 191 deletions src/backend/web/graphql/index.js

This file was deleted.

9 changes: 5 additions & 4 deletions src/backend/web/routes/query.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,23 @@ const router = express.Router();
router.get('/', async (req, res) => {
try {
const maxSearchLength = 256;
const { text, filter } = req.query;

if (!req.query.search) {
const error = 'Validation failed, query parameter search length is empty or undefined';
if (!text || !filter) {
const error = 'Validation failed, one or both query parameters are undefined';
res.status(400);
throw error;
}

// Github rule, query is greater than 256 chars return a validation failed message
if (req.query.search.length > maxSearchLength) {
if (text.length > maxSearchLength) {
const error =
'Validation failed, query parameter search length is greater than 256 characters.';
res.status(400);
throw error;
}

res.send(await search(req.query.search));
res.send(await search(text, filter));
} catch (error) {
res.send(`There was an error while executing your query: ${error}`);
logger.error({ error }, 'Something went wrong with search indexing');
Expand Down
Loading

0 comments on commit 87075df

Please sign in to comment.