refactor: add typegen utils module
This commit is contained in:
parent
17fad3a78a
commit
358c33efaa
|
@ -138,6 +138,7 @@ import {
|
|||
AllInputTypes,
|
||||
GetGen,
|
||||
} from "./typegenTypeHelpers";
|
||||
import { resolveTypegenConfig } from "./typegenUtils";
|
||||
import {
|
||||
assertNoMissingTypes,
|
||||
consoleWarn,
|
||||
|
@ -146,7 +147,6 @@ import {
|
|||
isObject,
|
||||
mapValues,
|
||||
objValues,
|
||||
resolveTypegenConfig,
|
||||
UNKNOWN_TYPE_SCALAR,
|
||||
validateOnInstallHookResult,
|
||||
} from "./utils";
|
||||
|
|
|
@ -26,4 +26,5 @@ export * from "./typegenFormatPrettier";
|
|||
export * from "./typegenMetadata";
|
||||
export * from "./typegenPrinter";
|
||||
export * from "./typegenTypeHelpers";
|
||||
export * from "./typegenUtils";
|
||||
export * from "./utils";
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
import { BuilderConfig } from "./builder";
|
||||
import { TypegenMetadataConfig } from "./typegenMetadata";
|
||||
import { assertAbsolutePath } from "./utils";
|
||||
|
||||
/**
|
||||
* Normalizes the builder config into the config we need for typegen
|
||||
*
|
||||
* @param config {BuilderConfig}
|
||||
*/
|
||||
export function resolveTypegenConfig(
|
||||
config: BuilderConfig
|
||||
): TypegenMetadataConfig {
|
||||
const {
|
||||
outputs,
|
||||
shouldGenerateArtifacts = Boolean(
|
||||
!process.env.NODE_ENV || process.env.NODE_ENV === "development"
|
||||
),
|
||||
...rest
|
||||
} = config;
|
||||
|
||||
let typegenPath: string | false = false;
|
||||
let schemaPath: string | false = false;
|
||||
if (outputs && typeof outputs === "object") {
|
||||
if (typeof outputs.schema === "string") {
|
||||
schemaPath = assertAbsolutePath(outputs.schema, "outputs.schema");
|
||||
}
|
||||
if (typeof outputs.typegen === "string") {
|
||||
typegenPath = assertAbsolutePath(outputs.typegen, "outputs.typegen");
|
||||
}
|
||||
} else if (outputs !== false) {
|
||||
console.warn(
|
||||
`You should specify a configuration value for outputs in Nexus' makeSchema. ` +
|
||||
`Provide one to remove this warning.`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
outputs: {
|
||||
typegen: shouldGenerateArtifacts ? typegenPath : false,
|
||||
schema: shouldGenerateArtifacts ? schemaPath : false,
|
||||
},
|
||||
};
|
||||
}
|
43
src/utils.ts
43
src/utils.ts
|
@ -22,11 +22,9 @@ import {
|
|||
specifiedScalarTypes,
|
||||
} from "graphql";
|
||||
import path from "path";
|
||||
import { BuilderConfig } from "./builder";
|
||||
import { decorateType } from "./definitions/decorateType";
|
||||
import { MissingType, NexusTypes, withNexusSymbol } from "./definitions/_types";
|
||||
import { PluginConfig } from "./plugin";
|
||||
import { TypegenMetadataConfig } from "./typegenMetadata";
|
||||
|
||||
export const isInterfaceField = (
|
||||
type: GraphQLObjectType,
|
||||
|
@ -304,47 +302,6 @@ export function printedGenTyping(config: PrintedGenTypingConfig) {
|
|||
return new PrintedGenTyping(config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Normalizes the builder config into the config we need for typegen
|
||||
*
|
||||
* @param config {BuilderConfig}
|
||||
*/
|
||||
export function resolveTypegenConfig(
|
||||
config: BuilderConfig
|
||||
): TypegenMetadataConfig {
|
||||
const {
|
||||
outputs,
|
||||
shouldGenerateArtifacts = Boolean(
|
||||
!process.env.NODE_ENV || process.env.NODE_ENV === "development"
|
||||
),
|
||||
...rest
|
||||
} = config;
|
||||
|
||||
let typegenPath: string | false = false;
|
||||
let schemaPath: string | false = false;
|
||||
if (outputs && typeof outputs === "object") {
|
||||
if (typeof outputs.schema === "string") {
|
||||
schemaPath = assertAbsolutePath(outputs.schema, "outputs.schema");
|
||||
}
|
||||
if (typeof outputs.typegen === "string") {
|
||||
typegenPath = assertAbsolutePath(outputs.typegen, "outputs.typegen");
|
||||
}
|
||||
} else if (outputs !== false) {
|
||||
console.warn(
|
||||
`You should specify a configuration value for outputs in Nexus' makeSchema. ` +
|
||||
`Provide one to remove this warning.`
|
||||
);
|
||||
}
|
||||
|
||||
return {
|
||||
...rest,
|
||||
outputs: {
|
||||
typegen: shouldGenerateArtifacts ? typegenPath : false,
|
||||
schema: shouldGenerateArtifacts ? schemaPath : false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export function unwrapType(
|
||||
type: GraphQLType
|
||||
): { type: GraphQLNamedType; isNonNull: boolean; list: boolean[] } {
|
||||
|
|
Loading…
Reference in New Issue