Skip to content

Commit

Permalink
fix: config types (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
danadajian authored Mar 11, 2024
1 parent 7078a68 commit 079e92c
Show file tree
Hide file tree
Showing 20 changed files with 45 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ jobs:
- name: Lint
run: bun lint

- name: Type Check
run: bun tsc

- name: Unit Tests
run: bun test

Expand Down
6 changes: 3 additions & 3 deletions src/definitions/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -49,7 +49,7 @@ ${indentMultiline(enumValues.join(",\n") + ";", 2)}

function buildEnumValueDefinition(
node: EnumValueDefinitionNode,
config: GraphQLKotlinCodegenConfig,
config: CodegenConfig,
) {
const annotations = buildAnnotations({
config,
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down Expand Up @@ -62,7 +62,7 @@ function getClassMembers({
}: {
node: ObjectTypeDefinitionNode;
schema: GraphQLSchema;
config: GraphQLKotlinCodegenConfig;
config: CodegenConfig;
completableFuture?: boolean;
}) {
const resolverType = isResolverType(node, config);
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/union.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "";
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/add-dependent-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/build-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -35,7 +35,7 @@ export function buildAnnotations({
definitionNode,
resolvedType,
}: {
config: GraphQLKotlinCodegenConfig;
config: CodegenConfig;
inputDescription?: string;
definitionNode?: DefinitionNode;
resolvedType?: TypeMetadata;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/build-directive-annotations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/build-field-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/build-type-metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/dependent-type-is-in-scope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 ||
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/dependent-type-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/get-dependent-type-names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/is-resolver-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) ||
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/should-include-type-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 4 additions & 2 deletions src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RawConfig & ParsedConfig> &
Input<typeof configSchema>;
export type CodegenConfig = RawConfig &
ParsedConfig &
Input<typeof configSchema>;
export const plugin: PluginFunction<GraphQLKotlinCodegenConfig> = (
export const plugin: PluginFunction<CodegenConfig> = (
schema,
_,
config,
Expand Down
9 changes: 3 additions & 6 deletions src/visitor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<RawConfig, CodegenConfig> {
constructor(
rawConfig: GraphQLKotlinCodegenConfig,
rawConfig: CodegenConfig,
protected _schema: GraphQLSchema,
) {
super(rawConfig, rawConfig);
Expand Down
4 changes: 2 additions & 2 deletions test/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -9,7 +9,7 @@ function buildUnitTest({
config,
}: {
testName: string;
config: GraphQLKotlinCodegenConfig;
config: CodegenConfig;
}) {
it(testName, async () => {
const filePath = `./test/unit/${testName}`;
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"types": ["bun-types"]
},
"include": ["./**/*"],
"exclude": ["node_modules", "dist"]
"exclude": ["node_modules", "dist", "docs"]
}

0 comments on commit 079e92c

Please sign in to comment.