Use ES module syntax in backend instead of require
Ok cool, so apparently another win we get from using `ts-node` is that I can finally easily use some non-native-Node features like ES module import syntax, for consistency with what I'm doing in the main app source! That was getting on my nerves tbh. Ooh I bet I can finally use `?.` too, I've had to rewrite that a bunch…
This commit is contained in:
parent
1dda0d4edb
commit
19482be2b8
29 changed files with 74 additions and 83 deletions
|
@ -1,7 +1,7 @@
|
||||||
const util = require("util");
|
import util from "util";
|
||||||
|
|
||||||
const jwtVerify = util.promisify(require("jsonwebtoken").verify);
|
const jwtVerify = util.promisify(require("jsonwebtoken").verify);
|
||||||
const jwksClient = require("jwks-rsa");
|
import jwksClient from "jwks-rsa";
|
||||||
|
|
||||||
const jwks = jwksClient({
|
const jwks = jwksClient({
|
||||||
jwksUri: "https://openneo.us.auth0.com/.well-known/jwks.json",
|
jwksUri: "https://openneo.us.auth0.com/.well-known/jwks.json",
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const mysql = require("mysql2");
|
import mysql from "mysql2";
|
||||||
|
|
||||||
let globalDbs = new Map();
|
let globalDbs = new Map();
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,9 @@
|
||||||
const { beelinePlugin } = require("./lib/beeline-graphql");
|
import { beelinePlugin } from "./lib/beeline-graphql";
|
||||||
const { gql, makeExecutableSchema } = require("apollo-server");
|
import { gql, makeExecutableSchema } from "apollo-server";
|
||||||
|
import { getUserIdFromToken } from "./auth";
|
||||||
const { getUserIdFromToken } = require("./auth");
|
import connectToDb from "./db";
|
||||||
const connectToDb = require("./db");
|
import buildLoaders from "./loaders";
|
||||||
const buildLoaders = require("./loaders");
|
import { plugin as cacheControlPluginFork } from "./lib/apollo-cache-control-fork";
|
||||||
const {
|
|
||||||
plugin: cacheControlPluginFork,
|
|
||||||
} = require("./lib/apollo-cache-control-fork");
|
|
||||||
|
|
||||||
const rootTypeDefs = gql`
|
const rootTypeDefs = gql`
|
||||||
enum CacheScope {
|
enum CacheScope {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
// Adapted from https://github.com/apollographql/apollo-server/blob/201630ad284754248fc9ab6ebedc7506fcc3d951/packages/apollo-server-lambda/src/ApolloServer.ts
|
// Adapted from https://github.com/apollographql/apollo-server/blob/201630ad284754248fc9ab6ebedc7506fcc3d951/packages/apollo-server-lambda/src/ApolloServer.ts
|
||||||
|
|
||||||
const { ApolloServerBase, runHttpQuery } = require("apollo-server-core");
|
import { ApolloServerBase, runHttpQuery } from "apollo-server-core";
|
||||||
const { Headers } = require("apollo-server-env");
|
|
||||||
const {
|
import { Headers } from "apollo-server-env";
|
||||||
renderPlaygroundPage,
|
import { renderPlaygroundPage } from "@apollographql/graphql-playground-html";
|
||||||
} = require("@apollographql/graphql-playground-html");
|
|
||||||
|
|
||||||
function graphqlVercel(options) {
|
function graphqlVercel(options) {
|
||||||
if (!options) {
|
if (!options) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const beeline = require("honeycomb-beeline");
|
import beeline from "honeycomb-beeline";
|
||||||
|
|
||||||
const beelinePlugin = {
|
const beelinePlugin = {
|
||||||
requestDidStart() {
|
requestDidStart() {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const DataLoader = require("dataloader");
|
import DataLoader from "dataloader";
|
||||||
const { normalizeRow } = require("./util");
|
import { normalizeRow } from "./util";
|
||||||
|
|
||||||
const buildClosetListLoader = (db) =>
|
const buildClosetListLoader = (db) =>
|
||||||
new DataLoader(async (ids) => {
|
new DataLoader(async (ids) => {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const fetch = require("node-fetch");
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
async function loadAssetManifest(swfUrl) {
|
async function loadAssetManifest(swfUrl) {
|
||||||
const manifestUrl = convertSwfUrlToManifestUrl(swfUrl);
|
const manifestUrl = convertSwfUrlToManifestUrl(swfUrl);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { createCanvas, loadImage } = require("canvas");
|
import { createCanvas, loadImage } from "canvas";
|
||||||
|
|
||||||
async function renderOutfitImage(layerRefs, size) {
|
async function renderOutfitImage(layerRefs, size) {
|
||||||
const canvas = createCanvas(size, size);
|
const canvas = createCanvas(size, size);
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
const { renderOutfitImage } = require("./outfit-images");
|
import { renderOutfitImage } from "./outfit-images";
|
||||||
|
import { toMatchImageSnapshot } from "jest-image-snapshot";
|
||||||
const { toMatchImageSnapshot } = require("jest-image-snapshot");
|
|
||||||
expect.extend({ toMatchImageSnapshot });
|
expect.extend({ toMatchImageSnapshot });
|
||||||
|
|
||||||
const originalConsoleWarn = console.warn;
|
const originalConsoleWarn = console.warn;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls } = require("./setup.js");
|
import { query, getDbCalls } from "./setup.js";
|
||||||
|
|
||||||
describe("Color", () => {
|
describe("Color", () => {
|
||||||
it("loads a single color", async () => {
|
it("loads a single color", async () => {
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const {
|
import {
|
||||||
query,
|
query,
|
||||||
mutate,
|
mutate,
|
||||||
getDbCalls,
|
getDbCalls,
|
||||||
useTestDb,
|
useTestDb,
|
||||||
logInAsTestUser,
|
logInAsTestUser,
|
||||||
createItem,
|
createItem,
|
||||||
} = require("./setup.js");
|
} from "./setup.js";
|
||||||
|
|
||||||
describe("Item", () => {
|
describe("Item", () => {
|
||||||
it("loads metadata", async () => {
|
it("loads metadata", async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls } = require("./setup.js");
|
import { query, getDbCalls } from "./setup.js";
|
||||||
|
|
||||||
describe("ItemSearch", () => {
|
describe("ItemSearch", () => {
|
||||||
it("loads Neopian Times items", async () => {
|
it("loads Neopian Times items", async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls } = require("./setup.js");
|
import { query, getDbCalls } from "./setup.js";
|
||||||
|
|
||||||
describe("Outfit", () => {
|
describe("Outfit", () => {
|
||||||
it("loads an outfit by ID", async () => {
|
it("loads an outfit by ID", async () => {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const {
|
import {
|
||||||
query,
|
query,
|
||||||
getDbCalls,
|
getDbCalls,
|
||||||
clearDbCalls,
|
clearDbCalls,
|
||||||
useTestDb,
|
useTestDb,
|
||||||
connectToDb,
|
connectToDb,
|
||||||
} = require("./setup.js");
|
} from "./setup.js";
|
||||||
|
|
||||||
describe("Pet", () => {
|
describe("Pet", () => {
|
||||||
it("looks up a pet", async () => {
|
it("looks up a pet", async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls } = require("./setup.js");
|
import { query, getDbCalls } from "./setup.js";
|
||||||
|
|
||||||
describe("PetAppearance", () => {
|
describe("PetAppearance", () => {
|
||||||
it("loads for species and color", async () => {
|
it("loads for species and color", async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls } = require("./setup.js");
|
import { query, getDbCalls } from "./setup.js";
|
||||||
|
|
||||||
describe("Species", () => {
|
describe("Species", () => {
|
||||||
it("loads a single species", async () => {
|
it("loads a single species", async () => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { query, getDbCalls, logInAsTestUser } = require("./setup.js");
|
import { query, getDbCalls, logInAsTestUser } from "./setup.js";
|
||||||
|
|
||||||
describe("User", () => {
|
describe("User", () => {
|
||||||
it("looks up a user", async () => {
|
it("looks up a user", async () => {
|
||||||
|
|
|
@ -1,15 +1,13 @@
|
||||||
const fs = require("fs");
|
import fs from "fs";
|
||||||
const path = require("path");
|
import path from "path";
|
||||||
|
import { ApolloServer } from "apollo-server";
|
||||||
const { ApolloServer } = require("apollo-server");
|
import { createTestClient } from "apollo-server-testing";
|
||||||
const { createTestClient } = require("apollo-server-testing");
|
import { AuthenticationClient } from "auth0";
|
||||||
const { AuthenticationClient } = require("auth0");
|
import auth from "../auth";
|
||||||
|
|
||||||
const auth = require("../auth");
|
|
||||||
const actualAuth = jest.requireActual("../auth");
|
const actualAuth = jest.requireActual("../auth");
|
||||||
const connectToDb = require("../db");
|
import connectToDb from "../db";
|
||||||
const actualConnectToDb = jest.requireActual("../db");
|
const actualConnectToDb = jest.requireActual("../db");
|
||||||
const { config } = require("../index");
|
import { config } from "../index";
|
||||||
|
|
||||||
let accessTokenForQueries = null;
|
let accessTokenForQueries = null;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
const { loadAssetManifest } = require("../neopets-assets");
|
import { loadAssetManifest } from "../neopets-assets";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
enum LayerImageSize {
|
enum LayerImageSize {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
enum OwnsOrWants {
|
enum OwnsOrWants {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
const { getRestrictedZoneIds, oneWeek, oneDay, oneHour } = require("../util");
|
import { getRestrictedZoneIds, oneWeek, oneDay, oneHour } from "../util";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type Item @cacheControl(maxAge: ${oneDay}, staleWhileRevalidate: ${oneWeek}) {
|
type Item @cacheControl(maxAge: ${oneDay}, staleWhileRevalidate: ${oneWeek}) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
const { ManagementClient } = require("auth0");
|
import { ManagementClient } from "auth0";
|
||||||
|
|
||||||
const auth0 = new ManagementClient({
|
const auth0 = new ManagementClient({
|
||||||
domain: "openneo.us.auth0.com",
|
domain: "openneo.us.auth0.com",
|
||||||
|
@ -8,7 +8,7 @@ const auth0 = new ManagementClient({
|
||||||
scope: "read:users update:users",
|
scope: "read:users update:users",
|
||||||
});
|
});
|
||||||
|
|
||||||
const {
|
import {
|
||||||
capitalize,
|
capitalize,
|
||||||
getPoseFromPetState,
|
getPoseFromPetState,
|
||||||
getPetStateFieldsFromPose,
|
getPetStateFieldsFromPose,
|
||||||
|
@ -16,7 +16,7 @@ const {
|
||||||
loadBodyName,
|
loadBodyName,
|
||||||
logToDiscord,
|
logToDiscord,
|
||||||
normalizeRow,
|
normalizeRow,
|
||||||
} = require("../util");
|
} from "../util";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type RemoveLayerFromItemMutationResult {
|
type RemoveLayerFromItemMutationResult {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type Outfit {
|
type Outfit {
|
||||||
|
|
|
@ -1,11 +1,9 @@
|
||||||
const util = require("util");
|
import util from "util";
|
||||||
|
import fetch from "node-fetch";
|
||||||
const fetch = require("node-fetch");
|
import { gql } from "apollo-server";
|
||||||
const { gql } = require("apollo-server");
|
import xmlrpc from "xmlrpc";
|
||||||
const xmlrpc = require("xmlrpc");
|
import { getPoseFromPetState } from "../util";
|
||||||
|
import { saveModelingData } from "../modeling";
|
||||||
const { getPoseFromPetState } = require("../util");
|
|
||||||
const { saveModelingData } = require("../modeling");
|
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type Pet {
|
type Pet {
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
const {
|
|
||||||
|
import {
|
||||||
capitalize,
|
capitalize,
|
||||||
getPoseFromPetState,
|
getPoseFromPetState,
|
||||||
getRestrictedZoneIds,
|
getRestrictedZoneIds,
|
||||||
oneWeek,
|
oneWeek,
|
||||||
oneDay,
|
oneDay,
|
||||||
oneHour,
|
oneHour,
|
||||||
} = require("../util");
|
} from "../util";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type Color @cacheControl(maxAge: ${oneWeek}) {
|
type Color @cacheControl(maxAge: ${oneWeek}) {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
type User {
|
type User {
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
const { gql } = require("apollo-server");
|
import { gql } from "apollo-server";
|
||||||
|
|
||||||
const typeDefs = gql`
|
const typeDefs = gql`
|
||||||
# Cache for 1 week (unlikely to change)
|
# Cache for 1 week (unlikely to change)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const beeline = require("honeycomb-beeline");
|
import beeline from "honeycomb-beeline";
|
||||||
const fetch = require("node-fetch");
|
import fetch from "node-fetch";
|
||||||
|
|
||||||
function capitalize(str) {
|
function capitalize(str) {
|
||||||
return str[0].toUpperCase() + str.slice(1);
|
return str[0].toUpperCase() + str.slice(1);
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
const gql = require("graphql-tag");
|
import gql from "graphql-tag";
|
||||||
const { getDbCalls } = require("./query-tests/setup.js");
|
import { getDbCalls } from "./query-tests/setup.js";
|
||||||
|
import connectToDb from "./db";
|
||||||
const connectToDb = require("./db");
|
import { loadBodyName } from "./util";
|
||||||
const { loadBodyName } = require("./util");
|
|
||||||
|
|
||||||
describe("loadBodyName", () => {
|
describe("loadBodyName", () => {
|
||||||
it("returns placeholder string for 0", async () => {
|
it("returns placeholder string for 0", async () => {
|
||||||
|
|
Loading…
Reference in a new issue