diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 0be3875d..ad61698d 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -16,6 +16,9 @@ module.exports = { ignoreRestSiblings: true, }, ], + // TODO: Enable this rule when we can turn it on for the website + // and example projects. + // "@typescript-eslint/consistent-type-imports": "error", "no-constant-condition": ["error", { checkLoops: false }], "no-constant-binary-expression": "error", }, diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 02484461..a034bb6f 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -57,7 +57,7 @@ jobs: - name: Build # Integration tests depend upon having .js versions created by tsc run: pnpm run build - name: Unit Tests - run: pnpm run test + run: pnpm run testCI lint: name: "Lint" runs-on: ubuntu-latest diff --git a/examples/express-graphql-http/tsconfig.json b/examples/express-graphql-http/tsconfig.json index 3b3157a9..189471e1 100644 --- a/examples/express-graphql-http/tsconfig.json +++ b/examples/express-graphql-http/tsconfig.json @@ -1,11 +1,4 @@ { - // Most ts-node options can be specified here using their programmatic names. - "ts-node": { - "files": true, - // It is faster to skip typechecking. - // Remove if you want ts-node to do typechecking. - "transpileOnly": false - }, "grats": { "nullableByDefault": false }, diff --git a/examples/express-graphql/tsconfig.json b/examples/express-graphql/tsconfig.json index 19178f89..fbfc985c 100644 --- a/examples/express-graphql/tsconfig.json +++ b/examples/express-graphql/tsconfig.json @@ -1,11 +1,4 @@ { - // Most ts-node options can be specified here using their programmatic names. - "ts-node": { - // It is faster to skip typechecking. - // Remove if you want ts-node to do typechecking. - "files": true, - "transpileOnly": true - }, "grats": { "nullableByDefault": false }, diff --git a/examples/production-app/models/PostConnection.ts b/examples/production-app/models/PostConnection.ts index 8c4db6d7..b5acfca7 100644 --- a/examples/production-app/models/PostConnection.ts +++ b/examples/production-app/models/PostConnection.ts @@ -1,8 +1,8 @@ -import { GqlInfo, Int } from "grats"; +import type { GqlInfo, Int } from "grats"; import * as DB from "../Database"; -import { VC } from "../ViewerContext"; -import { Post } from "./Post"; -import { Connection } from "../graphql/Connection"; +import type { VC } from "../ViewerContext"; +import type { Post } from "./Post"; +import type { Connection } from "../graphql/Connection"; import { connectionFromSelectOrCount } from "../graphql/gqlUtils.js"; /** diff --git a/package.json b/package.json index 0492714b..ae251bed 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,8 @@ "!dist/src/tests" ], "scripts": { - "test": "ts-node src/tests/test.ts", + "test": "node --experimental-strip-types src/tests/test.ts", + "testCI": "node dist/tests/test.js", "integration-tests": "node src/tests/integration.mjs", "build": "rm -rf dist/ && tsc --build", "format": "prettier . --write", @@ -19,8 +20,8 @@ "dependencies": { "commander": "^10.0.0", "graphql": "^16.9.0", - "typescript": "5.5.4", - "semver": "^7.5.4" + "semver": "^7.5.4", + "typescript": "5.8.3" }, "devDependencies": { "@types/node": "^18.14.6", @@ -32,8 +33,7 @@ "node-fetch": "^3.3.1", "path-browserify": "^1.0.1", "prettier": "^2.8.7", - "process": "^0.11.10", - "ts-node": "^10.9.1" + "process": "^0.11.10" }, "prettier": { "trailingComma": "all" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a42aee28..af3f7ddf 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -18,8 +18,8 @@ importers: specifier: ^7.5.4 version: 7.5.4 typescript: - specifier: 5.5.4 - version: 5.5.4 + specifier: 5.8.3 + version: 5.8.3 devDependencies: '@types/node': specifier: ^18.14.6 @@ -29,10 +29,10 @@ importers: version: 7.5.6 '@typescript-eslint/eslint-plugin': specifier: ^5.55.0 - version: 5.55.0(@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.5.4))(eslint@8.36.0)(typescript@5.5.4) + version: 5.55.0(@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.8.3))(eslint@8.36.0)(typescript@5.8.3) '@typescript-eslint/parser': specifier: ^5.55.0 - version: 5.55.0(eslint@8.36.0)(typescript@5.5.4) + version: 5.55.0(eslint@8.36.0)(typescript@5.8.3) eslint: specifier: ^8.36.0 version: 8.36.0 @@ -51,9 +51,6 @@ importers: process: specifier: ^0.11.10 version: 0.11.10 - ts-node: - specifier: ^10.9.1 - version: 10.9.1(@types/node@18.15.0)(typescript@5.5.4) examples/apollo-server: dependencies: @@ -9819,20 +9816,6 @@ packages: resolution: {integrity: sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==} engines: {node: '>=6.10'} - ts-node@10.9.1: - resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==} - hasBin: true - peerDependencies: - '@swc/core': '>=1.2.50' - '@swc/wasm': '>=1.2.50' - '@types/node': '*' - typescript: '>=2.7' - peerDependenciesMeta: - '@swc/core': - optional: true - '@swc/wasm': - optional: true - ts-node@10.9.2: resolution: {integrity: sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==} hasBin: true @@ -9906,6 +9889,11 @@ packages: engines: {node: '>=14.17'} hasBin: true + typescript@5.8.3: + resolution: {integrity: sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ==} + engines: {node: '>=14.17'} + hasBin: true + uid-safe@2.1.5: resolution: {integrity: sha512-KPHm4VL5dDXKz01UuEd88Df+KzynaohSL9fBh096KWAxSKZQDI2uBrVqtvRM4rwrIrRRKsdLNML/lnaaVSRioA==} engines: {node: '>= 0.8'} @@ -15111,34 +15099,34 @@ snapshots: '@types/node': 20.8.10 optional: true - '@typescript-eslint/eslint-plugin@5.55.0(@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.5.4))(eslint@8.36.0)(typescript@5.5.4)': + '@typescript-eslint/eslint-plugin@5.55.0(@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.8.3))(eslint@8.36.0)(typescript@5.8.3)': dependencies: '@eslint-community/regexpp': 4.4.0 - '@typescript-eslint/parser': 5.55.0(eslint@8.36.0)(typescript@5.5.4) + '@typescript-eslint/parser': 5.55.0(eslint@8.36.0)(typescript@5.8.3) '@typescript-eslint/scope-manager': 5.55.0 - '@typescript-eslint/type-utils': 5.55.0(eslint@8.36.0)(typescript@5.5.4) - '@typescript-eslint/utils': 5.55.0(eslint@8.36.0)(typescript@5.5.4) + '@typescript-eslint/type-utils': 5.55.0(eslint@8.36.0)(typescript@5.8.3) + '@typescript-eslint/utils': 5.55.0(eslint@8.36.0)(typescript@5.8.3) debug: 4.3.4(supports-color@9.3.1) eslint: 8.36.0 grapheme-splitter: 1.0.4 ignore: 5.2.4 natural-compare-lite: 1.4.0 semver: 7.5.4 - tsutils: 3.21.0(typescript@5.5.4) + tsutils: 3.21.0(typescript@5.8.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.8.3 transitivePeerDependencies: - supports-color - '@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.5.4)': + '@typescript-eslint/parser@5.55.0(eslint@8.36.0)(typescript@5.8.3)': dependencies: '@typescript-eslint/scope-manager': 5.55.0 '@typescript-eslint/types': 5.55.0 - '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.8.3) debug: 4.3.4(supports-color@9.3.1) eslint: 8.36.0 optionalDependencies: - typescript: 5.5.4 + typescript: 5.8.3 transitivePeerDependencies: - supports-color @@ -15147,15 +15135,15 @@ snapshots: '@typescript-eslint/types': 5.55.0 '@typescript-eslint/visitor-keys': 5.55.0 - '@typescript-eslint/type-utils@5.55.0(eslint@8.36.0)(typescript@5.5.4)': + '@typescript-eslint/type-utils@5.55.0(eslint@8.36.0)(typescript@5.8.3)': dependencies: - '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.5.4) - '@typescript-eslint/utils': 5.55.0(eslint@8.36.0)(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.8.3) + '@typescript-eslint/utils': 5.55.0(eslint@8.36.0)(typescript@5.8.3) debug: 4.3.4(supports-color@9.3.1) eslint: 8.36.0 - tsutils: 3.21.0(typescript@5.5.4) + tsutils: 3.21.0(typescript@5.8.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.8.3 transitivePeerDependencies: - supports-color @@ -15163,7 +15151,7 @@ snapshots: '@typescript-eslint/types@5.62.0': {} - '@typescript-eslint/typescript-estree@5.55.0(typescript@5.5.4)': + '@typescript-eslint/typescript-estree@5.55.0(typescript@5.8.3)': dependencies: '@typescript-eslint/types': 5.55.0 '@typescript-eslint/visitor-keys': 5.55.0 @@ -15171,9 +15159,9 @@ snapshots: globby: 11.1.0 is-glob: 4.0.3 semver: 7.5.4 - tsutils: 3.21.0(typescript@5.5.4) + tsutils: 3.21.0(typescript@5.8.3) optionalDependencies: - typescript: 5.5.4 + typescript: 5.8.3 transitivePeerDependencies: - supports-color @@ -15191,14 +15179,14 @@ snapshots: transitivePeerDependencies: - supports-color - '@typescript-eslint/utils@5.55.0(eslint@8.36.0)(typescript@5.5.4)': + '@typescript-eslint/utils@5.55.0(eslint@8.36.0)(typescript@5.8.3)': dependencies: '@eslint-community/eslint-utils': 4.2.0(eslint@8.36.0) '@types/json-schema': 7.0.11 '@types/semver': 7.5.6 '@typescript-eslint/scope-manager': 5.55.0 '@typescript-eslint/types': 5.55.0 - '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.5.4) + '@typescript-eslint/typescript-estree': 5.55.0(typescript@5.8.3) eslint: 8.36.0 eslint-scope: 5.1.1 semver: 7.5.4 @@ -18291,7 +18279,7 @@ snapshots: history@4.10.1: dependencies: - '@babel/runtime': 7.24.0 + '@babel/runtime': 7.26.0 loose-envify: 1.4.0 resolve-pathname: 3.0.0 tiny-invariant: 1.3.1 @@ -22376,24 +22364,6 @@ snapshots: ts-dedent@2.2.0: {} - ts-node@10.9.1(@types/node@18.15.0)(typescript@5.5.4): - dependencies: - '@cspotcode/source-map-support': 0.8.1 - '@tsconfig/node10': 1.0.9 - '@tsconfig/node12': 1.0.11 - '@tsconfig/node14': 1.0.3 - '@tsconfig/node16': 1.0.3 - '@types/node': 18.15.0 - acorn: 8.8.2 - acorn-walk: 8.2.0 - arg: 4.1.3 - create-require: 1.1.1 - diff: 4.0.2 - make-error: 1.3.6 - typescript: 5.5.4 - v8-compile-cache-lib: 3.0.1 - yn: 3.1.1 - ts-node@10.9.2(@types/node@18.15.0)(typescript@5.5.4): dependencies: '@cspotcode/source-map-support': 0.8.1 @@ -22423,6 +22393,11 @@ snapshots: tslib: 1.14.1 typescript: 5.5.4 + tsutils@3.21.0(typescript@5.8.3): + dependencies: + tslib: 1.14.1 + typescript: 5.8.3 + type-check@0.3.2: dependencies: prelude-ls: 1.1.2 @@ -22454,6 +22429,8 @@ snapshots: typescript@5.5.4: {} + typescript@5.8.3: {} + uid-safe@2.1.5: dependencies: random-bytes: 1.0.0 diff --git a/src/Errors.ts b/src/Errors.ts index f41ee240..070fa5b6 100644 --- a/src/Errors.ts +++ b/src/Errors.ts @@ -13,7 +13,7 @@ import { CONTEXT_TAG, INFO_TAG, DIRECTIVE_TAG, -} from "./Extractor"; +} from "./Extractor.ts"; export const ISSUE_URL = "https://github.com/captbaritone/grats/issues"; diff --git a/src/Extractor.ts b/src/Extractor.ts index 5d080a98..2070d2f1 100644 --- a/src/Extractor.ts +++ b/src/Extractor.ts @@ -1,7 +1,6 @@ -import { +import type { FieldDefinitionNode, InputValueDefinitionNode, - Kind, NamedTypeNode, NameNode, TypeNode, @@ -13,40 +12,38 @@ import { ConstObjectFieldNode, ConstObjectValueNode, ConstListValueNode, - assertName, DefinitionNode, +} from "graphql"; +import { assertName } from "graphql"; +import { + Kind, version as graphqlJSVersion, TokenKind, GraphQLError, } from "graphql"; import { gte as semverGte } from "semver"; -import { - tsErr, - tsRelated, +import type { DiagnosticsResult, - gqlErr, DiagnosticResult, -} from "./utils/DiagnosticError"; -import { err, ok } from "./utils/Result"; +} from "./utils/DiagnosticError.ts"; +import { tsErr, tsRelated, gqlErr } from "./utils/DiagnosticError.ts"; +import { err, ok } from "./utils/Result.ts"; import * as ts from "typescript"; -import { - DeclarationDefinition, - NameDefinition, - UNRESOLVED_REFERENCE_NAME, -} from "./TypeContext"; -import * as E from "./Errors"; -import { traverseJSDocTags } from "./utils/JSDoc"; -import { GraphQLConstructor } from "./GraphQLConstructor"; -import { relativePath } from "./gratsRoot"; -import { ISSUE_URL } from "./Errors"; -import { detectInvalidComments } from "./comments"; -import { extend, invariant } from "./utils/helpers"; -import * as Act from "./CodeActions"; -import { +import type { DeclarationDefinition, NameDefinition } from "./TypeContext.ts"; +import { UNRESOLVED_REFERENCE_NAME } from "./TypeContext.ts"; +import * as E from "./Errors.ts"; +import { traverseJSDocTags } from "./utils/JSDoc.ts"; +import { GraphQLConstructor } from "./GraphQLConstructor.ts"; +import { relativePath } from "./gratsRoot.mts"; +import { ISSUE_URL } from "./Errors.ts"; +import { detectInvalidComments } from "./comments.ts"; +import { extend, invariant } from "./utils/helpers.ts"; +import * as Act from "./CodeActions.ts"; +import type { InputValueDefinitionNodeOrResolverArg, ResolverArgument, -} from "./resolverSignature"; -import { Parser } from "graphql/language/parser"; +} from "./resolverSignature.ts"; +import { Parser } from "graphql/language/parser.js"; export const LIBRARY_IMPORT_NAME = "grats"; export const LIBRARY_NAME = "Grats"; diff --git a/src/GraphQLAstExtensions.ts b/src/GraphQLAstExtensions.ts index 49dd02b3..6b434abc 100644 --- a/src/GraphQLAstExtensions.ts +++ b/src/GraphQLAstExtensions.ts @@ -1,4 +1,4 @@ -import { ResolverSignature } from "./resolverSignature"; +import type { ResolverSignature } from "./resolverSignature.ts"; /** * In most cases we can use directives to annotate constructs diff --git a/src/GraphQLConstructor.ts b/src/GraphQLConstructor.ts index d18a6ab2..2b09d249 100644 --- a/src/GraphQLConstructor.ts +++ b/src/GraphQLConstructor.ts @@ -1,12 +1,7 @@ -import { - Kind, +import type { ListTypeNode, NamedTypeNode, - Location as GraphQLLocation, NameNode, - Source, - Token, - TokenKind, TypeNode, NonNullTypeNode, StringValueNode, @@ -34,13 +29,23 @@ import { DirectiveDefinitionNode, EnumValueNode, } from "graphql"; -import * as ts from "typescript"; -import { uniqueId } from "./utils/helpers"; -import { DiagnosticResult, TsLocatableNode } from "./utils/DiagnosticError"; import { + Source, + Kind, + Token, + TokenKind, + Location as GraphQLLocation, +} from "graphql"; +import * as ts from "typescript"; +import { uniqueId } from "./utils/helpers.ts"; +import type { + DiagnosticResult, + TsLocatableNode, +} from "./utils/DiagnosticError.ts"; +import type { InputValueDefinitionNodeOrResolverArg, ResolverSignature, -} from "./resolverSignature"; +} from "./resolverSignature.ts"; export class GraphQLConstructor { /* Top Level Types */ diff --git a/src/InterfaceGraph.ts b/src/InterfaceGraph.ts index b1710fa0..435123be 100644 --- a/src/InterfaceGraph.ts +++ b/src/InterfaceGraph.ts @@ -1,6 +1,7 @@ -import { TypeContext } from "./TypeContext"; -import { DefaultMap } from "./utils/helpers"; -import { DefinitionNode, Kind } from "graphql"; +import type { TypeContext } from "./TypeContext.ts"; +import { DefaultMap } from "./utils/helpers.ts"; +import type { DefinitionNode } from "graphql"; +import { Kind } from "graphql"; export type InterfaceImplementor = { kind: "TYPE" | "INTERFACE"; name: string }; export type InterfaceMap = DefaultMap>; diff --git a/src/Locate.ts b/src/Locate.ts index 48067f91..74b1014d 100644 --- a/src/Locate.ts +++ b/src/Locate.ts @@ -1,12 +1,12 @@ +import type { GraphQLSchema, Location } from "graphql"; import { GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, - GraphQLSchema, - Location, } from "graphql"; -import { Result, err, ok } from "./utils/Result"; -import { nullThrows } from "./utils/helpers"; +import type { Result } from "./utils/Result.ts"; +import { err, ok } from "./utils/Result.ts"; +import { nullThrows } from "./utils/helpers.ts"; type EntityName = { parent: string; diff --git a/src/TypeContext.ts b/src/TypeContext.ts index e0c7e4eb..c6852f65 100644 --- a/src/TypeContext.ts +++ b/src/TypeContext.ts @@ -1,4 +1,4 @@ -import { +import type { InputObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, NameNode, @@ -6,18 +6,16 @@ import { UnionTypeDefinitionNode, } from "graphql"; import * as ts from "typescript"; -import { - gqlErr, +import type { DiagnosticResult, - tsErr, - gqlRelated, DiagnosticsResult, FixableDiagnosticWithLocation, -} from "./utils/DiagnosticError"; -import { err, ok } from "./utils/Result"; -import * as E from "./Errors"; -import { ExtractionSnapshot } from "./Extractor"; -import { ResolverArgument } from "./resolverSignature"; +} from "./utils/DiagnosticError.ts"; +import { gqlErr, tsErr, gqlRelated } from "./utils/DiagnosticError.ts"; +import { err, ok } from "./utils/Result.ts"; +import * as E from "./Errors.ts"; +import type { ExtractionSnapshot } from "./Extractor.ts"; +import type { ResolverArgument } from "./resolverSignature.ts"; export const UNRESOLVED_REFERENCE_NAME = `__UNRESOLVED_REFERENCE__`; diff --git a/src/cli.ts b/src/cli.ts index 1cbfd849..e4322fca 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,26 +1,25 @@ #!/usr/bin/env node -import * as E from "./Errors"; -import { GraphQLNamedType, GraphQLObjectType, Location } from "graphql"; -import { getParsedTsConfig } from "./"; -import { - SchemaAndDoc, - buildSchemaAndDocResult, - extractSchemaAndDoc, -} from "./lib"; +import * as E from "./Errors.ts"; +import type { GraphQLNamedType, Location } from "graphql"; +import { GraphQLObjectType } from "graphql"; +import { getParsedTsConfig } from "./index.ts"; +import type { SchemaAndDoc } from "./lib.ts"; +import { buildSchemaAndDocResult, extractSchemaAndDoc } from "./lib.ts"; import { Command } from "commander"; import { writeFileSync } from "fs"; import { resolve, dirname } from "path"; -import { version } from "../package.json"; -import { locate } from "./Locate"; -import { printGratsSDL, printExecutableSchema } from "./printSchema"; +import { locate } from "./Locate.ts"; +import { printGratsSDL, printExecutableSchema } from "./printSchema.ts"; import * as ts from "typescript"; import { locationlessErr, ReportableDiagnostics, -} from "./utils/DiagnosticError"; -import { GratsConfig, ParsedCommandLineGrats } from "./gratsConfig"; -import { err, ok, Result } from "./utils/Result"; +} from "./utils/DiagnosticError.ts"; +import type { GratsConfig, ParsedCommandLineGrats } from "./gratsConfig.ts"; +import type { Result } from "./utils/Result.ts"; +import { err, ok } from "./utils/Result.ts"; +import { version } from "../package.json"; const program = new Command(); diff --git a/src/codegen/TSAstBuilder.ts b/src/codegen/TSAstBuilder.ts index 0f081459..63cb43e9 100644 --- a/src/codegen/TSAstBuilder.ts +++ b/src/codegen/TSAstBuilder.ts @@ -1,7 +1,7 @@ import * as ts from "typescript"; -import { isNonNull } from "../utils/helpers"; +import { isNonNull } from "../utils/helpers.ts"; import * as path from "path"; -import { resolveRelativePath } from "../gratsRoot"; +import { resolveRelativePath } from "../gratsRoot.mts"; type JsonObject = { [key: string]: JsonValue }; type JsonArray = JsonValue[]; @@ -24,11 +24,13 @@ export default class TSAstBuilder { imports: Map = new Map(); _helpers: ts.Statement[] = []; _statements: ts.Statement[] = []; + private _destination: string; + private importModuleSpecifierEnding: string; - constructor( - private _destination: string, - private importModuleSpecifierEnding: string, - ) {} + constructor(_destination: string, importModuleSpecifierEnding: string) { + this._destination = _destination; + this.importModuleSpecifierEnding = importModuleSpecifierEnding; + } addHelper(statement: ts.Statement) { this._helpers.push(statement); } diff --git a/src/codegen/resolverCodegen.ts b/src/codegen/resolverCodegen.ts index 6338d940..3e40db28 100644 --- a/src/codegen/resolverCodegen.ts +++ b/src/codegen/resolverCodegen.ts @@ -1,13 +1,17 @@ -import { ConstDirectiveNode, GraphQLField } from "graphql"; +import type { ConstDirectiveNode, GraphQLField } from "graphql"; import * as ts from "typescript"; -import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives"; +import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives.ts"; import { ASSERT_NON_NULL_HELPER, createAssertNonNullHelper, -} from "../codegenHelpers"; -import { nullThrows } from "../utils/helpers"; -import { ResolverArgument, ResolverDefinition, Metadata } from "../metadata"; -import TSAstBuilder from "./TSAstBuilder"; +} from "../codegenHelpers.ts"; +import { nullThrows } from "../utils/helpers.ts"; +import type { + ResolverArgument, + ResolverDefinition, + Metadata, +} from "../metadata.ts"; +import type TSAstBuilder from "./TSAstBuilder.ts"; const RESOLVER_ARGS = ["source", "args", "context", "info"] as const; @@ -19,9 +23,14 @@ const F = ts.factory; * for any codegen that needs to generate resolver methods. */ export default class ResolverCodegen { + public ts: TSAstBuilder; + public _resolvers: Metadata; _helpers: Set = new Set(); _derivedContextNames: Map = new Map(); - constructor(public ts: TSAstBuilder, public _resolvers: Metadata) {} + constructor(ts: TSAstBuilder, _resolvers: Metadata) { + this.ts = ts; + this._resolvers = _resolvers; + } resolveMethod( fieldName: string, methodName: string, diff --git a/src/codegen/resolverMapCodegen.ts b/src/codegen/resolverMapCodegen.ts index 055874cf..22eb0147 100644 --- a/src/codegen/resolverMapCodegen.ts +++ b/src/codegen/resolverMapCodegen.ts @@ -1,9 +1,10 @@ import * as ts from "typescript"; -import { GratsConfig } from "../gratsConfig"; -import TSAstBuilder from "./TSAstBuilder"; -import ResolverCodegen from "./resolverCodegen"; -import { Metadata, FieldDefinition } from "../metadata"; -import { GraphQLObjectType, GraphQLSchema } from "graphql"; +import type { GratsConfig } from "../gratsConfig.ts"; +import TSAstBuilder from "./TSAstBuilder.ts"; +import ResolverCodegen from "./resolverCodegen.ts"; +import type { Metadata, FieldDefinition } from "../metadata.ts"; +import type { GraphQLSchema } from "graphql"; +import { GraphQLObjectType } from "graphql"; const F = ts.factory; @@ -33,13 +34,17 @@ export function resolverMapCodegen( class Codegen { ts: TSAstBuilder; resolvers: ResolverCodegen; + _schema: GraphQLSchema; + _resolvers: Metadata; constructor( - public _schema: GraphQLSchema, - public _resolvers: Metadata, + _schema: GraphQLSchema, + _resolvers: Metadata, config: GratsConfig, destination: string, ) { + this._schema = _schema; + this._resolvers = _resolvers; this.ts = new TSAstBuilder(destination, config.importModuleSpecifierEnding); this.resolvers = new ResolverCodegen(this.ts, _resolvers); } diff --git a/src/codegen/schemaCodegen.ts b/src/codegen/schemaCodegen.ts index 28fe8425..737695d7 100644 --- a/src/codegen/schemaCodegen.ts +++ b/src/codegen/schemaCodegen.ts @@ -1,4 +1,4 @@ -import { +import type { GraphQLAbstractType, GraphQLArgument, GraphQLDirective, @@ -14,6 +14,8 @@ import { GraphQLScalarType, GraphQLSchema, GraphQLUnionType, +} from "graphql"; +import { isEnumType, isInputObjectType, isInputType, @@ -27,13 +29,14 @@ import { valueFromASTUntyped, } from "graphql"; import * as ts from "typescript"; -import { extend, nullThrows } from "../utils/helpers"; -import { GratsConfig } from "../gratsConfig.js"; -import { naturalCompare } from "../utils/naturalCompare"; -import TSAstBuilder, { JsonValue } from "./TSAstBuilder"; -import ResolverCodegen from "./resolverCodegen"; -import { Metadata } from "../metadata"; -import { ConstDirectiveNode } from "graphql/language"; +import { extend, nullThrows } from "../utils/helpers.ts"; +import type { GratsConfig } from "../gratsConfig.ts"; +import { naturalCompare } from "../utils/naturalCompare.ts"; +import type { JsonValue } from "./TSAstBuilder.ts"; +import TSAstBuilder from "./TSAstBuilder.ts"; +import ResolverCodegen from "./resolverCodegen.ts"; +import type { Metadata } from "../metadata.ts"; +import type { ConstDirectiveNode } from "graphql/language/index.js"; // These directives will be added to the schema by default, so we don't need to // include them in the generated schema. @@ -68,15 +71,17 @@ class Codegen { _typeNameMappings: Map = new Map(); _typeDefinitions: Set = new Set(); _graphQLImports: Set = new Set(); + _schema: GraphQLSchema; constructor( - public _schema: GraphQLSchema, + _schema: GraphQLSchema, _resolvers: Metadata, config: GratsConfig, destination: string, ) { this.ts = new TSAstBuilder(destination, config.importModuleSpecifierEnding); this.resolvers = new ResolverCodegen(this.ts, _resolvers); + this._schema = _schema; } graphQLImport(name: string): ts.Identifier { diff --git a/src/comments.ts b/src/comments.ts index 670f70f9..8846881a 100644 --- a/src/comments.ts +++ b/src/comments.ts @@ -1,8 +1,8 @@ import * as ts from "typescript"; -import { rangeErr } from "./utils/DiagnosticError"; -import * as E from "./Errors"; -import * as Act from "./CodeActions"; -import { ALL_TAGS, KILLS_PARENT_ON_EXCEPTION_TAG } from "./Extractor"; +import { rangeErr } from "./utils/DiagnosticError.ts"; +import * as E from "./Errors.ts"; +import * as Act from "./CodeActions.ts"; +import { ALL_TAGS, KILLS_PARENT_ON_EXCEPTION_TAG } from "./Extractor.ts"; // A line that starts with optional *s followed by @gql or @killsParentOnException const BLOCK_COMMENT_REGEX = diff --git a/src/gratsConfig.ts b/src/gratsConfig.ts index c5019e2f..aa75b0f3 100644 --- a/src/gratsConfig.ts +++ b/src/gratsConfig.ts @@ -1,4 +1,4 @@ -import * as ts from "typescript"; +import type * as ts from "typescript"; export type GratsConfig = { // Where Grats should write your schema file. Path is relative to the diff --git a/src/gratsRoot.ts b/src/gratsRoot.mts similarity index 82% rename from src/gratsRoot.ts rename to src/gratsRoot.mts index 3e5b00db..8b39587a 100644 --- a/src/gratsRoot.ts +++ b/src/gratsRoot.mts @@ -1,4 +1,7 @@ -import { relative, resolve, join } from "path"; +import { relative, resolve, join, dirname } from "path"; +import { fileURLToPath } from "url"; + +const __dirname = dirname(fileURLToPath(import.meta.url)); // Grats parses TypeScript files and finds resolvers. If the field resolver is a // named export, Grats needs to be able to import that file during execution. diff --git a/src/index.ts b/src/index.ts index 1c0605a6..6c00f9d1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,15 +1,16 @@ import * as ts from "typescript"; -import { ParsedCommandLineGrats, validateGratsOptions } from "./gratsConfig"; -import { ReportableDiagnostics } from "./utils/DiagnosticError"; -import { err, ok } from "./utils/Result"; -import { Result } from "./utils/Result"; +import type { ParsedCommandLineGrats } from "./gratsConfig.ts"; +import { validateGratsOptions } from "./gratsConfig.ts"; +import { ReportableDiagnostics } from "./utils/DiagnosticError.ts"; +import { err, ok } from "./utils/Result.ts"; +import type { Result } from "./utils/Result.ts"; -export { printSDLWithoutMetadata } from "./printSchema"; -export * from "./Types"; -export * from "./lib"; +export { printSDLWithoutMetadata } from "./printSchema.ts"; +export * from "./Types.ts"; +export * from "./lib.ts"; // Used by the experimental TypeScript plugin -export { extract } from "./Extractor"; -export { codegen } from "./codegen/schemaCodegen"; +export { extract } from "./Extractor.ts"; +export { codegen } from "./codegen/schemaCodegen.ts"; // #FIXME: Report diagnostics instead of throwing! export function getParsedTsConfig( diff --git a/src/lib.ts b/src/lib.ts index bff6cae1..57b446ce 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,49 +1,43 @@ +import type { DocumentNode, GraphQLError, GraphQLSchema } from "graphql"; +import { buildASTSchema, Kind, validateSchema } from "graphql"; +import type { DiagnosticsWithoutLocationResult } from "./utils/DiagnosticError.ts"; import { - buildASTSchema, - DocumentNode, - GraphQLError, - GraphQLSchema, - Kind, - validateSchema, -} from "graphql"; -import { - DiagnosticsWithoutLocationResult, - ReportableDiagnostics, graphQlErrorToDiagnostic, -} from "./utils/DiagnosticError"; -import { concatResults, ResultPipe } from "./utils/Result"; -import { ok, err } from "./utils/Result"; -import { Result } from "./utils/Result"; + ReportableDiagnostics, +} from "./utils/DiagnosticError.ts"; +import { concatResults, ResultPipe } from "./utils/Result.ts"; +import { ok, err } from "./utils/Result.ts"; +import type { Result } from "./utils/Result.ts"; import * as ts from "typescript"; -import { ExtractionSnapshot } from "./Extractor"; -import { TypeContext } from "./TypeContext"; -import { validateSDL } from "graphql/validation/validate"; -import { ParsedCommandLineGrats } from "./gratsConfig"; -import { validateTypenames } from "./validations/validateTypenames"; -import { extractSnapshotsFromProgram } from "./transforms/snapshotsFromProgram"; -import { validateMergedInterfaces } from "./validations/validateMergedInterfaces"; -import { addInterfaceFields } from "./transforms/addInterfaceFields"; -import { filterNonGqlInterfaces } from "./transforms/filterNonGqlInterfaces"; -import { validateAsyncIterable } from "./validations/validateAsyncIterable"; -import { applyDefaultNullability } from "./transforms/applyDefaultNullability"; -import { mergeExtensions } from "./transforms/mergeExtensions"; -import { sortSchemaAst } from "./transforms/sortSchemaAst"; -import { validateDuplicateContextOrInfo } from "./validations/validateDuplicateContextOrInfo"; -import { validateSemanticNullability } from "./validations/validateSemanticNullability"; -import { resolveTypes } from "./transforms/resolveTypes"; -import { resolveResolverParams } from "./transforms/resolveResolverParams"; -import { customSpecValidations } from "./validations/customSpecValidations"; -import { makeResolverSignature } from "./transforms/makeResolverSignature"; -import { addImplicitRootTypes } from "./transforms/addImplicitRootTypes"; -import { Metadata } from "./metadata"; -import { validateDirectiveArguments } from "./validations/validateDirectiveArguments"; -import { coerceDefaultEnumValues } from "./transforms/coerceDefaultEnumValues"; +import type { ExtractionSnapshot } from "./Extractor.ts"; +import { TypeContext } from "./TypeContext.ts"; +import { validateSDL } from "graphql/validation/validate.js"; +import type { ParsedCommandLineGrats } from "./gratsConfig.ts"; +import { validateTypenames } from "./validations/validateTypenames.ts"; +import { extractSnapshotsFromProgram } from "./transforms/snapshotsFromProgram.ts"; +import { validateMergedInterfaces } from "./validations/validateMergedInterfaces.ts"; +import { addInterfaceFields } from "./transforms/addInterfaceFields.ts"; +import { filterNonGqlInterfaces } from "./transforms/filterNonGqlInterfaces.ts"; +import { validateAsyncIterable } from "./validations/validateAsyncIterable.ts"; +import { applyDefaultNullability } from "./transforms/applyDefaultNullability.ts"; +import { mergeExtensions } from "./transforms/mergeExtensions.ts"; +import { sortSchemaAst } from "./transforms/sortSchemaAst.ts"; +import { validateDuplicateContextOrInfo } from "./validations/validateDuplicateContextOrInfo.ts"; +import { validateSemanticNullability } from "./validations/validateSemanticNullability.ts"; +import { resolveTypes } from "./transforms/resolveTypes.ts"; +import { resolveResolverParams } from "./transforms/resolveResolverParams.ts"; +import { customSpecValidations } from "./validations/customSpecValidations.ts"; +import { makeResolverSignature } from "./transforms/makeResolverSignature.ts"; +import { addImplicitRootTypes } from "./transforms/addImplicitRootTypes.ts"; +import type { Metadata } from "./metadata.ts"; +import { validateDirectiveArguments } from "./validations/validateDirectiveArguments.ts"; +import { coerceDefaultEnumValues } from "./transforms/coerceDefaultEnumValues.ts"; // Export the TypeScript plugin implementation used by // grats-ts-plugin -export { initTsPlugin } from "./tsPlugin/initTsPlugin"; +export { initTsPlugin } from "./tsPlugin/initTsPlugin.ts"; -export { GratsConfig } from "./gratsConfig"; +export type { GratsConfig } from "./gratsConfig.ts"; export type SchemaAndDoc = { schema: GraphQLSchema; diff --git a/src/printSchema.ts b/src/printSchema.ts index 186576dc..f6b07b44 100644 --- a/src/printSchema.ts +++ b/src/printSchema.ts @@ -1,14 +1,9 @@ -import { - DocumentNode, - GraphQLSchema, - print, - visit, - specifiedScalarTypes, -} from "graphql"; -import { GratsConfig } from "./gratsConfig"; -import { codegen } from "./codegen/schemaCodegen"; -import { Metadata } from "./metadata"; -import { resolverMapCodegen } from "./codegen/resolverMapCodegen"; +import type { DocumentNode, GraphQLSchema } from "graphql"; +import { print, visit, specifiedScalarTypes } from "graphql"; +import type { GratsConfig } from "./gratsConfig.ts"; +import { codegen } from "./codegen/schemaCodegen.ts"; +import type { Metadata } from "./metadata.ts"; +import { resolverMapCodegen } from "./codegen/resolverMapCodegen.ts"; /** * Prints code for a TypeScript module that exports a GraphQLSchema. diff --git a/src/publicDirectives.ts b/src/publicDirectives.ts index 31a470ca..2392b468 100644 --- a/src/publicDirectives.ts +++ b/src/publicDirectives.ts @@ -1,12 +1,11 @@ -import { +import type { ConstDirectiveNode, DefinitionNode, DocumentNode, - Kind, Location, - parse, } from "graphql"; -import { uniqueId } from "./utils/helpers"; +import { Kind, parse } from "graphql"; +import { uniqueId } from "./utils/helpers.ts"; /** * Grats supports some additional, non-spec server directives in order to diff --git a/src/resolverSignature.ts b/src/resolverSignature.ts index 390e7508..400c3bef 100644 --- a/src/resolverSignature.ts +++ b/src/resolverSignature.ts @@ -1,5 +1,5 @@ import * as ts from "typescript"; -import { +import type { ConstDirectiveNode, ConstValueNode, InputValueDefinitionNode, @@ -9,7 +9,7 @@ import { StringValueNode, TypeNode, } from "graphql"; -import { DiagnosticResult } from "./utils/DiagnosticError"; +import type { DiagnosticResult } from "./utils/DiagnosticError.ts"; /** * Describes the backing resolver for a field. This broadly matches the metadata diff --git a/src/tests/TestRunner.ts b/src/tests/TestRunner.ts index 7cc519cf..bf570ce2 100644 --- a/src/tests/TestRunner.ts +++ b/src/tests/TestRunner.ts @@ -1,7 +1,7 @@ import * as fs from "fs"; import * as path from "path"; import { diff } from "jest-diff"; -import { ask } from "./yesNo"; +import { ask } from "./yesNo.ts"; type Transformer = ( code: string, diff --git a/src/tests/integrationFixtures/aliasedMethod/schema.ts b/src/tests/integrationFixtures/aliasedMethod/schema.ts index 833b3516..f232f8a1 100644 --- a/src/tests/integrationFixtures/aliasedMethod/schema.ts +++ b/src/tests/integrationFixtures/aliasedMethod/schema.ts @@ -1,4 +1,4 @@ -import { someType as querySomeTypeResolver } from "./index"; +import { someType as querySomeTypeResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql"; export function getSchema(): GraphQLSchema { const SomeTypeType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/complexDefaultInput/schema.ts b/src/tests/integrationFixtures/complexDefaultInput/schema.ts index 27a2eb66..d8ce3804 100644 --- a/src/tests/integrationFixtures/complexDefaultInput/schema.ts +++ b/src/tests/integrationFixtures/complexDefaultInput/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLInputObjectType } from "graphql"; export function getSchema(): GraphQLSchema { const SomeObjType: GraphQLInputObjectType = new GraphQLInputObjectType({ diff --git a/src/tests/integrationFixtures/complexPlurals/schema.ts b/src/tests/integrationFixtures/complexPlurals/schema.ts index 27a6bd49..c7abdf4d 100644 --- a/src/tests/integrationFixtures/complexPlurals/schema.ts +++ b/src/tests/integrationFixtures/complexPlurals/schema.ts @@ -1,4 +1,4 @@ -import { arrayOfArrayOfPromises as queryArrayOfArrayOfPromisesResolver, arrayOfPromises as queryArrayOfPromisesResolver, asyncIterableOfArrayOfPromises as queryAsyncIterableOfArrayOfPromisesResolver } from "./index"; +import { arrayOfArrayOfPromises as queryArrayOfArrayOfPromisesResolver, arrayOfPromises as queryArrayOfPromisesResolver, asyncIterableOfArrayOfPromises as queryAsyncIterableOfArrayOfPromisesResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLList, GraphQLNonNull, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/connectionExample/index.ts b/src/tests/integrationFixtures/connectionExample/index.ts index 08a1581c..6c5fc659 100644 --- a/src/tests/integrationFixtures/connectionExample/index.ts +++ b/src/tests/integrationFixtures/connectionExample/index.ts @@ -1,4 +1,4 @@ -import { Int } from "../../../Types"; +import type { Int } from "../../../index.ts"; /** @gqlQueryField */ export function firstHundredIntegers(args: { @@ -35,7 +35,12 @@ class FirstHundredIntegersConnection { /** @gqlField */ edges: FirstHundredIntegersEdge[]; - constructor(public first?: number | null, public after?: string | null) { + first?: number | null; + after?: string | null; + + constructor(first?: number | null, after?: string | null) { + this.first = first; + this.after = after; const start = parseInt(after || "0", 10); const end = first ? start + first : this._max; diff --git a/src/tests/integrationFixtures/connectionExample/index.ts.expected b/src/tests/integrationFixtures/connectionExample/index.ts.expected index 5f3695ba..5774aedc 100644 --- a/src/tests/integrationFixtures/connectionExample/index.ts.expected +++ b/src/tests/integrationFixtures/connectionExample/index.ts.expected @@ -1,7 +1,7 @@ ----------------- INPUT ----------------- -import { Int } from "../../../Types"; +import type { Int } from "../../../index.ts"; /** @gqlQueryField */ export function firstHundredIntegers(args: { @@ -38,7 +38,12 @@ class FirstHundredIntegersConnection { /** @gqlField */ edges: FirstHundredIntegersEdge[]; - constructor(public first?: number | null, public after?: string | null) { + first?: number | null; + after?: string | null; + + constructor(first?: number | null, after?: string | null) { + this.first = first; + this.after = after; const start = parseInt(after || "0", 10); const end = first ? start + first : this._max; diff --git a/src/tests/integrationFixtures/connectionExample/schema.ts b/src/tests/integrationFixtures/connectionExample/schema.ts index 9578451b..d9178952 100644 --- a/src/tests/integrationFixtures/connectionExample/schema.ts +++ b/src/tests/integrationFixtures/connectionExample/schema.ts @@ -1,4 +1,4 @@ -import { firstHundredIntegers as queryFirstHundredIntegersResolver } from "./index"; +import { firstHundredIntegers as queryFirstHundredIntegersResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLList, GraphQLNonNull, GraphQLString, GraphQLInt, GraphQLBoolean } from "graphql"; export function getSchema(): GraphQLSchema { const FirstHundredIntegersEdgeType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/deprecated/schema.ts b/src/tests/integrationFixtures/deprecated/schema.ts index dd5d1088..1ef5ca3d 100644 --- a/src/tests/integrationFixtures/deprecated/schema.ts +++ b/src/tests/integrationFixtures/deprecated/schema.ts @@ -1,4 +1,4 @@ -import { goodBye as queryGoodByeResolver, hello as queryHelloResolver } from "./index"; +import { goodBye as queryGoodByeResolver, hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/derivedContext/schema.ts b/src/tests/integrationFixtures/derivedContext/schema.ts index 7e9f687a..cc1f706c 100644 --- a/src/tests/integrationFixtures/derivedContext/schema.ts +++ b/src/tests/integrationFixtures/derivedContext/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver, derived as derived } from "./index"; +import { hello as queryHelloResolver, derived as derived } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/enumDefault/schema.ts b/src/tests/integrationFixtures/enumDefault/schema.ts index fd094a21..40f08987 100644 --- a/src/tests/integrationFixtures/enumDefault/schema.ts +++ b/src/tests/integrationFixtures/enumDefault/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLEnumType } from "graphql"; export function getSchema(): GraphQLSchema { const GreetingOptionsType: GraphQLEnumType = new GraphQLEnumType({ diff --git a/src/tests/integrationFixtures/explicitNullPassedToArgWithDefault/schema.ts b/src/tests/integrationFixtures/explicitNullPassedToArgWithDefault/schema.ts index 8ce5d9ca..c7e159a2 100644 --- a/src/tests/integrationFixtures/explicitNullPassedToArgWithDefault/schema.ts +++ b/src/tests/integrationFixtures/explicitNullPassedToArgWithDefault/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/functionField/schema.ts b/src/tests/integrationFixtures/functionField/schema.ts index 3c86c7a4..7df8e760 100644 --- a/src/tests/integrationFixtures/functionField/schema.ts +++ b/src/tests/integrationFixtures/functionField/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/functionFieldRenamed/schema.ts b/src/tests/integrationFixtures/functionFieldRenamed/schema.ts index 579d9b43..384021d2 100644 --- a/src/tests/integrationFixtures/functionFieldRenamed/schema.ts +++ b/src/tests/integrationFixtures/functionFieldRenamed/schema.ts @@ -1,4 +1,4 @@ -import { notHello as queryHelloResolver } from "./index"; +import { notHello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/getAcessor/schema.ts b/src/tests/integrationFixtures/getAcessor/schema.ts index f768891b..05f74b73 100644 --- a/src/tests/integrationFixtures/getAcessor/schema.ts +++ b/src/tests/integrationFixtures/getAcessor/schema.ts @@ -1,4 +1,4 @@ -import { me as queryMeResolver } from "./index"; +import { me as queryMeResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const UserType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/inputTypeOneOf/index.ts b/src/tests/integrationFixtures/inputTypeOneOf/index.ts index c22f9570..7439101e 100644 --- a/src/tests/integrationFixtures/inputTypeOneOf/index.ts +++ b/src/tests/integrationFixtures/inputTypeOneOf/index.ts @@ -1,4 +1,4 @@ -import { ID } from "../../.."; +import type { ID } from "../../../index.ts"; /** @gqlInput */ type UserPayload = { diff --git a/src/tests/integrationFixtures/inputTypeOneOf/index.ts.expected b/src/tests/integrationFixtures/inputTypeOneOf/index.ts.expected index 95b513d9..4269bf93 100644 --- a/src/tests/integrationFixtures/inputTypeOneOf/index.ts.expected +++ b/src/tests/integrationFixtures/inputTypeOneOf/index.ts.expected @@ -1,7 +1,7 @@ ----------------- INPUT ----------------- -import { ID } from "../../.."; +import type { ID } from "../../../index.ts"; /** @gqlInput */ type UserPayload = { diff --git a/src/tests/integrationFixtures/inputTypeOneOf/schema.ts b/src/tests/integrationFixtures/inputTypeOneOf/schema.ts index edfe1d80..5b73be49 100644 --- a/src/tests/integrationFixtures/inputTypeOneOf/schema.ts +++ b/src/tests/integrationFixtures/inputTypeOneOf/schema.ts @@ -1,4 +1,4 @@ -import { greet as queryGreetResolver } from "./index"; +import { greet as queryGreetResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLInputObjectType, GraphQLID } from "graphql"; export function getSchema(): GraphQLSchema { const UserPayloadType: GraphQLInputObjectType = new GraphQLInputObjectType({ diff --git a/src/tests/integrationFixtures/killsParentOnException/schema.ts b/src/tests/integrationFixtures/killsParentOnException/schema.ts index d38eed97..675762e0 100644 --- a/src/tests/integrationFixtures/killsParentOnException/schema.ts +++ b/src/tests/integrationFixtures/killsParentOnException/schema.ts @@ -1,4 +1,4 @@ -import { me as queryMeResolver } from "./index"; +import { me as queryMeResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const UserType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/killsParentOnExceptionOnQuery/schema.ts b/src/tests/integrationFixtures/killsParentOnExceptionOnQuery/schema.ts index 9cdc6b32..97d6e17c 100644 --- a/src/tests/integrationFixtures/killsParentOnExceptionOnQuery/schema.ts +++ b/src/tests/integrationFixtures/killsParentOnExceptionOnQuery/schema.ts @@ -1,4 +1,4 @@ -import { alwaysThrowsKillsParentOnException as queryAlwaysThrowsKillsParentOnExceptionResolver, hello as queryHelloResolver } from "./index"; +import { alwaysThrowsKillsParentOnException as queryAlwaysThrowsKillsParentOnExceptionResolver, hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/killsParentOnExceptionReturnsNull/schema.ts b/src/tests/integrationFixtures/killsParentOnExceptionReturnsNull/schema.ts index d38eed97..675762e0 100644 --- a/src/tests/integrationFixtures/killsParentOnExceptionReturnsNull/schema.ts +++ b/src/tests/integrationFixtures/killsParentOnExceptionReturnsNull/schema.ts @@ -1,4 +1,4 @@ -import { me as queryMeResolver } from "./index"; +import { me as queryMeResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLNonNull, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const UserType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/nonNullArgWithDefault/schema.ts b/src/tests/integrationFixtures/nonNullArgWithDefault/schema.ts index 6d548619..d80f9b59 100644 --- a/src/tests/integrationFixtures/nonNullArgWithDefault/schema.ts +++ b/src/tests/integrationFixtures/nonNullArgWithDefault/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/nonNullEnumDefault/schema.ts b/src/tests/integrationFixtures/nonNullEnumDefault/schema.ts index 20eae9c6..d0450535 100644 --- a/src/tests/integrationFixtures/nonNullEnumDefault/schema.ts +++ b/src/tests/integrationFixtures/nonNullEnumDefault/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLEnumType } from "graphql"; export function getSchema(): GraphQLSchema { const GreetingOptionsType: GraphQLEnumType = new GraphQLEnumType({ diff --git a/src/tests/integrationFixtures/nonNullableListIncludesNull/schema.ts b/src/tests/integrationFixtures/nonNullableListIncludesNull/schema.ts index 8b1c4da5..e5d837be 100644 --- a/src/tests/integrationFixtures/nonNullableListIncludesNull/schema.ts +++ b/src/tests/integrationFixtures/nonNullableListIncludesNull/schema.ts @@ -1,4 +1,4 @@ -import { someList as querySomeListResolver, someListOfLists as querySomeListOfListsResolver } from "./index"; +import { someList as querySomeListResolver, someListOfLists as querySomeListOfListsResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLList, GraphQLNonNull, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/numericID/index.ts b/src/tests/integrationFixtures/numericID/index.ts index 11c29e11..9ac3ec20 100644 --- a/src/tests/integrationFixtures/numericID/index.ts +++ b/src/tests/integrationFixtures/numericID/index.ts @@ -1,4 +1,4 @@ -import { ID } from "../../../Types"; +import type { ID } from "../../../index.ts"; /** * Validating that graphql-js will coerce a numeric ID to a string. diff --git a/src/tests/integrationFixtures/numericID/index.ts.expected b/src/tests/integrationFixtures/numericID/index.ts.expected index eed9fbba..a17e1e5c 100644 --- a/src/tests/integrationFixtures/numericID/index.ts.expected +++ b/src/tests/integrationFixtures/numericID/index.ts.expected @@ -1,7 +1,7 @@ ----------------- INPUT ----------------- -import { ID } from "../../../Types"; +import type { ID } from "../../../index.ts"; /** * Validating that graphql-js will coerce a numeric ID to a string. diff --git a/src/tests/integrationFixtures/numericID/schema.ts b/src/tests/integrationFixtures/numericID/schema.ts index f11911ec..17b6c1ac 100644 --- a/src/tests/integrationFixtures/numericID/schema.ts +++ b/src/tests/integrationFixtures/numericID/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLID } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts b/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts deleted file mode 100644 index 9b9ee16d..00000000 --- a/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts +++ /dev/null @@ -1,20 +0,0 @@ -/** @gqlQueryField */ -export function me(): User { - return new User(); -} - -/** @gqlType */ -class User { - constructor( - /** @gqlField hello */ - public NOT_THIS: string = "world", - ) {} -} - -export const query = ` - query { - me { - hello - } - } -`; diff --git a/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts.expected b/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts.expected deleted file mode 100644 index 8ae15ad7..00000000 --- a/src/tests/integrationFixtures/parameterPropertyRenamed/index.ts.expected +++ /dev/null @@ -1,34 +0,0 @@ ------------------ -INPUT ------------------ -/** @gqlQueryField */ -export function me(): User { - return new User(); -} - -/** @gqlType */ -class User { - constructor( - /** @gqlField hello */ - public NOT_THIS: string = "world", - ) {} -} - -export const query = ` - query { - me { - hello - } - } -`; - ------------------ -OUTPUT ------------------ -{ - "data": { - "me": { - "hello": "world" - } - } -} \ No newline at end of file diff --git a/src/tests/integrationFixtures/parameterPropertyRenamed/schema.ts b/src/tests/integrationFixtures/parameterPropertyRenamed/schema.ts deleted file mode 100644 index bf226b8e..00000000 --- a/src/tests/integrationFixtures/parameterPropertyRenamed/schema.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { me as queryMeResolver } from "./index"; -import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; -export function getSchema(): GraphQLSchema { - const UserType: GraphQLObjectType = new GraphQLObjectType({ - name: "User", - fields() { - return { - hello: { - name: "hello", - type: GraphQLString, - resolve(source) { - return source.NOT_THIS; - } - } - }; - } - }); - const QueryType: GraphQLObjectType = new GraphQLObjectType({ - name: "Query", - fields() { - return { - me: { - name: "me", - type: UserType, - resolve() { - return queryMeResolver(); - } - } - }; - } - }); - return new GraphQLSchema({ - query: QueryType, - types: [QueryType, UserType] - }); -} diff --git a/src/tests/integrationFixtures/positionalNonNullArgWithDefault/schema.ts b/src/tests/integrationFixtures/positionalNonNullArgWithDefault/schema.ts index d930e887..3bc0219b 100644 --- a/src/tests/integrationFixtures/positionalNonNullArgWithDefault/schema.ts +++ b/src/tests/integrationFixtures/positionalNonNullArgWithDefault/schema.ts @@ -1,4 +1,4 @@ -import { hello as queryHelloResolver } from "./index"; +import { hello as queryHelloResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/promiseOfPromise/schema.ts b/src/tests/integrationFixtures/promiseOfPromise/schema.ts index 490660c0..44c876c8 100644 --- a/src/tests/integrationFixtures/promiseOfPromise/schema.ts +++ b/src/tests/integrationFixtures/promiseOfPromise/schema.ts @@ -1,4 +1,4 @@ -import { promiseOfPromise as queryPromiseOfPromiseResolver, promiseOfPromisePromise as queryPromiseOfPromisePromiseResolver } from "./index"; +import { promiseOfPromise as queryPromiseOfPromiseResolver, promiseOfPromisePromise as queryPromiseOfPromisePromiseResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/resolveTypeViaClass/index.ts b/src/tests/integrationFixtures/resolveTypeViaClass/index.ts index e5f7fc59..2082ac95 100644 --- a/src/tests/integrationFixtures/resolveTypeViaClass/index.ts +++ b/src/tests/integrationFixtures/resolveTypeViaClass/index.ts @@ -1,4 +1,4 @@ -import { ID } from "../../../Types"; +import type { ID } from "../../../index.ts"; /** @gqlInterface */ interface GqlNode { @@ -8,34 +8,38 @@ interface GqlNode { /** @gqlType */ export default class DefaultNode implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType */ export class User implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType RenamedNode */ export class ThisNameGetsIgnored implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType */ export class Guest implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } class AlsoUser extends User { diff --git a/src/tests/integrationFixtures/resolveTypeViaClass/index.ts.expected b/src/tests/integrationFixtures/resolveTypeViaClass/index.ts.expected index 28c80e50..766a0a3f 100644 --- a/src/tests/integrationFixtures/resolveTypeViaClass/index.ts.expected +++ b/src/tests/integrationFixtures/resolveTypeViaClass/index.ts.expected @@ -1,7 +1,7 @@ ----------------- INPUT ----------------- -import { ID } from "../../../Types"; +import type { ID } from "../../../index.ts"; /** @gqlInterface */ interface GqlNode { @@ -11,34 +11,38 @@ interface GqlNode { /** @gqlType */ export default class DefaultNode implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType */ export class User implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType RenamedNode */ export class ThisNameGetsIgnored implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } /** @gqlType */ export class Guest implements GqlNode { - constructor( - /** @gqlField */ - public id: ID, - ) {} + /** @gqlField */ + id: ID; + constructor(id: ID) { + this.id = id; + } } class AlsoUser extends User { diff --git a/src/tests/integrationFixtures/resolveTypeViaClass/schema.ts b/src/tests/integrationFixtures/resolveTypeViaClass/schema.ts index 4b2984b6..a1844cec 100644 --- a/src/tests/integrationFixtures/resolveTypeViaClass/schema.ts +++ b/src/tests/integrationFixtures/resolveTypeViaClass/schema.ts @@ -1,5 +1,5 @@ -import DefaultNodeClass from "./index"; -import { Guest as GuestClass, ThisNameGetsIgnored as RenamedNodeClass, User as UserClass, node as queryNodeResolver } from "./index"; +import DefaultNodeClass from "./index.ts"; +import { Guest as GuestClass, ThisNameGetsIgnored as RenamedNodeClass, User as UserClass, node as queryNodeResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLInterfaceType, GraphQLID, GraphQLNonNull } from "graphql"; export function getSchema(): GraphQLSchema { const GqlNodeType: GraphQLInterfaceType = new GraphQLInterfaceType({ diff --git a/src/tests/integrationFixtures/resolverErrorElidedToNull/schema.ts b/src/tests/integrationFixtures/resolverErrorElidedToNull/schema.ts index ad560b65..7042d62d 100644 --- a/src/tests/integrationFixtures/resolverErrorElidedToNull/schema.ts +++ b/src/tests/integrationFixtures/resolverErrorElidedToNull/schema.ts @@ -1,4 +1,4 @@ -import { alwaysThrows as queryAlwaysThrowsResolver } from "./index"; +import { alwaysThrows as queryAlwaysThrowsResolver } from "./index.ts"; import { GraphQLSchema, GraphQLObjectType, GraphQLString } from "graphql"; export function getSchema(): GraphQLSchema { const QueryType: GraphQLObjectType = new GraphQLObjectType({ diff --git a/src/tests/integrationFixtures/strictSemanticNullability/schema.ts b/src/tests/integrationFixtures/strictSemanticNullability/schema.ts index 20202d40..186b02b4 100644 --- a/src/tests/integrationFixtures/strictSemanticNullability/schema.ts +++ b/src/tests/integrationFixtures/strictSemanticNullability/schema.ts @@ -1,4 +1,4 @@ -import { actuallyReturnsAsyncNull as queryActuallyReturnsAsyncNullResolver, actuallyReturnsNull as queryActuallyReturnsNullResolver, me as queryMeResolver, names as subscriptionNamesResolver } from "./index"; +import { actuallyReturnsAsyncNull as queryActuallyReturnsAsyncNullResolver, actuallyReturnsNull as queryActuallyReturnsNullResolver, me as queryMeResolver, names as subscriptionNamesResolver } from "./index.ts"; import { defaultFieldResolver, GraphQLSchema, GraphQLDirective, DirectiveLocation, GraphQLList, GraphQLInt, GraphQLObjectType, GraphQLString, GraphQLInterfaceType } from "graphql"; async function assertNonNull(value: T | Promise): Promise { const awaited = await value; diff --git a/src/tests/test.ts b/src/tests/test.ts index cb762eed..6c0633ee 100644 --- a/src/tests/test.ts +++ b/src/tests/test.ts @@ -1,9 +1,9 @@ import * as path from "path"; -import TestRunner from "./TestRunner"; +import TestRunner from "./TestRunner.ts"; import { buildSchemaAndDocResult, buildSchemaAndDocResultWithHost, -} from "../lib"; +} from "../lib.ts"; import * as ts from "typescript"; import { buildASTSchema, @@ -14,20 +14,17 @@ import { specifiedScalarTypes, } from "graphql"; import { Command } from "commander"; -import { locate } from "../Locate"; -import { gqlErr, ReportableDiagnostics } from "../utils/DiagnosticError"; +import { locate } from "../Locate.ts"; +import { gqlErr, ReportableDiagnostics } from "../utils/DiagnosticError.ts"; import { writeFileSync } from "fs"; -import { codegen } from "../codegen/schemaCodegen"; +import { codegen } from "../codegen/schemaCodegen.ts"; import { diff } from "jest-diff"; import * as semver from "semver"; -import { - GratsConfig, - ParsedCommandLineGrats, - validateGratsOptions, -} from "../gratsConfig"; -import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives"; -import { applySDLHeader, applyTypeScriptHeader } from "../printSchema"; -import { extend } from "../utils/helpers"; +import type { GratsConfig, ParsedCommandLineGrats } from "../gratsConfig.ts"; +import { validateGratsOptions } from "../gratsConfig.ts"; +import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives.ts"; +import { applySDLHeader, applyTypeScriptHeader } from "../printSchema.ts"; +import { extend } from "../utils/helpers.ts"; const TS_VERSION = ts.version; @@ -69,9 +66,10 @@ program } }); -const gratsDir = path.join(__dirname, "../.."); -const fixturesDir = path.join(__dirname, "fixtures"); -const integrationFixturesDir = path.join(__dirname, "integrationFixtures"); +const gratsDir = path.join("."); +const testDir = path.join(gratsDir, "src", "tests"); +const fixturesDir = path.join(testDir, "fixtures"); +const integrationFixturesDir = path.join(testDir, "integrationFixtures"); const testDirs = [ { @@ -102,7 +100,7 @@ const testDirs = [ const files = [ `${fixturesDir}/${fileName}`, - path.join(__dirname, `../Types.ts`), + path.join(gratsDir, `src/Types.ts`), ]; let parsedOptions: ParsedCommandLineGrats; try { @@ -189,6 +187,7 @@ const testDirs = [ const firstLine = code.split("\n")[0]; let config: Partial = { nullableByDefault: true, + importModuleSpecifierEnding: ".ts", }; if (firstLine.startsWith("// {")) { const json = firstLine.slice(3); @@ -198,7 +197,7 @@ const testDirs = [ const filePath = `${integrationFixturesDir}/${fileName}`; const schemaPath = path.join(path.dirname(filePath), "schema.ts"); - const files = [filePath, path.join(__dirname, `../Types.ts`)]; + const files = [filePath, path.join(gratsDir, `src/Types.ts`)]; const parsedOptions: ParsedCommandLineGrats = validateGratsOptions({ options: { // Required to enable ts-node to locate function exports diff --git a/src/transforms/addImplicitRootTypes.ts b/src/transforms/addImplicitRootTypes.ts index 293cbec1..f71bc89b 100644 --- a/src/transforms/addImplicitRootTypes.ts +++ b/src/transforms/addImplicitRootTypes.ts @@ -1,13 +1,12 @@ -import { +import type { DocumentNode, - Kind, Location, NameNode, ObjectTypeDefinitionNode, - visit, } from "graphql"; -import { OPERATION_TYPES } from "../Extractor"; -import { nullThrows } from "../utils/helpers"; +import { Kind, visit } from "graphql"; +import { OPERATION_TYPES } from "../Extractor.ts"; +import { nullThrows } from "../utils/helpers.ts"; /** * Ensure any root types which have been extended with `@gqlQueryField` and diff --git a/src/transforms/addInterfaceFields.ts b/src/transforms/addInterfaceFields.ts index b2ecd37c..01588157 100644 --- a/src/transforms/addInterfaceFields.ts +++ b/src/transforms/addInterfaceFields.ts @@ -1,17 +1,18 @@ -import * as E from "../Errors"; -import * as ts from "typescript"; -import { DefinitionNode, Kind, ObjectTypeExtensionNode } from "graphql"; -import { TypeContext } from "../TypeContext"; -import { +import * as E from "../Errors.ts"; +import type * as ts from "typescript"; +import type { DefinitionNode, ObjectTypeExtensionNode } from "graphql"; +import { Kind } from "graphql"; +import type { TypeContext } from "../TypeContext.ts"; +import type { DiagnosticResult, DiagnosticsResult, - gqlErr, - gqlRelated, -} from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import { InterfaceMap, computeInterfaceMap } from "../InterfaceGraph"; -import { extend, nullThrows, uniqueId } from "../utils/helpers"; -import { FIELD_TAG } from "../Extractor"; +} from "../utils/DiagnosticError.ts"; +import { gqlErr, gqlRelated } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import type { InterfaceMap } from "../InterfaceGraph.ts"; +import { computeInterfaceMap } from "../InterfaceGraph.ts"; +import { extend, nullThrows, uniqueId } from "../utils/helpers.ts"; +import { FIELD_TAG } from "../Extractor.ts"; /** * Grats allows you to define GraphQL fields on TypeScript interfaces using diff --git a/src/transforms/applyDefaultNullability.ts b/src/transforms/applyDefaultNullability.ts index a313537c..139ae2b8 100644 --- a/src/transforms/applyDefaultNullability.ts +++ b/src/transforms/applyDefaultNullability.ts @@ -1,15 +1,17 @@ -import { DocumentNode, Kind, visit } from "graphql"; -import { DiagnosticsResult, gqlErr } from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import * as ts from "typescript"; -import * as E from "../Errors"; +import type { DocumentNode } from "graphql"; +import { Kind, visit } from "graphql"; +import type { DiagnosticsResult } from "../utils/DiagnosticError.ts"; +import { gqlErr } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import type * as ts from "typescript"; +import * as E from "../Errors.ts"; import { addSemanticNonNullDirective, makeSemanticNonNullDirective, -} from "../publicDirectives"; -import { GraphQLConstructor } from "../GraphQLConstructor"; -import { GratsConfig } from "../gratsConfig"; -import { nullThrows } from "../utils/helpers"; +} from "../publicDirectives.ts"; +import { GraphQLConstructor } from "../GraphQLConstructor.ts"; +import type { GratsConfig } from "../gratsConfig.ts"; +import { nullThrows } from "../utils/helpers.ts"; /** * Grats has options to make all fields nullable by default to conform to diff --git a/src/transforms/coerceDefaultEnumValues.ts b/src/transforms/coerceDefaultEnumValues.ts index b671b2ea..b147039f 100644 --- a/src/transforms/coerceDefaultEnumValues.ts +++ b/src/transforms/coerceDefaultEnumValues.ts @@ -1,17 +1,15 @@ -import { +import type { ConstObjectFieldNode, ConstValueNode, DefinitionNode, EnumTypeDefinitionNode, InputObjectTypeDefinitionNode, - isTypeDefinitionNode, - Kind, ListTypeNode, NamedTypeNode, TypeNode, - visit, } from "graphql"; -import { TypeContext } from "../TypeContext"; +import { Kind, visit, isTypeDefinitionNode } from "graphql"; +import type { TypeContext } from "../TypeContext.ts"; /** * This transform visits argument default values checking for values used in diff --git a/src/transforms/filterNonGqlInterfaces.ts b/src/transforms/filterNonGqlInterfaces.ts index b0047674..d3dd9587 100644 --- a/src/transforms/filterNonGqlInterfaces.ts +++ b/src/transforms/filterNonGqlInterfaces.ts @@ -1,5 +1,6 @@ -import { DefinitionNode, Kind, NamedTypeNode } from "graphql"; -import { TypeContext } from "../TypeContext"; +import type { DefinitionNode, NamedTypeNode } from "graphql"; +import { Kind } from "graphql"; +import type { TypeContext } from "../TypeContext.ts"; type InterfaceHaver = { readonly interfaces?: ReadonlyArray; diff --git a/src/transforms/makeResolverSignature.ts b/src/transforms/makeResolverSignature.ts index 1770cbaa..7ceaeb69 100644 --- a/src/transforms/makeResolverSignature.ts +++ b/src/transforms/makeResolverSignature.ts @@ -1,13 +1,14 @@ -import { DocumentNode, Kind } from "graphql"; -import { +import type { DocumentNode } from "graphql"; +import { Kind } from "graphql"; +import type { ResolverArgument, ResolverDefinition, Metadata, FieldDefinition, ContextArgs, -} from "../metadata"; -import { invariant, nullThrows } from "../utils/helpers"; -import { ResolverArgument as DirectiveResolverArgument } from "../resolverSignature"; +} from "../metadata.ts"; +import { invariant, nullThrows } from "../utils/helpers.ts"; +import type { ResolverArgument as DirectiveResolverArgument } from "../resolverSignature.ts"; export function makeResolverSignature(documentAst: DocumentNode): Metadata { const resolvers: Metadata = { diff --git a/src/transforms/mergeExtensions.ts b/src/transforms/mergeExtensions.ts index 48a4320f..693a3f54 100644 --- a/src/transforms/mergeExtensions.ts +++ b/src/transforms/mergeExtensions.ts @@ -1,5 +1,6 @@ -import { DocumentNode, FieldDefinitionNode, visit } from "graphql"; -import { extend } from "../utils/helpers"; +import type { DocumentNode, FieldDefinitionNode } from "graphql"; +import { visit } from "graphql"; +import { extend } from "../utils/helpers.ts"; /** * Takes every example of `extend type Foo` and `extend interface Foo` and diff --git a/src/transforms/resolveResolverParams.ts b/src/transforms/resolveResolverParams.ts index 312226bd..ebf4fda4 100644 --- a/src/transforms/resolveResolverParams.ts +++ b/src/transforms/resolveResolverParams.ts @@ -1,34 +1,28 @@ -import * as ts from "typescript"; -import { +import type * as ts from "typescript"; +import type { DefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, - Kind, - visit, } from "graphql"; -import { - DerivedResolverDefinition, - TypeContext, - UNRESOLVED_REFERENCE_NAME, -} from "../TypeContext"; -import { err, ok } from "../utils/Result"; -import { +import { Kind, visit } from "graphql"; +import type { DerivedResolverDefinition, TypeContext } from "../TypeContext.ts"; +import { UNRESOLVED_REFERENCE_NAME } from "../TypeContext.ts"; +import { err, ok } from "../utils/Result.ts"; +import { gqlErr, tsErr, tsRelated } from "../utils/DiagnosticError.ts"; +import type { DiagnosticsResult, FixableDiagnosticWithLocation, - gqlErr, - tsErr, - tsRelated, -} from "../utils/DiagnosticError"; -import { invariant, nullThrows } from "../utils/helpers"; -import { +} from "../utils/DiagnosticError.ts"; +import { invariant, nullThrows } from "../utils/helpers.ts"; +import type { ContextResolverArgument, DerivedContextResolverArgument, NamedResolverArgument, ResolverArgument, UnresolvedResolverArgument, -} from "../resolverSignature"; -import * as E from "../Errors"; -import { GraphQLConstructor } from "../GraphQLConstructor"; +} from "../resolverSignature.ts"; +import * as E from "../Errors.ts"; +import { GraphQLConstructor } from "../GraphQLConstructor.ts"; export function resolveResolverParams( ctx: TypeContext, diff --git a/src/transforms/resolveTypes.ts b/src/transforms/resolveTypes.ts index 3b9a4942..3b4f85bb 100644 --- a/src/transforms/resolveTypes.ts +++ b/src/transforms/resolveTypes.ts @@ -1,30 +1,28 @@ -import { +import type { ASTNode, DefinitionNode, InputObjectTypeDefinitionNode, InterfaceTypeDefinitionNode, - Kind, Location, NameNode, NamedTypeNode, ObjectTypeDefinitionNode, TypeDefinitionNode, UnionTypeDefinitionNode, - visit, } from "graphql"; -import { loc } from "../GraphQLConstructor"; -import { TypeContext } from "../TypeContext"; +import { Kind, visit } from "graphql"; +import { loc } from "../GraphQLConstructor.ts"; +import type { TypeContext } from "../TypeContext.ts"; import * as ts from "typescript"; -import { err, ok } from "../utils/Result"; -import { +import { err, ok } from "../utils/Result.ts"; +import type { DiagnosticResult, DiagnosticsResult, TsLocatableNode, - gqlErr, - tsErr, -} from "../utils/DiagnosticError"; -import { extend, nullThrows } from "../utils/helpers"; -import * as E from "../Errors"; +} from "../utils/DiagnosticError.ts"; +import { gqlErr, tsErr } from "../utils/DiagnosticError.ts"; +import { extend, nullThrows } from "../utils/helpers.ts"; +import * as E from "../Errors.ts"; type Template = { declarationTemplate: TypeDefinitionNode; @@ -71,11 +69,14 @@ export function resolveTypes( * which refer to generic types resolve to the correct type. */ class TemplateExtractor { + private ctx: TypeContext; _templates: Map = new Map(); _definitions: Array = []; _definedTemplates: Set = new Set(); _errors: ts.DiagnosticWithLocation[] = []; - constructor(private ctx: TypeContext) {} + constructor(ctx: TypeContext) { + this.ctx = ctx; + } materializeGenericTypeReferences( definitions: Array, @@ -370,10 +371,15 @@ function getTypeParameters( * being able to use it to report diagnostics */ class EntityNameWithTypeArguments implements TsLocatableNode { + typeName: ts.EntityName; + typeArguments?: ts.NodeArray; constructor( - public typeName: ts.EntityName, - public typeArguments?: ts.NodeArray, - ) {} + typeName: ts.EntityName, + typeArguments?: ts.NodeArray, + ) { + this.typeName = typeName; + this.typeArguments = typeArguments; + } getStart() { return this.typeName.getStart(); diff --git a/src/transforms/snapshotsFromProgram.ts b/src/transforms/snapshotsFromProgram.ts index 262eebe2..7694fea0 100644 --- a/src/transforms/snapshotsFromProgram.ts +++ b/src/transforms/snapshotsFromProgram.ts @@ -1,10 +1,11 @@ import * as ts from "typescript"; -import { ParsedCommandLineGrats } from "../gratsConfig"; -import { ExtractionSnapshot, extract } from "../Extractor"; -import { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError"; -import { collectResults } from "../utils/Result"; -import { err } from "../utils/Result"; -import { extend } from "../utils/helpers"; +import type { ParsedCommandLineGrats } from "../gratsConfig.ts"; +import type { ExtractionSnapshot } from "../Extractor.ts"; +import { extract } from "../Extractor.ts"; +import type { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError.ts"; +import { collectResults } from "../utils/Result.ts"; +import { err } from "../utils/Result.ts"; +import { extend } from "../utils/helpers.ts"; const TAG_REGEX = /@(gql)|(killsParentOnException)/i; diff --git a/src/transforms/sortSchemaAst.ts b/src/transforms/sortSchemaAst.ts index 265163fb..b3dcfde6 100644 --- a/src/transforms/sortSchemaAst.ts +++ b/src/transforms/sortSchemaAst.ts @@ -1,5 +1,6 @@ -import { DefinitionNode, DocumentNode, Kind, NameNode, visit } from "graphql"; -import { naturalCompare } from "../utils/naturalCompare"; +import type { DefinitionNode, DocumentNode, NameNode } from "graphql"; +import { Kind, visit } from "graphql"; +import { naturalCompare } from "../utils/naturalCompare.ts"; /* * Similar to lexicographicSortSchema from graphql-js but applied against an AST diff --git a/src/tsPlugin/initTsPlugin.ts b/src/tsPlugin/initTsPlugin.ts index 0b45891d..4b8c75f2 100644 --- a/src/tsPlugin/initTsPlugin.ts +++ b/src/tsPlugin/initTsPlugin.ts @@ -1,8 +1,10 @@ import { version as gratsTsVersion } from "typescript"; -import type * as TS from "typescript/lib/tsserverlibrary"; -import { extract } from "../Extractor"; -import { FAKE_ERROR_CODE } from "../utils/DiagnosticError"; -import { nullThrows } from "../utils/helpers"; +// Maybe this should actually be: +// import type * as TS from "typescript/lib/tsserverlibrary"; +import type * as TS from "typescript"; +import { extract } from "../Extractor.ts"; +import { FAKE_ERROR_CODE } from "../utils/DiagnosticError.ts"; +import { nullThrows } from "../utils/helpers.ts"; // An experimental plugin for TypeScript that adds a new language service // which reports diagnostics for the current file. Currently it only reports diff --git a/src/utils/DiagnosticError.ts b/src/utils/DiagnosticError.ts index 833f88eb..84d6c259 100644 --- a/src/utils/DiagnosticError.ts +++ b/src/utils/DiagnosticError.ts @@ -1,6 +1,6 @@ -import { GraphQLError, Location, Source } from "graphql"; +import type { GraphQLError, Location, Source } from "graphql"; import * as ts from "typescript"; -import { Result } from "./Result"; +import type { Result } from "./Result.ts"; type FixableDiagnostic = ts.Diagnostic & { fix?: ts.CodeFixAction; diff --git a/src/utils/Result.ts b/src/utils/Result.ts index 9d205649..71205aa1 100644 --- a/src/utils/Result.ts +++ b/src/utils/Result.ts @@ -1,5 +1,5 @@ -import * as ts from "typescript"; -import { DiagnosticsResult } from "./DiagnosticError"; +import type * as ts from "typescript"; +import type { DiagnosticsResult } from "./DiagnosticError.ts"; export type Result = Ok | Err; @@ -19,7 +19,10 @@ export function err(err: E): Err { * Helper class for chaining together a series of `Result` operations. */ export class ResultPipe { - constructor(private readonly _result: Result) {} + private readonly _result: Result; + constructor(_result: Result) { + this._result = _result; + } // Transform the value if OK, otherwise return the error. map(fn: (value: T) => T2): ResultPipe { if (this._result.kind === "OK") { diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index e7721601..a895d4b7 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -1,6 +1,9 @@ export class DefaultMap { _map: Map = new Map(); - constructor(private readonly getDefault: () => V) {} + private readonly getDefault: () => V; + constructor(getDefault: () => V) { + this.getDefault = getDefault; + } get(key: K): V { if (!this._map.has(key)) { diff --git a/src/validations/customSpecValidations.ts b/src/validations/customSpecValidations.ts index a9b8fece..580c4273 100644 --- a/src/validations/customSpecValidations.ts +++ b/src/validations/customSpecValidations.ts @@ -1,8 +1,10 @@ -import { DocumentNode, Kind } from "graphql"; -import { DiagnosticsResult, gqlErr } from "../utils/DiagnosticError"; -import { ok } from "../utils/Result"; -import { DiagnosticWithLocation } from "typescript"; -import * as E from "../Errors"; +import type { DocumentNode } from "graphql"; +import { Kind } from "graphql"; +import type { DiagnosticsResult } from "../utils/DiagnosticError.ts"; +import { gqlErr } from "../utils/DiagnosticError.ts"; +import { ok } from "../utils/Result.ts"; +import type { DiagnosticWithLocation } from "typescript"; +import * as E from "../Errors.ts"; /** * Grats depends upon graphql-js for implementing spec-compliant GraphQL schema diff --git a/src/validations/validateAsyncIterable.ts b/src/validations/validateAsyncIterable.ts index 11619db0..047f8b58 100644 --- a/src/validations/validateAsyncIterable.ts +++ b/src/validations/validateAsyncIterable.ts @@ -1,18 +1,18 @@ -import * as ts from "typescript"; -import { +import type * as ts from "typescript"; +import type { DocumentNode, FieldDefinitionNode, InterfaceTypeDefinitionNode, InterfaceTypeExtensionNode, - Kind, ObjectTypeDefinitionNode, ObjectTypeExtensionNode, TypeNode, - visit, } from "graphql"; -import { DiagnosticsResult, gqlErr } from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import * as E from "../Errors"; +import { Kind, visit } from "graphql"; +import type { DiagnosticsResult } from "../utils/DiagnosticError.ts"; +import { gqlErr } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import * as E from "../Errors.ts"; /** * Ensure that all fields on `Subscription` return an AsyncIterable and transform diff --git a/src/validations/validateDirectiveArguments.ts b/src/validations/validateDirectiveArguments.ts index cbec4518..a1d7f2ca 100644 --- a/src/validations/validateDirectiveArguments.ts +++ b/src/validations/validateDirectiveArguments.ts @@ -1,23 +1,18 @@ -import * as ts from "typescript"; +import type * as ts from "typescript"; +import type { DocumentNode, GraphQLSchema, GraphQLError } from "graphql"; import { - DocumentNode, - GraphQLSchema, visit, + visitWithTypeInfo, + isScalarType, + getNamedType, ValuesOfCorrectTypeRule, ValidationContext, TypeInfo, - visitWithTypeInfo, - GraphQLError, - getNamedType, - isScalarType, } from "graphql"; -import { - DiagnosticsWithoutLocationResult, - gqlErr, - gqlRelated, -} from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import { nullThrows } from "../utils/helpers"; +import type { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError.ts"; +import { gqlErr, gqlRelated } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import { nullThrows } from "../utils/helpers.ts"; /** * Surprisingly, the GraphQL spec (and therefore graphql-js) does not enforce diff --git a/src/validations/validateDuplicateContextOrInfo.ts b/src/validations/validateDuplicateContextOrInfo.ts index 578ee784..0f6b352e 100644 --- a/src/validations/validateDuplicateContextOrInfo.ts +++ b/src/validations/validateDuplicateContextOrInfo.ts @@ -1,12 +1,11 @@ -import { NameDefinition, TypeContext } from "../TypeContext"; -import { err, ok } from "../utils/Result"; -import { +import type { NameDefinition, TypeContext } from "../TypeContext.ts"; +import { err, ok } from "../utils/Result.ts"; +import type { DiagnosticsResult, FixableDiagnosticWithLocation, - gqlErr, - gqlRelated, -} from "../utils/DiagnosticError"; -import * as E from "../Errors"; +} from "../utils/DiagnosticError.ts"; +import { gqlErr, gqlRelated } from "../utils/DiagnosticError.ts"; +import * as E from "../Errors.ts"; export function validateDuplicateContextOrInfo( ctx: TypeContext, diff --git a/src/validations/validateMergedInterfaces.ts b/src/validations/validateMergedInterfaces.ts index 08630d9c..fdcd7d90 100644 --- a/src/validations/validateMergedInterfaces.ts +++ b/src/validations/validateMergedInterfaces.ts @@ -1,11 +1,8 @@ import * as ts from "typescript"; -import * as E from "../Errors"; -import { - DiagnosticsWithoutLocationResult, - tsErr, - tsRelated, -} from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; +import * as E from "../Errors.ts"; +import type { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError.ts"; +import { tsErr, tsRelated } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; /** * Prevent using merged interfaces as GraphQL interfaces. diff --git a/src/validations/validateSemanticNullability.ts b/src/validations/validateSemanticNullability.ts index de126343..1dd767ce 100644 --- a/src/validations/validateSemanticNullability.ts +++ b/src/validations/validateSemanticNullability.ts @@ -1,19 +1,12 @@ -import * as ts from "typescript"; -import { - ConstDirectiveNode, - GraphQLField, - GraphQLSchema, - isInterfaceType, -} from "graphql"; -import { - DiagnosticsWithoutLocationResult, - gqlErr, - gqlRelated, -} from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import { GratsConfig } from "../gratsConfig"; -import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives"; -import { astNode } from "../utils/helpers"; +import type * as ts from "typescript"; +import type { ConstDirectiveNode, GraphQLField, GraphQLSchema } from "graphql"; +import { isInterfaceType } from "graphql"; +import { gqlErr, gqlRelated } from "../utils/DiagnosticError.ts"; +import type { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import type { GratsConfig } from "../gratsConfig.ts"; +import { SEMANTIC_NON_NULL_DIRECTIVE } from "../publicDirectives.ts"; +import { astNode } from "../utils/helpers.ts"; /** * Ensure that all semantically non-nullable fields on an interface are also diff --git a/src/validations/validateTypenames.ts b/src/validations/validateTypenames.ts index 87efedc8..a5fce6d5 100644 --- a/src/validations/validateTypenames.ts +++ b/src/validations/validateTypenames.ts @@ -1,19 +1,11 @@ -import * as ts from "typescript"; -import { - GraphQLInterfaceType, - GraphQLSchema, - Kind, - isAbstractType, - isType, -} from "graphql"; -import { - DiagnosticsWithoutLocationResult, - gqlErr, - gqlRelated, -} from "../utils/DiagnosticError"; -import { err, ok } from "../utils/Result"; -import { nullThrows } from "../utils/helpers"; -import * as E from "../Errors"; +import type * as ts from "typescript"; +import { Kind, isAbstractType, isType, GraphQLInterfaceType } from "graphql"; +import type { GraphQLSchema } from "graphql"; +import type { DiagnosticsWithoutLocationResult } from "../utils/DiagnosticError.ts"; +import { gqlErr, gqlRelated } from "../utils/DiagnosticError.ts"; +import { err, ok } from "../utils/Result.ts"; +import { nullThrows } from "../utils/helpers.ts"; +import * as E from "../Errors.ts"; /** * Ensure that every type which implements an interface or is a member of a diff --git a/tsconfig.json b/tsconfig.json index 1b8c6e39..520d55c0 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,20 +1,10 @@ { - // Most ts-node options can be specified here using their programmatic names. - "ts-node": { - // It is faster to skip typechecking. - // Remove if you want ts-node to do typechecking. - "transpileOnly": true, - "files": true, - "compilerOptions": { - // compilerOptions specified here will override those declared below, - // but *only* in ts-node. Useful if you want ts-node and tsc to use - // different options with a single tsconfig.json. - } - }, "grats": { "nullableByDefault": false }, "compilerOptions": { + "rootDir": "./", + "module": "nodenext", "skipLibCheck": true, "lib": ["es2017"], // typescript options here @@ -24,7 +14,8 @@ "strictNullChecks": true, "declaration": true, "resolveJsonModule": true, - "strictPropertyInitialization": true + "strictPropertyInitialization": true, + "rewriteRelativeImportExtensions": true }, "exclude": [ "node_modules", diff --git a/website/src/components/PlaygroundFeatures/urlState.ts b/website/src/components/PlaygroundFeatures/urlState.ts index 4977bf7c..fe8159c1 100644 --- a/website/src/components/PlaygroundFeatures/urlState.ts +++ b/website/src/components/PlaygroundFeatures/urlState.ts @@ -1,5 +1,5 @@ import { DEFAULT_STATE } from "./defaultState"; -import { State, SerializableState } from "./store"; +import type { State, SerializableState } from "./store"; import lzstring from "lz-string"; import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";