Skip to content

Commit

Permalink
locations
Browse files Browse the repository at this point in the history
  • Loading branch information
willruggiano committed May 14, 2024
1 parent 4dd6c18 commit d30fbf4
Show file tree
Hide file tree
Showing 14 changed files with 93 additions and 59 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/.dockerignore
/.gitignore
/docker-compose.yaml
/justfile
/Dockerfile
/README.md
Expand Down
35 changes: 19 additions & 16 deletions bin/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,32 @@ app.use(
express.json(),
expressMiddleware(server, {
async context({ req }) {
const user = await (async () => {
console.log("Authorization:", req.headers.authorization);
const auth = req.headers.authorization;
if (!auth) return;
const [user] = await sql<[{ id: string; language: number }?]>`
try {
const user = await (async () => {
if (!req.headers.authorization) return;
const [user] = await sql<[{ id: string; language: number }?]>`
SELECT
workeruuid AS id,
workerlanguageid AS language
FROM public.worker
WHERE workerexternalid = ${auth};
WHERE workerexternalid = ${req.headers.authorization};
`;
return user;
})();
return user;
})();

const ctx = {
authScope: user?.id,
languageTypeId: user?.language ?? 20,
};
const ctx = {
authScope: user?.id,
languageTypeId: user?.language ?? 20,
};

return {
...ctx,
orm: orm(ctx),
};
return {
...ctx,
orm: orm(ctx),
};
} catch (e) {
console.error(e);
throw e;
}
},
}),
);
Expand Down
2 changes: 1 addition & 1 deletion copilot/.workspace
Original file line number Diff line number Diff line change
@@ -1 +1 @@
application: tendrel-graphql
application: graphql
21 changes: 14 additions & 7 deletions copilot/graphql/manifest.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# The manifest for the "graphql" service.
# Read the full specification for the "Request-Driven Web Service" type at:
# https://aws.github.io/copilot-cli/docs/manifest/rd-web-service/
# Read the full specification for the "Load Balanced Web Service" type at:
# https://aws.github.io/copilot-cli/docs/manifest/lb-web-service/

# Your service name will be used in naming your resources like log groups, App Runner services, etc.
# Your service name will be used in naming your resources like log groups, ECS services, etc.
name: graphql
# The "architecture" of the service you're running.
type: Request-Driven Web Service
type: Load Balanced Web Service

image:
# Docker build arguments.
Expand All @@ -14,8 +13,14 @@ image:
# Port exposed through your container to route traffic to it.
port: 4000

http:
path: /v1 # gql.tendrel.io/v1
http: false
nlb:
port: 443/tls
target_port: 4000

network:
vpc:
placement: private

# Number of CPU units for the task.
cpu: 1024
Expand All @@ -40,6 +45,8 @@ environments:
LOG_LEVEL: debug
NODE_ENV: development
test:
nlb:
alias: test.graphql.tendrel.io
secrets:
DB_USERNAME:
secretsmanager: "/database/service/graphql:username::"
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
environment:
POSTGRES_PASSWORD: password
ports:
- 5432:5432
- 5433:5432
volumes:
- pgdata:/var/lib/postgresql/data

Expand Down
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
biome
bun
just
postgresql
(stdenv.mkDerivation rec {
pname = "copilot-cli";
version = "1.33.3";
Expand Down
6 changes: 1 addition & 5 deletions lib/schema/resolvers/Customer.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { sql } from "@/datasources/postgres";
import type {
CustomerResolvers,
Language,
Name,
} from "./../__generated__/types.generated";
import type { CustomerResolvers, Language, Name } from "@/schema";
export const Customer: CustomerResolvers = {
async name(parent, _, ctx) {
const [name] = await sql<[Name]>`
Expand Down
7 changes: 3 additions & 4 deletions lib/schema/resolvers/Language.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { sql } from "@/datasources/postgres";
import type {
LanguageResolvers,
Name,
} from "./../__generated__/types.generated";
import type { LanguageResolvers, Name } from "@/schema";

export const Language: LanguageResolvers = {
async name(parent, _, ctx) {
const [name] = await sql<[Name?]>`
Expand All @@ -29,6 +27,7 @@ export const Language: LanguageResolvers = {
ON m.languagemastersourcelanguagetypeid = s.systagid
WHERE m.languagemasterid = ${parent.name_id};
`;

return fallback;
}

Expand Down
20 changes: 18 additions & 2 deletions lib/schema/resolvers/Location.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
import type { LocationResolvers } from "./../__generated__/types.generated";
import { sql } from "@/datasources/postgres";
import type { LocationResolvers, Name } from "@/schema";
export const Location: LocationResolvers = {
/* Implement Location resolver logic here */
async name(parent, _, ctx) {
const [name] = await sql<[Name]>`
SELECT
COALESCE(t.languagetranslationid, m.languagemasterid) AS id,
COALESCE(t.languagetranslationtypeid, m.languagemastersourcelanguagetypeid) AS language_id,
COALESCE(t.languagetranslationvalue, m.languagemastersource) AS value
FROM public.languagemaster AS m
LEFT JOIN public.languagetranslations AS t
ON
m.languagemasterid = t.languagetranslationmasterid
AND t.languagetranslationtypeid = ${ctx.languageTypeId}
WHERE m.languagemasterid = ${parent.name_id};
`;

return name;
},
};
11 changes: 2 additions & 9 deletions lib/schema/resolvers/Name.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
import { sql } from "@/datasources/postgres";
import type {
Language,
NameResolvers,
} from "./../__generated__/types.generated";
import type { Language, NameResolvers } from "@/schema";

export const Name: NameResolvers = {
async language(parent) {
console.log(
"typeof parent.language_id =:",
typeof parent.language_id,
parent.language_id,
);
const [language] = await sql<[Language]>`
SELECT
systaguuid AS id,
Expand Down
2 changes: 1 addition & 1 deletion lib/schema/resolvers/Query/customer.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { QueryResolver } from "@/schema/resolvers";

export const customer: NonNullable<QueryResolvers["customer"]> = async (
export const customer: QueryResolver<"customer"> = async (
_,
{ id },
{ orm },
Expand Down
9 changes: 3 additions & 6 deletions lib/schema/resolvers/Query/customers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import { sql } from "@/datasources/postgres";
import type { Customer, QueryResolvers } from "@/schema";
import type { Customer } from "@/schema";
import type { QueryResolver } from "@/schema/resolvers";
import { GraphQLError } from "graphql";

export const customers: NonNullable<QueryResolvers["customers"]> = async (
_,
__,
ctx,
) => {
export const customers: QueryResolver<"customers"> = async (_, __, ctx) => {
const { authScope } = ctx;

if (!authScope)
Expand Down
32 changes: 26 additions & 6 deletions lib/schema/resolvers/Query/locations.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,30 @@
import type { QueryResolvers } from "./../../__generated__/types.generated";
import { sql } from "@/datasources/postgres";
import type { Location } from "@/schema";
import type { QueryResolver } from "@/schema/resolvers";
import { GraphQLError } from "graphql";

export const locations: NonNullable<QueryResolvers['locations']> = async (
export const locations: QueryResolver<"locations"> = async (
_,
{ customerId, options },
{ languageTypeId },
{ customerId },
{ authScope },
) => {
return [];
};
if (!authScope) {
throw new GraphQLError("Unauthenticated", {
extensions: {
code: 401,
},
});
}

return await sql<Location[]>`
SELECT
l.locationuuid AS id,
l.locationnameid AS name_id,
l.locationparentid AS parent_id
FROM public.location AS l
INNER JOIN public.customer AS c
ON l.locationcustomerid = c.customerid
WHERE
c.customeruuid = ${customerId};
`;
};
3 changes: 2 additions & 1 deletion lib/schema/resolvers/Tag.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { TagResolvers } from "./../__generated__/types.generated";
import type { TagResolvers } from "@/schema";

export const Tag: TagResolvers = {
/* Implement Tag resolver logic here */
};

0 comments on commit d30fbf4

Please sign in to comment.