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

Geofence config #69

Merged
merged 3 commits into from
Nov 12, 2024
Merged

Geofence config #69

merged 3 commits into from
Nov 12, 2024

Conversation

JaredHightower-Tendrel
Copy link
Contributor

No description provided.

import type { WithKey } from "@/util";
import Dataloader from "dataloader";
import type { Request } from "express";
import { GraphQLError } from "graphql/error";
import { sql } from "./postgres";

export default (_: Request) =>
new Dataloader<string, Location>(async keys => {
const rows = await sql<WithKey<Location>[]>`
new Dataloader<string, Location & Geofence>(async keys => {
Copy link
Contributor

Choose a reason for hiding this comment

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

shouldnt need Location & Geofence right? since type Location below has a geofence property. or maybe im misreading that bit

Copy link
Member

Choose a reason for hiding this comment

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

No, you're reading right but these types are a little misleading. We aren't grabbing a full Location, but rather a smaller subset: just the scalar properties and foreign key references. The Location resolver (capital L Location.ts) then uses the foreign keys to resolve those objects (if the user asks for them).

In the case of geofence, it is an object and it is easier to build that object in js than sql. So we're just flattening its fields when we grab it from sql, and then bundling them into an object in the Location resolver.

Kinda janky. Definitely a little misleading. The newer stuff (Checklist) does all of this a little better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was needed for the LocationResolvers to pick up the geofence types
Screenshot 2024-11-12 at 10 56 40 AM

schema/legacy/resolvers/Location.ts Outdated Show resolved Hide resolved
schema/legacy/resolvers/Geofence.ts Outdated Show resolved Hide resolved
@JaredHightower-Tendrel JaredHightower-Tendrel merged commit fc2a966 into main Nov 12, 2024
3 checks passed
@JaredHightower-Tendrel JaredHightower-Tendrel deleted the feat/geo-fence-config branch November 12, 2024 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants