Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade Node and core dependencies #219

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module.exports = {
export default {
env: {
es2021: true,
esnext: true,
jest: true,
node: true,
},
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
22
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# build environment
FROM node:16-alpine as build
FROM node:22-alpine as build
WORKDIR /app
# Install deps
COPY package.json /app/package.json
Expand Down Expand Up @@ -34,4 +34,4 @@ ENV NODE_ENV=prod
ENTRYPOINT ["/app/entrypoint.sh"]

EXPOSE 4000 8080
CMD ["yarn", "prod"]
CMD ["yarn", "prod"]
14 changes: 2 additions & 12 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,5 @@
{
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "16"
}
}
],
"@babel/preset-typescript"
],
"plugins": ["@babel/plugin-proposal-class-properties"],
"presets": ["@babel/preset-env", "@babel/preset-typescript"],
"plugins": [],
"ignore": ["node_modules"]
}
31 changes: 18 additions & 13 deletions graphql/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { ApolloServer, gql } from "apollo-server";
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import gql from "graphql-tag";
import GraphQLJSON, { GraphQLJSONObject } from "graphql-type-json";
import macros from "../utils/macros";

Expand Down Expand Up @@ -61,19 +63,22 @@ const server = new ApolloServer({
searchResolvers,
termInfoResolvers,
],
debug: true,
// debug: true,
});

if (require.main === module) {
server
.listen()
.then(({ url }) => {
macros.log(`ready at ${url}`);
return;
})
.catch((err) => {
macros.error(`error starting graphql server: ${JSON.stringify(err)}`);
});
}
console.log("hi");

// if (require.main === module) {
startStandaloneServer(server, {
listen: { port: 3000 },
})
.then(({ url }) => {
macros.log(`ready at ${url}`);
return;
})
.catch((err) => {
macros.error(`error starting graphql server: ${JSON.stringify(err)}`);
});
// }

export default server;
10 changes: 7 additions & 3 deletions graphql/resolvers/major.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import { UserInputError } from "apollo-server";
import prisma from "../../services/prisma";
import { Major as PrismaMajor } from "@prisma/client";
import { GraphQLError } from "graphql";

const noResultsError = (recordType): never => {
throw new UserInputError(`${recordType} not found!`);
throw new GraphQLError(`${recordType} not found!`, {
extensions: {
code: "BAD_USER_INPUT",
},
});
};

const getLatestMajorOccurrence = async (
majorId: string
majorId: string,
): Promise<PrismaMajor> => {
const majors: PrismaMajor[] = await prisma.major.findMany({
where: { majorId: majorId },
Expand Down
69 changes: 45 additions & 24 deletions graphql/tests/class.test.seq.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* This file is part of Search NEU and licensed under AGPL3.
* See the license file in the root folder for details.
*/
import { gql } from "apollo-server";
import { GraphQLResponse } from "apollo-server-core";
import gql from "graphql-tag";
import { GraphQLResponse } from "@apollo/server";
import { DocumentNode, GraphQLError } from "graphql";
import prisma from "../../services/prisma";
import server from "../index";
Expand Down Expand Up @@ -164,11 +164,15 @@ describe("returns errors for non-existant classes", () => {
`,
});

expect(res?.errors?.length).toBe(1);
expect(res?.errors?.[0]).toEqual(
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res.body.singleResult.errors.length).toBe(1);
expect(res.body.singleResult.errors?.[0]).toEqual(
new GraphQLError(
`We couldn't find any occurrences of a class with subject 'CS' and class ID '2510'`
)
`We couldn't find any occurrences of a class with subject 'CS' and class ID '2510'`,
),
);
});

Expand All @@ -187,10 +191,13 @@ describe("returns errors for non-existant classes", () => {
}
`,
});
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res?.errors).toBeUndefined();
expect(res.body.singleResult.errors).toBeUndefined();
// This doesn't throw an error - it just omits any classes for which we have no data
expect(res?.data).toEqual({
expect(res.body.singleResult.data).toEqual({
bulkClasses: [],
});
});
Expand All @@ -207,12 +214,15 @@ describe("returns errors for non-existant classes", () => {
}
`,
});
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res?.errors?.length).toBe(1);
expect(res?.errors?.[0]).toEqual(
expect(res.body.singleResult.errors.length).toBe(1);
expect(res.body.singleResult.errors?.[0]).toEqual(
new GraphQLError(
`We couldn't find any occurrences of a class with subject 'CS' and class ID '2510'`
)
`We couldn't find any occurrences of a class with subject 'CS' and class ID '2510'`,
),
);
});

Expand All @@ -229,11 +239,15 @@ describe("returns errors for non-existant classes", () => {
`,
});

expect(res?.errors?.length).toBe(1);
expect(res?.errors?.[0]).toEqual(
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res.body.singleResult.errors.length).toBe(1);
expect(res.body.singleResult.errors?.[0]).toEqual(
new GraphQLError(
"We couldn't find a course matching the term '202310', subject 'CS', and class ID '2500'"
)
"We couldn't find a course matching the term '202310', subject 'CS', and class ID '2500'",
),
);
});

Expand All @@ -248,11 +262,15 @@ describe("returns errors for non-existant classes", () => {
`,
});

expect(res?.errors?.length).toBe(1);
expect(res?.errors?.[0]).toEqual(
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res.body.singleResult.errors.length).toBe(1);
expect(res.body.singleResult.errors?.[0]).toEqual(
new GraphQLError(
"We couldn't find a course matching the hash 'neu.edu/202310/CS/2500'"
)
"We couldn't find a course matching the hash 'neu.edu/202310/CS/2500'",
),
);
});

Expand All @@ -266,12 +284,15 @@ describe("returns errors for non-existant classes", () => {
}
`,
});
if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res?.errors?.length).toBe(1);
expect(res?.errors?.[0]).toEqual(
expect(res.body.singleResult.errors.length).toBe(1);
expect(res.body.singleResult.errors?.[0]).toEqual(
new GraphQLError(
"We couldn't find a section matching the hash 'neu.edu/201830/CS/2500/123456'"
)
"We couldn't find a section matching the hash 'neu.edu/201830/CS/2500/123456'",
),
);
});
});
Expand Down
4 changes: 2 additions & 2 deletions graphql/tests/major.test.seq.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";
import prisma from "../../services/prisma";
import server from "../index";
import { DocumentNode } from "graphql";
import { GraphQLResponse } from "apollo-server-core";
import { GraphQLResponse } from "@apollo/server";

const query = async (queryBody: {
query: string | DocumentNode;
Expand Down
11 changes: 8 additions & 3 deletions graphql/tests/search.test.seq.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";
import { mocked } from "jest-mock";
import searcher from "../../services/searcher";
import server from "../index";
import { Course, Requisite, Section } from "../../types/types";
import { DocumentNode } from "graphql";
import { GraphQLResponse } from "apollo-server-core";
import { GraphQLResponse } from "@apollo/server";

jest.mock("../../services/searcher");

Expand Down Expand Up @@ -208,7 +208,12 @@ describe("search resolver", () => {
10,
{},
]);
expect(res.data.search).toEqual({

if (res.body.kind !== "single") {
fail("incorrect graphql response kind");
}

expect(res.body.singleResult.data.search).toEqual({
totalCount: 1,
pageInfo: { hasNextPage: false },
});
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/class.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
extend type Query {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/classOccurrence.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
type ClassOccurrence {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/employee.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
type Employee {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/major.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
extend type Query {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/majorOccurrence.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
type MajorOccurrence {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/search.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
extend type Query {
Expand Down
2 changes: 1 addition & 1 deletion graphql/typeDefs/termInfo.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { gql } from "apollo-server";
import gql from "graphql-tag";

const typeDef = gql`
extend type Query {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: "2"

services:
postgresql:
image: postgres:11.19-bullseye
Expand All @@ -13,8 +11,9 @@ services:
- POSTGRES_USER=postgres
env_file:
- ../../.env

es:
image: docker.elastic.co/elasticsearch/elasticsearch-oss:7.10.2
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.24
ports:
- 9200:9200
environment:
Expand Down
Loading
Loading