Skip to content

Commit

Permalink
New Packages (#19)
Browse files Browse the repository at this point in the history
* adding graphql packages

* valid e2e tests, esm packages, passing unit tests

* adding build steps to workflow files

* removing xmlkit from the equation

* fixing e2e path

* reorganizing build scripts

* adding new check for sign up test

Co-authored-by: Charlie ⚡ <[email protected]>
  • Loading branch information
charliewilco and Charlie ⚡ committed Jan 14, 2023
1 parent 42b085e commit b7b8401
Show file tree
Hide file tree
Showing 73 changed files with 4,528 additions and 602 deletions.
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
9 changes: 4 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 2

- uses: actions/cache@v3
with:
# See here for caching with `yarn` https://github.com/actions/cache/blob/main/examples.md#node---yarn or you can leverage caching with actions/setup-node https://github.com/actions/setup-node
Expand All @@ -37,9 +37,8 @@ jobs:
- name: Generate Types
run: npm run generate && npx prisma generate --schema apps/graphql/prisma/schema.prisma

- name: Types
run: npm run types

- name: Build
run: npm run build


- name: Types
run: npm run types
36 changes: 19 additions & 17 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,23 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# - uses: actions/setup-node@v3
# with:
# node-version: 18
- uses: actions/setup-node@v3
with:
node-version: 18

- name: Skip
run: echo 'Not today, come back later'
# - name: Install dependencies
# run: npm ci
# - name: Install Playwright Browsers
# run: npm run deps --workspace=@reubin/e2e
# - name: Run Playwright tests
# run: npm test --workspace=@reubin/e2e
# - uses: actions/upload-artifact@v3
# if: always()
# with:
# name: playwright-report
# path: playwright-report/
# retention-days: 30
- name: Install dependencies
run: npm ci
- name: Generate Types
run: npm run generate && npx prisma generate --schema apps/graphql/prisma/schema.prisma
- name: Build
run: npm run build
- name: Install Playwright Browsers
run: npm run deps --workspace=@reubin/e2e
- name: Run Playwright tests
run: npm test --workspace=@reubin/e2e
- uses: actions/upload-artifact@v3
if: always()
with:
name: playwright-report
path: e2e/playwright-report/
retention-days: 30
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,10 @@ jobs:
POSTGRES_DB: ci_db_test
POSTGRES_PORT: ${{ job.services.postgres.ports[5432] }}
DATABASE_URL: postgresql:https://postgres:postgres@localhost:5432/ci_db_test
- name: Build
run: npm run build
- name: Test
run: npm run test
run: npm test
env:
# The hostname used to communicate with the PostgreSQL service container
POSTGRES_HOST: localhost
Expand Down
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM node:18-alpine

# Create app directory
WORKDIR /usr/src/app
RUN npm install -g turbo

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./
COPY turbo.json ./

RUN npm install
RUN npm run build

# Bundle app source
COPY . .

EXPOSE 4000
CMD ["npm", "start"]
2 changes: 1 addition & 1 deletion apps/graphql/jest.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/** @type {import('jest').Config} */
module.exports = {
preset: "ts-jest",
preset: "ts-jest/presets/default-esm",
testEnvironment: "node",
verbose: true,
transform: {
Expand Down
37 changes: 20 additions & 17 deletions apps/graphql/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"name": "@reubin/graphql",
"version": "1.2.1",
"type": "module",
"private": true,
"scripts": {
"start": "node dist/server",
Expand All @@ -15,40 +16,42 @@
"@apollo/rover": "^0.10.0",
"@rollup/plugin-graphql": "^2.0.2",
"@rollup/plugin-run": "^3.0.1",
"@rollup/plugin-typescript": "^9.0.2",
"@types/jest": "^29.1.1",
"@types/node": "^18.7.20",
"babel-jest": "^29.1.2",
"@rollup/plugin-typescript": "^11.0.0",
"@types/jest": "^29.2.5",
"@types/node": "^18.11.18",
"babel-jest": "^29.3.1",
"cuid": "^2.1.8",
"jest": "^29.2.2",
"prisma": "^4.8.0",
"rollup": "^3.4.0",
"ts-jest": "^29.0.2",
"typescript": "^4.8.4"
"jest": "^29.3.1",
"prisma": "^4.8.1",
"rollup": "^3.10.0",
"ts-jest": "^29.0.4",
"typescript": "^4.9.4"
},
"dependencies": {
"@apollo/server": "^4.3.0",
"@graphql-tools/schema": "^9.0.12",
"@prisma/client": "^4.8.0",
"@graphql-tools/schema": "^9.0.13",
"@graphql-tools/utils": "^9.1.4",
"@prisma/client": "^4.8.1",
"@reubin/graphql-date-ts": "*",
"@reubin/rsskit": "*",
"@types/base-64": "^1.0.0",
"@types/bcryptjs": "^2.4.2",
"@types/jsonwebtoken": "^9.0.0",
"@types/jsonwebtoken": "^9.0.1",
"@types/sanitize-html": "^2.8.0",
"@types/xml2js": "^0.4.11",
"axios": "^1.2.0",
"axios": "^1.2.2",
"base-64": "^1.0.0",
"bcryptjs": "^2.4.3",
"cheerio": "^1.0.0-rc.12",
"date-fns": "^2.9.3",
"date-fns": "^2.29.3",
"entities": "^4.4.0",
"graphql": "^16.6.0",
"graphql-tag": "^2.12.6",
"html-entities": "^2.3.2",
"html-entities": "^2.3.3",
"jsonwebtoken": "^9.0.0",
"nexus": "^1.3.0",
"sanitize-html": "^2.8.1",
"universal-cookie": "^4.0.4",
"xml2js": "^0.4.23",
"zod": "^3.20.0"
"zod": "^3.20.2"
}
}
3 changes: 2 additions & 1 deletion apps/graphql/rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ if (isDev) {
export default defineConfig({
input: "./src/server.ts",
external: (id) => !/^[./]/.test(id),
shimMissingExports: true,
output: [
{
file: "./dist/server.js",
format: "cjs",
format: "esm",
sourcemap: true,
},
],
Expand Down
28 changes: 28 additions & 0 deletions apps/graphql/src/auth-directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { mapSchema, getDirective, MapperKind } from "@graphql-tools/utils";
import { defaultFieldResolver, GraphQLSchema } from "graphql";

export function upperDirectiveTransformer(schema: GraphQLSchema, directiveName: string) {
return mapSchema(schema, {
// Executes once for each object field in the schema
[MapperKind.OBJECT_FIELD]: (fieldConfig) => {
// Check whether this field has the specified directive
const upperDirective = getDirective(schema, fieldConfig, directiveName)?.[0];

if (upperDirective) {
// Get this field's original resolver
const { resolve = defaultFieldResolver } = fieldConfig;

// Replace the original resolver with a function that *first* calls
// the original resolver, then converts its result to upper case
fieldConfig.resolve = async function (source, args, context, info) {
const result = await resolve(source, args, context, info);
if (typeof result === "string") {
return result.toUpperCase();
}
return result;
};
return fieldConfig;
}
},
});
}
2 changes: 1 addition & 1 deletion apps/graphql/src/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IncomingMessage } from "http";
import type { IncomingMessage } from "node:http";
import Cookies from "universal-cookie";

export interface Context {
Expand Down
2 changes: 1 addition & 1 deletion apps/graphql/src/model/entry.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Entry } from "@prisma/client";
import type { Services } from "../services";
import type { RSSItem } from "../rss";
import type { RSSItem } from "@reubin/rsskit";
import type { Entry as EntryType } from "../__generated__";

export class EntryController {
Expand Down
2 changes: 1 addition & 1 deletion apps/graphql/src/model/users.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as base64 from "base-64";
import base64 from "base-64";
import type { User } from "@prisma/client";

import { ReturnedUser, User as UserType } from "../__generated__";
Expand Down
Loading

1 comment on commit b7b8401

@vercel
Copy link

@vercel vercel bot commented on b7b8401 Jan 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.