diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 13df218..e575f54 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -25,6 +25,9 @@ jobs: - name: Lint run: bun lint + - name: Type Check + run: bun tsc + - name: Unit Tests run: bun test diff --git a/src/definitions/enum.ts b/src/definitions/enum.ts index 896bae2..cbd865a 100644 --- a/src/definitions/enum.ts +++ b/src/definitions/enum.ts @@ -15,11 +15,11 @@ import { EnumTypeDefinitionNode, EnumValueDefinitionNode } from "graphql"; import { indentMultiline } from "@graphql-codegen/visitor-plugin-common"; import { buildAnnotations } from "../helpers/build-annotations"; import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildEnumTypeDefinition( node: EnumTypeDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { if (!shouldIncludeTypeDefinition(node, config)) { return ""; @@ -49,7 +49,7 @@ ${indentMultiline(enumValues.join(",\n") + ";", 2)} function buildEnumValueDefinition( node: EnumValueDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { const annotations = buildAnnotations({ config, diff --git a/src/definitions/input.ts b/src/definitions/input.ts index b348411..8d34a58 100644 --- a/src/definitions/input.ts +++ b/src/definitions/input.ts @@ -16,12 +16,12 @@ import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-defi import { buildTypeMetadata } from "../helpers/build-type-metadata"; import { buildAnnotations } from "../helpers/build-annotations"; import { indent } from "@graphql-codegen/visitor-plugin-common"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildInputObjectDefinition( node: InputObjectTypeDefinitionNode, schema: GraphQLSchema, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { if (!shouldIncludeTypeDefinition(node, config)) { return ""; diff --git a/src/definitions/interface.ts b/src/definitions/interface.ts index cfb589e..9072eb6 100644 --- a/src/definitions/interface.ts +++ b/src/definitions/interface.ts @@ -17,12 +17,12 @@ import { indent } from "@graphql-codegen/visitor-plugin-common"; import { buildTypeMetadata } from "../helpers/build-type-metadata"; import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition"; import { buildFieldDefinition } from "../helpers/build-field-definition"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildInterfaceDefinition( node: InterfaceTypeDefinitionNode, schema: GraphQLSchema, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { if (!shouldIncludeTypeDefinition(node, config)) { return ""; diff --git a/src/definitions/object.ts b/src/definitions/object.ts index 10f7c5e..56885d1 100644 --- a/src/definitions/object.ts +++ b/src/definitions/object.ts @@ -20,12 +20,12 @@ import { getDependentInterfaceNames } from "../helpers/dependent-type-utils"; import { isResolverType } from "../helpers/is-resolver-type"; import { buildFieldDefinition } from "../helpers/build-field-definition"; import { isExternalField } from "../helpers/is-external-field"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildObjectTypeDefinition( node: ObjectTypeDefinitionNode, schema: GraphQLSchema, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { if (!shouldIncludeTypeDefinition(node, config)) { return ""; @@ -62,7 +62,7 @@ function getClassMembers({ }: { node: ObjectTypeDefinitionNode; schema: GraphQLSchema; - config: GraphQLKotlinCodegenConfig; + config: CodegenConfig; completableFuture?: boolean; }) { const resolverType = isResolverType(node, config); diff --git a/src/definitions/union.ts b/src/definitions/union.ts index fb6f0e5..bb77973 100644 --- a/src/definitions/union.ts +++ b/src/definitions/union.ts @@ -14,11 +14,11 @@ limitations under the License. import { UnionTypeDefinitionNode } from "graphql"; import { shouldIncludeTypeDefinition } from "../helpers/should-include-type-definition"; import { buildDirectiveAnnotations } from "../helpers/build-directive-annotations"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildUnionTypeDefinition( node: UnionTypeDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { if (!shouldIncludeTypeDefinition(node, config)) { return ""; diff --git a/src/helpers/add-dependent-types.ts b/src/helpers/add-dependent-types.ts index 33e9a4f..a5097e4 100644 --- a/src/helpers/add-dependent-types.ts +++ b/src/helpers/add-dependent-types.ts @@ -11,13 +11,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; import { getDependentTypeNames } from "./get-dependent-type-names"; import { dependentTypeIsInScope } from "./dependent-type-is-in-scope"; import { GraphQLSchema } from "graphql"; export function addDependentTypes( - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, schema: GraphQLSchema, ) { if (config.onlyTypes && (config.includeDependentTypes ?? true)) { diff --git a/src/helpers/build-annotations.ts b/src/helpers/build-annotations.ts index cd7d180..f0e6b95 100644 --- a/src/helpers/build-annotations.ts +++ b/src/helpers/build-annotations.ts @@ -19,7 +19,7 @@ import { TypeDefinitionNode, } from "graphql"; import { buildDirectiveAnnotations } from "./build-directive-annotations"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; import { TypeMetadata } from "./build-type-metadata"; import { dependentTypeIsInScope } from "./dependent-type-is-in-scope"; @@ -35,7 +35,7 @@ export function buildAnnotations({ definitionNode, resolvedType, }: { - config: GraphQLKotlinCodegenConfig; + config: CodegenConfig; inputDescription?: string; definitionNode?: DefinitionNode; resolvedType?: TypeMetadata; diff --git a/src/helpers/build-directive-annotations.ts b/src/helpers/build-directive-annotations.ts index c8cfe14..c88b2f4 100644 --- a/src/helpers/build-directive-annotations.ts +++ b/src/helpers/build-directive-annotations.ts @@ -11,13 +11,13 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; import { DefinitionNode, isDeprecatedDescription } from "./build-annotations"; import { getFederationDirectiveReplacement } from "./get-federation-directive-replacement"; export function buildDirectiveAnnotations( incomingNode: DefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, description?: string, ) { const kind = incomingNode.kind; diff --git a/src/helpers/build-field-definition.ts b/src/helpers/build-field-definition.ts index 887c520..ee71e0f 100644 --- a/src/helpers/build-field-definition.ts +++ b/src/helpers/build-field-definition.ts @@ -21,12 +21,12 @@ import { } from "graphql"; import { isResolverType } from "./is-resolver-type"; import { isExternalField } from "./is-external-field"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function buildFieldDefinition( fieldNode: FieldDefinitionNode, definitionNode: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, completableFuture?: boolean, ) { const shouldUseFunction = diff --git a/src/helpers/build-type-metadata.ts b/src/helpers/build-type-metadata.ts index a766913..1f6572d 100644 --- a/src/helpers/build-type-metadata.ts +++ b/src/helpers/build-type-metadata.ts @@ -22,7 +22,7 @@ import { import { getBaseTypeNode } from "@graphql-codegen/visitor-plugin-common"; import { wrapTypeWithModifiers } from "@graphql-codegen/java-common"; import { dependentTypeIsInScope } from "./dependent-type-is-in-scope"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export interface TypeMetadata { typeName: string; @@ -34,7 +34,7 @@ export interface TypeMetadata { export function buildTypeMetadata( typeNode: TypeNode, schema: GraphQLSchema, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ): TypeMetadata { const innerType = getBaseTypeNode(typeNode); const schemaType = schema.getType(innerType.name.value); diff --git a/src/helpers/dependent-type-is-in-scope.ts b/src/helpers/dependent-type-is-in-scope.ts index 7838bf3..ab79b03 100644 --- a/src/helpers/dependent-type-is-in-scope.ts +++ b/src/helpers/dependent-type-is-in-scope.ts @@ -11,11 +11,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function dependentTypeIsInScope( typeName: string, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { return ( !config.dependentTypesInScope || diff --git a/src/helpers/dependent-type-utils.ts b/src/helpers/dependent-type-utils.ts index 9db279a..d8d6e65 100644 --- a/src/helpers/dependent-type-utils.ts +++ b/src/helpers/dependent-type-utils.ts @@ -12,11 +12,11 @@ limitations under the License. */ import { Kind, TypeDefinitionNode, TypeNode } from "graphql"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function getDependentFieldTypeNames( node: TypeDefinitionNode, - dependentTypesInScope: GraphQLKotlinCodegenConfig["dependentTypesInScope"], + dependentTypesInScope: CodegenConfig["dependentTypesInScope"], ) { return "fields" in node && node.fields ? node.fields diff --git a/src/helpers/get-dependent-type-names.ts b/src/helpers/get-dependent-type-names.ts index 9c9463a..f5c26a8 100644 --- a/src/helpers/get-dependent-type-names.ts +++ b/src/helpers/get-dependent-type-names.ts @@ -18,12 +18,12 @@ import { getDependentInterfaceNames, getDependentUnionNames, } from "./dependent-type-utils"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function getDependentTypeNames( schema: GraphQLSchema, node: TypeDefinitionNode, - dependentTypesInScope: GraphQLKotlinCodegenConfig["dependentTypesInScope"], + dependentTypesInScope: CodegenConfig["dependentTypesInScope"], ): string[] { const namedTypes = getDependentFieldTypeNames(node, dependentTypesInScope) .concat(getDependentUnionNames(node)) diff --git a/src/helpers/is-resolver-type.ts b/src/helpers/is-resolver-type.ts index 7deb601..a7ca626 100644 --- a/src/helpers/is-resolver-type.ts +++ b/src/helpers/is-resolver-type.ts @@ -12,11 +12,11 @@ limitations under the License. */ import { InterfaceTypeDefinitionNode, ObjectTypeDefinitionNode } from "graphql"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function isResolverType( node: ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { return ( node.fields?.some((fieldNode) => fieldNode.arguments?.length) || diff --git a/src/helpers/should-include-type-definition.ts b/src/helpers/should-include-type-definition.ts index e83c3ab..fecdf5b 100644 --- a/src/helpers/should-include-type-definition.ts +++ b/src/helpers/should-include-type-definition.ts @@ -12,11 +12,11 @@ limitations under the License. */ import { TypeDefinitionNode } from "graphql"; -import { GraphQLKotlinCodegenConfig } from "../plugin"; +import { CodegenConfig } from "../plugin"; export function shouldIncludeTypeDefinition( node: TypeDefinitionNode, - config: GraphQLKotlinCodegenConfig, + config: CodegenConfig, ) { return !config.onlyTypes || config.onlyTypes.includes(node.name.value); } diff --git a/src/plugin.ts b/src/plugin.ts index 616aca8..25c62d1 100644 --- a/src/plugin.ts +++ b/src/plugin.ts @@ -27,10 +27,12 @@ import { configSchema } from "./config"; import { addDependentTypes } from "./helpers/add-dependent-types"; import { visit } from "graphql"; -export type GraphQLKotlinCodegenConfig = RawConfig & +export type GraphQLKotlinCodegenConfig = Partial & + Input; +export type CodegenConfig = RawConfig & ParsedConfig & Input; -export const plugin: PluginFunction = ( +export const plugin: PluginFunction = ( schema, _, config, diff --git a/src/visitor.ts b/src/visitor.ts index 4986af0..c2b57b8 100644 --- a/src/visitor.ts +++ b/src/visitor.ts @@ -20,19 +20,16 @@ import { ObjectTypeDefinitionNode, UnionTypeDefinitionNode, } from "graphql"; -import { GraphQLKotlinCodegenConfig } from "./plugin"; +import { CodegenConfig } from "./plugin"; import { buildEnumTypeDefinition } from "./definitions/enum"; import { buildInterfaceDefinition } from "./definitions/interface"; import { buildInputObjectDefinition } from "./definitions/input"; import { buildObjectTypeDefinition } from "./definitions/object"; import { buildUnionTypeDefinition } from "./definitions/union"; -export class KotlinVisitor extends BaseVisitor< - RawConfig, - GraphQLKotlinCodegenConfig -> { +export class KotlinVisitor extends BaseVisitor { constructor( - rawConfig: GraphQLKotlinCodegenConfig, + rawConfig: CodegenConfig, protected _schema: GraphQLSchema, ) { super(rawConfig, rawConfig); diff --git a/test/plugin.test.ts b/test/plugin.test.ts index ab1d934..6767630 100644 --- a/test/plugin.test.ts +++ b/test/plugin.test.ts @@ -1,5 +1,5 @@ import { buildSchema } from "graphql"; -import { GraphQLKotlinCodegenConfig, plugin } from "../src/plugin"; +import { CodegenConfig, plugin } from "../src/plugin"; import { describe, expect, it } from "bun:test"; import { Types } from "@graphql-codegen/plugin-helpers"; import * as glob from "glob"; @@ -9,7 +9,7 @@ function buildUnitTest({ config, }: { testName: string; - config: GraphQLKotlinCodegenConfig; + config: CodegenConfig; }) { it(testName, async () => { const filePath = `./test/unit/${testName}`; diff --git a/tsconfig.json b/tsconfig.json index c5bbd08..61cad32 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -13,5 +13,5 @@ "types": ["bun-types"] }, "include": ["./**/*"], - "exclude": ["node_modules", "dist"] + "exclude": ["node_modules", "dist", "docs"] }