Skip to content

Commit

Permalink
improve: Node 18 tsconfig and ES2023 lib (#794)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt committed Apr 22, 2024
1 parent cc2dc55 commit 05308fa
Show file tree
Hide file tree
Showing 9 changed files with 294 additions and 292 deletions.
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,26 +84,27 @@
"@graphql-typed-document-node/core": "^3.2.0",
"@molt/command": "^0.9.0",
"dprint": "^0.45.1",
"zod": "^3.22.5"
"zod": "^3.23.0"
},
"peerDependencies": {
"graphql": "14 - 16"
},
"devDependencies": {
"@pothos/core": "^3.41.1",
"@pothos/plugin-simple-objects": "^3.7.0",
"@tsconfig/node16": "^16.1.3",
"@tsconfig/node18": "^18.2.4",
"@tsconfig/strictest": "^2.0.5",
"@types/body-parser": "^1.19.5",
"@types/express": "^4.17.21",
"@types/json-bigint": "^1.0.4",
"@types/node": "^20.12.7",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"@typescript-eslint/eslint-plugin": "^7.7.1",
"@typescript-eslint/parser": "^7.7.1",
"apollo-server-express": "^3.13.0",
"body-parser": "^1.20.2",
"doctoc": "^2.2.1",
"dripip": "^0.10.0",
"eslint": "^9.0.0",
"eslint": "^9.1.1",
"eslint-config-prisma": "^0.6.0",
"eslint-plugin-deprecation": "^2.0.0",
"eslint-plugin-only-warn": "^1.1.0",
Expand All @@ -119,9 +120,9 @@
"happy-dom": "^14.7.1",
"json-bigint": "^1.0.0",
"tsx": "^4.7.2",
"type-fest": "^4.15.0",
"type-fest": "^4.16.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.7.0",
"typescript-eslint": "^7.7.1",
"vitest": "^1.5.0"
}
}
516 changes: 259 additions & 257 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

6 changes: 2 additions & 4 deletions src/client/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,7 @@ export const create = <$Input extends Input>(
const documentString = SelectionSet.selectionSet(documentObjectEncoded)
// todo variables
const result = await executeDocumentExpression({ document: documentString })
// @ts-expect-error todo make global available in TS...
if (result.errors && (result.errors.length > 0)) throw new AggregateError(result.errors) // eslint-disable-line
if (result.errors && (result.errors.length > 0)) throw new AggregateError(result.errors)
// todo check for errors
const dataDecoded = CustomScalars.decode(rootIndex, result.data)
return { ...result, data: dataDecoded }
Expand Down Expand Up @@ -169,8 +168,7 @@ export const create = <$Input extends Input>(
switch (returnMode) {
case `data`: {
if (result.errors && result.errors.length > 0) {
// @ts-expect-error fixme -- get this global available
throw new AggregateError(result.errors) // eslint-disable-line
throw new AggregateError(result.errors)
}
return result.data
}
Expand Down
14 changes: 7 additions & 7 deletions src/entrypoints/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import {
type BatchRequestsExtendedOptions,
type BatchRequestsOptions,
} from '../raw/functions/batchRequests.js'
import { RequestExtendedOptions } from '../raw/functions/request.js'
import type { RequestExtendedOptions } from '../raw/functions/request.js'
import { request } from '../raw/functions/request.js'
import type { GraphQLResponse, RequestMiddleware, ResponseMiddleware } from '../raw/helpers/types.js'
import { RawRequestOptions, RequestDocument, RequestOptions, Variables } from '../raw/helpers/types.js'
import type { RawRequestOptions, RequestDocument, RequestOptions, Variables } from '../raw/helpers/types.js'
export { GraphQLClient } from '../raw/classes/GraphQLClient.js'
export { batchRequests } from '../raw/functions/batchRequests.js'
export { gql } from '../raw/functions/gql.js'
Expand All @@ -19,13 +19,13 @@ export {
BatchRequestsOptions,
ClientError,
GraphQLResponse,
RawRequestOptions,
type RawRequestOptions,
request,
RequestDocument,
RequestExtendedOptions,
type RequestDocument,
type RequestExtendedOptions,
RequestMiddleware,
RequestOptions,
type RequestOptions,
ResponseMiddleware,
Variables,
type Variables,
}
export default request
6 changes: 3 additions & 3 deletions src/generator/code/SchemaRuntime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const index = (config: Config) => {
`
}

const union = (config: Config, type: GraphQLUnionType) => {
const union = (_config: Config, type: GraphQLUnionType) => {
// todo probably need thunks here
const members = type.getTypes().map(t => t.name).join(`, `)
return `
Expand All @@ -103,7 +103,7 @@ const interface$ = (config: Config, type: GraphQLInterfaceType) => {
return `export const ${type.name} = $.Interface(\`${type.name}\`, {${fields}}, [${implementors}])`
}

const enum$ = (config: Config, type: GraphQLEnumType) => {
const enum$ = (_config: Config, type: GraphQLEnumType) => {
const members = type.getValues().map((value) => {
return `\`${value.name}\``
}).join(`, `)
Expand Down Expand Up @@ -156,7 +156,7 @@ const renderArg = (config: Config, arg: GraphQLArgument) => {
return `${arg.name}: ${type}`
}

const scalar = (config: Config, type: GraphQLScalarType) => {
const scalar = (_config: Config, type: GraphQLScalarType) => {
return `$Scalar.${type.name}`
}

Expand Down
1 change: 0 additions & 1 deletion src/lib/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ export const getNodeName = (node: Describable): NodeNamePlus => {
return `GraphQLScalarType`
default:
return `GraphQLField`
throw new Error(`Unknown node type: ${node.name}`)
}
}

Expand Down
2 changes: 0 additions & 2 deletions tests/raw/exports.ts

This file was deleted.

4 changes: 2 additions & 2 deletions tests/raw/general.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ describe(`middleware`, () => {
await client.batchRequests([
{
document: `query x($foo: String) { foo(foo: $foo) }`,
variables: {foo: `bar`},
variables: { foo: `bar` },
},
])
expect(responseMiddleware).toBeCalledTimes(1)
Expand All @@ -156,7 +156,7 @@ describe(`middleware`, () => {
variables: [{ foo: `bar` }],
})
})
});
})
})

describe(`async request middleware`, () => {
Expand Down
22 changes: 13 additions & 9 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
{
"extends": "@tsconfig/node16/tsconfig.json",
"extends": [
"@tsconfig/strictest/tsconfig.json",
"@tsconfig/node18/tsconfig.json"
],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2020"],
"lib": ["DOM", "DOM.Iterable", "ES2023"],

// Use ESM
"module": "NodeNext",
"moduleResolution": "nodenext",

// Make the compiler stricter, catch more errors
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
// TODO enable, leads to lots of errors currently.
"exactOptionalPropertyTypes": false,
// We handle these with ESLint:
"noUnusedLocals": false,
"noUnusedParameters": false,

// DX
"sourceMap": true,
Expand All @@ -23,7 +26,8 @@

// Other
"skipLibCheck": true,
"esModuleInterop": true
"esModuleInterop": true,
"isolatedModules": false
},
"include": ["src", "tests", "examples"],
"exclude": ["build"]
Expand Down

0 comments on commit 05308fa

Please sign in to comment.