Skip to content
Merged
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
25 changes: 25 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Deploy

on:
push:
branches:
- main

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.9
- name: Install worker dependencies
run: bun install --frozen-lockfile
- name: Publish worker
run: |
bun publish
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
28 changes: 22 additions & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,28 @@
name: test
name: Test

on: [push]
on:
push:
branches-ignore:
- main

jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: oven-sh/setup-bun@v2
- run: bun install
- run: bun test
- name: Checkout
uses: actions/checkout@v4
- name: Install bun
uses: oven-sh/setup-bun@v2
with:
bun-version: 1.3.9
- name: Install worker dependencies
run: bun install --frozen-lockfile
- name: Typecheck
run: bun typecheck
- name: Run tests
run: bun test
- name: Test deploy
run: bun deploy:dryrun
env:
CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
7 changes: 7 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"singleQuote": true,
"semi": false,
"tabWidth": 2,
"printWidth": 80,
"plugins": ["prettier-plugin-organize-imports"]
}
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"files.associations": {
"wrangler.json": "jsonc"
}
}
255 changes: 155 additions & 100 deletions bun.lock

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{
"scripts": {
"dev": "wrangler dev"
"dev": "wrangler dev",
"deploy": "wrangler deploy --minify",
"deploy:dryrun": "wrangler deploy --minify --dry-run",
"typecheck": "tsgo --noEmit",
"watch": "tsgo --noEmit -w"
},
"dependencies": {
"@graphql-tools/utils": "^10.9.1",
Expand All @@ -20,15 +24,17 @@
"@eslint/js": "^9.33.0",
"@graphql-eslint/eslint-plugin": "^4.4.0",
"@graphql-tools/executor-http": "^2.1.1",
"@types/bun": "1.3.9",
"@types/iso-3166-2": "^1.0.4",
"@types/provinces": "^1.11.6",
"eslint": "^9.33.0",
"@typescript/native-preview": "7.0.0-dev.20260220.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-simple-import-sort": "^12.1.1",
"prettier": "3.6.2",
"typescript": "^5.9.2",
"eslint": "^9.33.0",
"prettier-plugin-organize-imports": "4.3.0",
"prettier": "3.8.1",
"typescript-eslint": "^8.39.1",
"wrangler": "^4.30.0"
"wrangler": "4.67.0"
}
}
73 changes: 37 additions & 36 deletions src/graphql.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { buildHTTPExecutor } from "@graphql-tools/executor-http";
import { countries } from "countries-list";
import { parse } from "graphql";
import { buildHTTPExecutor } from '@graphql-tools/executor-http'
import { expect, it } from 'bun:test'
import { countries } from 'countries-list'
import { parse } from 'graphql'

import { yoga } from "./graphql";
import { yoga } from './graphql'

const executor = buildHTTPExecutor({
fetch: yoga.fetch,
endpoint: "http://yoga/graphql",
});
endpoint: 'http://yoga/graphql',
})

const ListFilteredCountriesQuery = parse(/* GraphQL */ `
query ListFilteredCountries($filter: CountryFilterInput) {
Expand All @@ -16,78 +17,78 @@ const ListFilteredCountriesQuery = parse(/* GraphQL */ `
code
}
}
`);
`)

function assertSingleValue<TValue extends object>(
value: TValue | AsyncIterable<TValue>,
): asserts value is TValue {
if (Symbol.asyncIterator in value) {
throw new Error("Expected single value");
throw new Error('Expected single value')
}
}

it("returns filtered data", async () => {
it('returns filtered data', async () => {
const result = await executor({
document: ListFilteredCountriesQuery,
variables: {
filter: {
code: {
in: ["US", "CA"],
in: ['US', 'CA'],
},
},
},
});
})

assertSingleValue(result);
assertSingleValue(result)

expect(result.data?.countries).toHaveLength(2);
});
expect(result.data?.countries).toHaveLength(2)
})

it("filters names using a regular expression", async () => {
it('filters names using a regular expression', async () => {
const result = await executor({
document: ListFilteredCountriesQuery,
variables: {
filter: {
name: {
regex: "^United",
regex: '^United',
},
},
},
});
})

assertSingleValue(result);
assertSingleValue(result)

expect(result.data?.countries).toHaveLength(3);
});
expect(result.data?.countries).toHaveLength(3)
})

it("filters a single value", async () => {
it('filters a single value', async () => {
const result = await executor({
document: ListFilteredCountriesQuery,
variables: {
filter: {
code: {
eq: "US",
eq: 'US',
},
},
},
});
})

assertSingleValue(result);
assertSingleValue(result)

expect(result.data?.countries).toHaveLength(1);
});
expect(result.data?.countries).toHaveLength(1)
})

it("returns all data if no filter is provided", async () => {
it('returns all data if no filter is provided', async () => {
const result = await executor({
document: ListFilteredCountriesQuery,
});
})

assertSingleValue(result);
assertSingleValue(result)

expect(result.data?.countries).toHaveLength(Object.keys(countries).length);
});
expect(result.data?.countries).toHaveLength(Object.keys(countries).length)
})

it("returns data about country subdivisions", async () => {
it('returns data about country subdivisions', async () => {
const result = await executor({
document: parse(/* GraphQL */ `
query ListBritishSubdivisions {
Expand All @@ -98,9 +99,9 @@ it("returns data about country subdivisions", async () => {
}
}
`),
});
})

assertSingleValue(result);
assertSingleValue(result)

expect(result.data?.country.subdivisions).toHaveLength(4);
});
expect(result.data?.country.subdivisions).toHaveLength(4)
})
6 changes: 4 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
"esModuleInterop": true,
"isolatedModules": true,
"strict": true,
"resolveJsonModule": true
}
"resolveJsonModule": true,
"skipLibCheck": true,
"types": ["bun"]
},
}
Loading