Skip to content

Commit

Permalink
lint & format
Browse files Browse the repository at this point in the history
  • Loading branch information
o-az committed Nov 19, 2023
1 parent d295796 commit b859444
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 16 deletions.
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": ["biomejs.biome", "mikestead.dotenv", "EditorConfig.EditorConfig"],
"unwantedRecommendations": [
// we use Biome for linting and formatting so we don't need these
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
21 changes: 20 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"typescript.enablePromptUseWorkspaceTsdk": true,
"typescript.preferences.importModuleSpecifier": "non-relative"
"typescript.preferences.importModuleSpecifier": "non-relative",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"quickfix.biome": true,
"source.fixAll.biome": true,
"source.organizeImports.biome": true
},
"editor.defaultFormatter": "biomejs.biome",
"[json]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[jsonc]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[typescript]": {
"editor.defaultFormatter": "biomejs.biome"
},
"[javascript]": {
"editor.defaultFormatter": "biomejs.biome"
}
}
91 changes: 91 additions & 0 deletions biome.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"$schema": "https://biomejs.dev/schemas/1.3.3/schema.json",
"vcs": {
"root": ".",
"enabled": true,
"clientKind": "git"
},
"files": {
"include": [
"./**/*.ts",
"./**/*.js",
"./**/*.cjs",
"./**/*.d.ts",
"./**/*.json",
"./**/*.jsonc"
],
"ignoreUnknown": true,
"ignore": ["node_modules", ".lagon", "_"]
},
"organizeImports": {
"enabled": false
},
"formatter": {
"enabled": true,
"lineWidth": 100,
"indentWidth": 2,
"indentStyle": "space",
"formatWithErrors": true,
"include": [
"./**/*.ts",
"./**/*.js",
"./**/*.cjs",
"./**/*.d.ts",
"./**/*.json",
"./**/*.jsonc"
]
},
"linter": {
"enabled": true,
"rules": {
"all": true,
"style": {
"useBlockStatements": "off",
"useSelfClosingElements": "off",
"noUnusedTemplateLiteral": "off"
},
"nursery": {
"all": true,
"noUnusedImports": "off"
},
"complexity": {
"useLiteralKeys": "off"
},
"correctness": {
"noUndeclaredVariables": "off"
},
"suspicious": {
"noRedeclare": "off",
"noExplicitAny": "off",
"noEmptyInterface": "off"
}
}
},
"json": {
"parser": {
"allowComments": true
},
"formatter": {
"enabled": true,
"lineWidth": 100,
"indentWidth": 2
}
},
"javascript": {
"parser": {
"unsafeParameterDecoratorsEnabled": true
},
"formatter": {
"enabled": true,
"lineWidth": 100,
"indentWidth": 2,
"indentStyle": "space",
"quoteStyle": "single",
"trailingComma": "none",
"semicolons": "asNeeded",
"jsxQuoteStyle": "single",
"quoteProperties": "asNeeded",
"arrowParentheses": "asNeeded"
}
}
}
Binary file modified bun.lockb
Binary file not shown.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,16 @@
"dev": "lagon dev --env='.env.dev'",
"build": "lagon build",
"deploy:preview": "lagon deploy",
"deploy": "lagon deploy --production"
"deploy": "lagon deploy --production",
"lint": "biome check --apply .",
"format": "biome format . --write",
"typecheck": "tsc --project tsconfig.json --noEmit"
},
"dependencies": {
"graphql": "^16.8.1"
},
"devDependencies": {
"@biomejs/biome": "^1.3.3",
"bun-types": "^1.0.13",
"typescript": "^5.2.2"
},
Expand Down
10 changes: 5 additions & 5 deletions src/graphql/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
printSchema,
buildClientSchema,
getIntrospectionQuery,
type IntrospectionOptions,
type IntrospectionOptions
} from 'graphql'
import type { Json } from '#/types.ts'

Expand All @@ -14,24 +14,24 @@ export function jsonSchemaToSDL(jsonString: string) {

export async function fetchJsonSchema({
url,
minimal = true,
minimal = true
}: {
url: string
minimal?: boolean
}): Promise<Json> {
const introspectionOptions = {
descriptions: !minimal,
directiveIsRepeatable: !minimal,
schemaDescription: !minimal,
schemaDescription: !minimal
} satisfies IntrospectionOptions
try {
const response = await fetch(url, {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({
query: getIntrospectionQuery(introspectionOptions),
variable: {},
}),
variable: {}
})
})

if (!response.ok) throw new Error(`Failed to fetch from ${url}: ${response.statusText}`)
Expand Down
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function handler(request: Request): Promise<Response> {
const { htmlPage } = await import('#/graphql/graphiql.html.ts')
return new Response(htmlPage({ endpoint: introspectionURL }), {
status: 200,
headers: { 'Content-Type': 'text/html' },
headers: { 'Content-Type': 'text/html' }
})
}

Expand All @@ -42,13 +42,13 @@ export async function handler(request: Request): Promise<Response> {

return new Response(sdlSchema, {
status: sdlSchema.startsWith('Encountered an error') ? 400 : 200,
headers: { 'Content-Type': 'text/plain' },
headers: { 'Content-Type': 'text/plain' }
})
}

return new Response(JSON.stringify(jsonSchema), {
status: 200,
headers: { 'Content-Type': 'application/json' },
headers: { 'Content-Type': 'application/json' }
})
} catch (error) {
const message = error instanceof Error ? error.message : `Encountered an error: ${error}`
Expand Down
8 changes: 2 additions & 6 deletions src/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export const BASE_URL = process.env.BASE_URL ?? 'https://introspect.lagon.dev'

export const EXAMPLE_GRAPHQL_URL = 'https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3'

export const LANDING_MESSAGE = /* md */`
export const LANDING_MESSAGE = /* md */ `
If you want a JSON GraphQL schema, the format is:
${BASE_URL}/json/<introspection-url>
Expand All @@ -20,11 +20,7 @@ Source code: https://github.com/o-az/introspect
`

export function isURL(str: string) {
try {
return !!new URL(str)
} catch {
return false
}
return !!new URL(str)
}

export function formatMessages(...messages: string[]) {
Expand Down

0 comments on commit b859444

Please sign in to comment.