Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nexus

Package Overview
Dependencies
Maintainers
4
Versions
395
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nexus - npm Package Compare versions

Comparing version 1.2.0-next.13 to 1.2.0-next.14

dist-esm/rebuildType.d.ts

241

dist-esm/builder.d.ts

@@ -1,16 +0,13 @@

import { GraphQLField, GraphQLFieldConfig, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldResolver, GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLObjectType, GraphQLOutputType, GraphQLSchemaConfig, GraphQLType, printSchema } from 'graphql';
import type { ArgsRecord } from './definitions/args';
import { InputDefinitionBlock, NexusInputFieldDef, NexusOutputFieldDef, OutputDefinitionBlock } from './definitions/definitionBlocks';
import type { NexusExtendInputTypeConfig, NexusExtendInputTypeDef } from './definitions/extendInputType';
import type { NexusExtendTypeConfig, NexusExtendTypeDef } from './definitions/extendType';
import type { NexusInputObjectTypeConfig } from './definitions/inputObjectType';
import { FieldModificationDef, NexusInterfaceTypeConfig, NexusInterfaceTypeDef } from './definitions/interfaceType';
import { NexusObjectTypeConfig, NexusObjectTypeDef, ObjectDefinitionBlock } from './definitions/objectType';
import { UnionMembers } from './definitions/unionType';
import { AllNexusNamedInputTypeDefs, AllNexusNamedOutputTypeDefs, AllNexusNamedTypeDefs, AllNexusOutputTypeDefs, NexusWrapKind } from './definitions/wrapping';
import type { MissingType, NexusFeaturesInput, NexusGraphQLInputObjectTypeConfig, NexusGraphQLInterfaceTypeConfig, NexusGraphQLObjectTypeConfig, NexusGraphQLSchema, NonNullConfig, SourceTypings, TypingImport } from './definitions/_types';
import { GraphQLNamedType, GraphQLSchema, GraphQLSchemaConfig, printSchema } from 'graphql';
import { InputDefinitionBlock } from './definitions/definitionBlocks';
import type { NexusExtendInputTypeDef } from './definitions/extendInputType';
import type { NexusExtendTypeDef } from './definitions/extendType';
import { NexusInterfaceTypeConfig } from './definitions/interfaceType';
import { ObjectDefinitionBlock } from './definitions/objectType';
import { AllNexusNamedTypeDefs, AllNexusOutputTypeDefs } from './definitions/wrapping';
import type { MissingType, NexusFeaturesInput, NexusGraphQLSchema, NonNullConfig, TypingImport } from './definitions/_types';
import type { DynamicInputMethodDef, DynamicOutputMethodDef } from './dynamicMethod';
import type { DynamicOutputPropertyDef } from './dynamicProperty';
import { NexusSchemaExtension } from './extensions';
import { CreateFieldResolverInfo, NexusPlugin, PluginConfig } from './plugin';
import { NexusPlugin } from './plugin';
import type { SourceTypesConfigOptions } from './typegenAutoConfig';

@@ -29,4 +26,2 @@ import type { TypegenFormatFn } from './typegenFormatPrettier';

};
declare type PossibleOutputType = string | AllNexusNamedOutputTypeDefs | Exclude<GraphQLOutputType, GraphQLNonNull<any> | GraphQLList<any>>;
declare type PossibleInputType = string | AllNexusNamedInputTypeDefs | GraphQLType;
export interface ConfiguredTypegen {

@@ -52,4 +47,51 @@ /** Path for the generated type defs */

}
export interface MergeSchemaConfig {
/**
* GraphQL Schema to merge into the Nexus type definitions.
*
* We unwrap each type, preserve the "nullable/nonNull" status of any fields &
* arguments, and then combine with the local Nexus GraphQL types.
*
* If you have multiple schemas
*/
schema: GraphQLSchema;
/**
* If we want to "merge" specific types, provide a list of the types you wish to merge here.
*
* @default ['Query', 'Mutation']
*/
mergeTypes?: string[] | true;
/**
* If there are types that we don't want to include from the external schema in our final
* Nexus generated schema, provide them here.
*/
skipTypes?: string[];
/**
* If there are certain "fields" that we want to skip, we can specify
* the fields here and we'll ensure they don't get merged into the schema
*/
skipFields?: Record<string, string[]>;
/**
* If there are certain arguments for any type fields that we want to skip, we can specify
* the fields here & ensure they don't get merged into the final schema.
*
* @example
* skipArgs: {
* Mutation: {
* createAccount: ['internalId']
* }
* }
*/
skipArgs?: Record<string, Record<string, string[]>>;
}
export interface BuilderConfigInput {
/**
* If we have an external schema that we want to "merge into" our local Nexus schema definitions,
* we can configure it here.
*
* If you have more than one schema that needs merging, you can look into using
* graphql-tools to pre-merge into a single schema: https://www.graphql-tools.com/docs/schema-merging
*/
mergeSchema?: MergeSchemaConfig;
/**
* Generated artifact settings. Set to false to disable all. Set to true to enable all and use default

@@ -177,5 +219,2 @@ * paths. Leave undefined for default behaviour of each artifact.

export declare type TypeToWalk = {
type: 'named';
value: GraphQLNamedType;
} | {
type: 'input';

@@ -212,5 +251,5 @@ value: NexusShapedInput;

/** Used to check for circular references. */
protected buildingTypes: Set<unknown>;
private buildingTypes;
/** The "final type" map contains all types as they are built. */
protected finalTypeMap: Record<string, GraphQLNamedType>;
private finalTypeMap;
/**

@@ -220,3 +259,3 @@ * The "defined type" map keeps track of all of the types that were defined directly as `GraphQL*Type`

*/
protected definedTypeMap: Record<string, GraphQLNamedType>;
private definedTypeMap;
/**

@@ -226,47 +265,62 @@ * The "pending type" map keeps track of all types that were defined w/ GraphQL Nexus and haven't been

*/
protected pendingTypeMap: Record<string, AllNexusNamedTypeDefs>;
/** All "extensions" to types (adding fields on types from many locations) */
protected typeExtendMap: Record<string, NexusExtendTypeConfig<string>[] | null>;
/** All "extensions" to input types (adding fields on types from many locations) */
protected inputTypeExtendMap: Record<string, NexusExtendInputTypeConfig<string>[] | null>;
protected dynamicInputFields: DynamicInputFields;
protected dynamicOutputFields: DynamicOutputFields;
protected dynamicOutputProperties: DynamicOutputProperties;
protected plugins: NexusPlugin[];
private pendingTypeMap;
/**
* All "extensions" to types (adding fields on types from many locations)
*/
private typeExtendMap;
/**
* All "extensions" to input types (adding fields on types from many locations)
*/
private inputTypeExtendMap;
/**
* When we encounter "named" types from graphql-js, we keep them separate from Nexus definitions.
* This way we can have Nexus definitions take precedence without worrying about conflicts,
* particularly when we're looking to override behavior from inherited types.
*/
private graphqlNamedTypeMap;
/**
* If we're merging against a remote schema, the types from the schema are kept here,
* for fallbacks / merging when we're building the actual Schema
*/
private graphqlMergeSchemaMap;
private dynamicInputFields;
private dynamicOutputFields;
private dynamicOutputProperties;
private plugins;
/** All types that need to be traversed for children types */
protected typesToWalk: TypeToWalk[];
private typesToWalk;
/** Root type mapping information annotated on the type definitions */
protected sourceTypings: SourceTypings;
private sourceTypings;
/** Array of missing types */
protected missingTypes: Record<string, MissingType>;
private missingTypes;
/** Methods we are able to access to read/modify builder state from plugins */
protected builderLens: PluginBuilderLens;
private builderLens;
/** Created just before types are walked, this keeps track of all of the resolvers */
protected onMissingTypeFns: Exclude<PluginConfig['onMissingType'], undefined>[];
private onMissingTypeFns;
/** Executed just before types are walked */
protected onBeforeBuildFns: Exclude<PluginConfig['onBeforeBuild'], undefined>[];
private onBeforeBuildFns;
/** Executed as the field resolvers are included on the field */
protected onCreateResolverFns: Exclude<PluginConfig['onCreateFieldResolver'], undefined>[];
private onCreateResolverFns;
/** Executed as the field "subscribe" fields are included on the schema */
protected onCreateSubscribeFns: Exclude<PluginConfig['onCreateFieldSubscribe'], undefined>[];
private onCreateSubscribeFns;
/** Executed after the schema is constructed, for any final verification */
protected onAfterBuildFns: Exclude<PluginConfig['onAfterBuild'], undefined>[];
private onAfterBuildFns;
/** Executed after the object is defined, allowing us to add additional fields to the object */
protected onObjectDefinitionFns: Exclude<PluginConfig['onObjectDefinition'], undefined>[];
private onObjectDefinitionFns;
/** Executed after the object is defined, allowing us to add additional fields to the object */
protected onInputObjectDefinitionFns: Exclude<PluginConfig['onInputObjectDefinition'], undefined>[];
private onInputObjectDefinitionFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddArgFns: Exclude<PluginConfig['onAddArg'], undefined>[];
private onAddArgFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddOutputFieldFns: Exclude<PluginConfig['onAddOutputField'], undefined>[];
private onAddOutputFieldFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddInputFieldFns: Exclude<PluginConfig['onAddInputField'], undefined>[];
private onAddInputFieldFns;
/** The `schemaExtension` is created just after the types are walked, but before the fields are materialized. */
protected _schemaExtension?: NexusSchemaExtension;
protected config: BuilderConfig;
get schemaExtension(): NexusSchemaExtension;
private _schemaExtension?;
private config;
private get schemaExtension();
constructor(config: BuilderConfigInput);
setConfigOption: <K extends "features" | "nonNullDefaults" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K, value: BuilderConfigInput[K]) => void;
setConfigOption: <K extends "features" | "nonNullDefaults" | "mergeSchema" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K, value: BuilderConfigInput[K]) => void;
hasConfigOption: (key: keyof BuilderConfigInput) => boolean;
getConfigOption: <K extends "features" | "nonNullDefaults" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K) => BuilderConfigInput[K];
getConfigOption: <K extends "features" | "nonNullDefaults" | "mergeSchema" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K) => BuilderConfigInput[K];
hasType: (typeName: string) => boolean;

@@ -278,16 +332,16 @@ /**

*/
addType: (typeDef: NexusAcceptedTypeDef) => void;
private addType;
addTypes(types: any): void;
private addToNexusMeta;
rebuildNamedOutputFields(config: ReturnType<GraphQLObjectType['toConfig'] | GraphQLInterfaceType['toConfig']>): Record<string, any>;
walkTypes(): void;
beforeWalkTypes(): void;
beforeBuildTypes(): void;
checkForInterfaceCircularDependencies(): void;
buildNexusTypes(): void;
createSchemaExtension(): void;
private walkTypes;
private beforeWalkTypes;
private beforeBuildTypes;
private checkForInterfaceCircularDependencies;
private buildNexusTypes;
private createSchemaExtension;
getFinalTypeMap(): BuildTypes<any>;
buildInputObjectType(config: NexusInputObjectTypeConfig<any>): GraphQLInputObjectType;
buildObjectType(config: NexusObjectTypeConfig<string>): GraphQLObjectType<any, any>;
buildInterfaceType(config: NexusInterfaceTypeConfig<any>): GraphQLInterfaceType;
private shouldMerge;
private buildInputObjectType;
private buildObjectType;
private buildInterfaceType;
private addOutputField;

@@ -298,38 +352,37 @@ private addInputField;

private buildScalarType;
protected finalize<T extends GraphQLNamedType>(type: T): T;
protected missingType(typeName: string, fromObject?: boolean): GraphQLNamedType;
protected buildUnionMembers(unionName: string, members: UnionMembers | undefined): GraphQLObjectType<any, any>[];
protected buildInterfaceList(interfaces: (string | NexusInterfaceTypeDef<any>)[]): GraphQLInterfaceType[];
protected buildInterfaceFields(forTypeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig, interfaces: (string | NexusInterfaceTypeDef<any>)[], modifications: Record<string, FieldModificationDef<any, any>>): GraphQLFieldConfigMap<any, any>;
protected buildOutputFields(fields: NexusOutputFieldDef[], typeConfig: NexusGraphQLInterfaceTypeConfig | NexusGraphQLObjectTypeConfig, intoObject: GraphQLFieldConfigMap<any, any>): GraphQLFieldConfigMap<any, any>;
protected buildInputObjectFields(fields: NexusInputFieldDef[], typeConfig: NexusGraphQLInputObjectTypeConfig): GraphQLInputFieldConfigMap;
protected getNonNullDefault(nonNullDefaultConfig: {
nonNullDefaults?: NonNullConfig;
} | undefined, kind: 'input' | 'output'): boolean;
protected buildOutputField(fieldConfig: NexusOutputFieldDef, typeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig): GraphQLFieldConfig<any, any>;
protected makeFinalResolver(info: CreateFieldResolverInfo, resolver?: GraphQLFieldResolver<any, any>): GraphQLFieldResolver<any, any, {
[argName: string]: any;
}>;
protected buildInputObjectField(fieldConfig: NexusInputFieldDef, typeConfig: NexusGraphQLInputObjectTypeConfig): GraphQLInputFieldConfig;
protected buildArgs(args: ArgsRecord, typeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig, fieldName: string): GraphQLFieldConfigArgumentMap;
protected getInterface(name: string | NexusInterfaceTypeDef<any>): GraphQLInterfaceType;
protected getInputType(possibleInputType: PossibleInputType): Exclude<GraphQLInputType, GraphQLNonNull<any> | GraphQLList<any>>;
protected getOutputType(possibleOutputType: PossibleOutputType): Exclude<GraphQLOutputType, GraphQLNonNull<any> | GraphQLList<any>>;
protected getObjectOrInterfaceType(name: string | NexusObjectTypeDef<string>): GraphQLObjectType | GraphQLInterfaceType;
protected getObjectType(name: string | NexusObjectTypeDef<string>): GraphQLObjectType;
protected getOrBuildType(type: string | AllNexusNamedTypeDefs | GraphQLNamedType, fromObject?: boolean): GraphQLNamedType;
protected walkInputType<T extends NexusShapedInput>(obj: T): T;
addDynamicInputFields(block: InputDefinitionBlock<any>, wrapping?: NexusWrapKind[]): void;
addDynamicOutputMembers(block: OutputDefinitionBlock<any>, stage: 'walk' | 'build', wrapping?: NexusWrapKind[]): void;
addDynamicScalar(methodName: string, typeName: string, block: OutputDefinitionBlock<any> | InputDefinitionBlock<any>): void;
protected walkOutputType<T extends NexusShapedOutput>(obj: T): T;
protected walkInterfaceType(obj: NexusInterfaceTypeConfig<any>): NexusInterfaceTypeConfig<any>;
protected maybeTraverseModification(mod: FieldModificationDef<any, any>): void;
protected maybeTraverseOutputFieldType(type: NexusOutputFieldDef): void;
private finalize;
private missingType;
private buildUnionMembers;
private buildInterfaceList;
private buildInterfaceFields;
private buildOutputFields;
private buildInputObjectFields;
private getNonNullDefault;
private buildOutputField;
private makeFinalResolver;
private buildInputObjectField;
private buildArgs;
private getInterface;
private getInputType;
private getOutputType;
private getObjectType;
private getOrBuildType;
private walkInputType;
private addDynamicInputFields;
private addDynamicOutputMembers;
private addDynamicField;
private walkOutputType;
private walkInterfaceType;
private maybeTraverseModification;
private maybeTraverseOutputFieldType;
private traverseArgs;
protected maybeTraverseInputFieldType(type: NexusInputFieldDef): void;
protected walkNamedTypes(namedType: GraphQLNamedType): void;
protected addUnknownTypeInternal(t: GraphQLNamedType): void;
protected addNamedTypeOutputField(obj: GraphQLField<any, any>): void;
protected replaceNamedType(type: GraphQLType): any;
private maybeTraverseInputFieldType;
/**
* Given a "mergeSchema", gathers all of the types and constructs them
* into a map of types that we keep as a "merge schema"
*
* @param config
*/
private handleMergeSchema;
private handleNativeType;
}

@@ -336,0 +389,0 @@ export declare type DynamicFieldDefs = {

import { __rest } from "tslib";
import { assertValidName, defaultFieldResolver, getNamedType, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, isInputObjectType, isInterfaceType, isLeafType, isNamedType, isObjectType, isOutputType, isScalarType, isSchema, isUnionType, isWrappingType, } from 'graphql';
import { assertValidName, defaultFieldResolver, GraphQLBoolean, GraphQLEnumType, GraphQLFloat, GraphQLID, GraphQLInputObjectType, GraphQLInt, GraphQLInterfaceType, GraphQLNonNull, GraphQLObjectType, GraphQLScalarType, GraphQLSchema, GraphQLString, GraphQLUnionType, isInputObjectType, isInputType, isInterfaceType, isLeafType, isNamedType, isObjectType, isOutputType, isSchema, isWrappingType, } from 'graphql';
import { InputDefinitionBlock, } from './definitions/definitionBlocks';

@@ -7,3 +7,3 @@ import { InterfaceDefinitionBlock, } from './definitions/interfaceType';

import { UnionDefinitionBlock } from './definitions/unionType';
import { finalizeWrapping, isNexusDynamicInputMethod, isNexusDynamicOutputMethod, isNexusDynamicOutputProperty, isNexusEnumTypeDef, isNexusExtendInputTypeDef, isNexusExtendTypeDef, isNexusInputObjectTypeDef, isNexusInterfaceTypeDef, isNexusNamedTypeDef, isNexusObjectTypeDef, isNexusPlugin, isNexusScalarTypeDef, isNexusUnionTypeDef, isNexusWrappingType, normalizeArgWrapping, rewrapAsGraphQLType, unwrapGraphQLDef, unwrapNexusDef, } from './definitions/wrapping';
import { finalizeWrapping, isNexusDynamicInputMethod, isNexusDynamicOutputMethod, isNexusDynamicOutputProperty, isNexusEnumTypeDef, isNexusExtendInputTypeDef, isNexusExtendTypeDef, isNexusInputObjectTypeDef, isNexusInterfaceTypeDef, isNexusNamedInputTypeDef, isNexusNamedOuputTypeDef, isNexusNamedTypeDef, isNexusObjectTypeDef, isNexusPlugin, isNexusScalarTypeDef, isNexusUnionTypeDef, isNexusWrappingType, normalizeArgWrapping, rewrapAsGraphQLType, unwrapGraphQLDef, unwrapNexusDef, } from './definitions/wrapping';
import { NexusFieldExtension, NexusInputObjectTypeExtension, NexusInterfaceTypeExtension, NexusObjectTypeExtension, NexusSchemaExtension, } from './extensions';

@@ -14,4 +14,5 @@ import { messages } from './messages';

import { fieldAuthorizePlugin } from './plugins/fieldAuthorizePlugin';
import { casesHandled, consoleWarn, eachObj, getArgNamedType, getNexusNamedType, graphql15InterfaceConfig, graphql15InterfaceType, invariantGuard, isArray, isObject, mapValues, objValues, UNKNOWN_TYPE_SCALAR, } from './utils';
import { casesHandled, consoleWarn, eachObj, getArgNamedType, getNexusNamedType, graphql15InterfaceType, invariantGuard, isArray, isObject, objValues, UNKNOWN_TYPE_SCALAR, } from './utils';
import { NEXUS_BUILD, isNexusMetaBuild, isNexusMeta, isNexusMetaType, resolveNexusMetaType, } from './definitions/nexusMeta';
import { rebuildNamedType } from './rebuildType';
const SCALARS = {

@@ -47,6 +48,21 @@ String: GraphQLString,

this.pendingTypeMap = {};
/** All "extensions" to types (adding fields on types from many locations) */
/**
* All "extensions" to types (adding fields on types from many locations)
*/
this.typeExtendMap = {};
/** All "extensions" to input types (adding fields on types from many locations) */
/**
* All "extensions" to input types (adding fields on types from many locations)
*/
this.inputTypeExtendMap = {};
/**
* When we encounter "named" types from graphql-js, we keep them separate from Nexus definitions.
* This way we can have Nexus definitions take precedence without worrying about conflicts,
* particularly when we're looking to override behavior from inherited types.
*/
this.graphqlNamedTypeMap = {};
/**
* If we're merging against a remote schema, the types from the schema are kept here,
* for fallbacks / merging when we're building the actual Schema
*/
this.graphqlMergeSchemaMap = {};
this.dynamicInputFields = {};

@@ -92,3 +108,6 @@ this.dynamicOutputFields = {};

this.hasType = (typeName) => {
return Boolean(this.pendingTypeMap[typeName] || this.finalTypeMap[typeName]);
return Boolean(this.pendingTypeMap[typeName] ||
this.finalTypeMap[typeName] ||
this.graphqlNamedTypeMap[typeName] ||
this.graphqlMergeSchemaMap[typeName]);
};

@@ -101,7 +120,3 @@ /**

this.addType = (typeDef) => {
var _a, _b;
if (isNexusMeta(typeDef)) {
this.addToNexusMeta(typeDef);
return;
}
var _a, _b, _c;
if (isNexusDynamicInputMethod(typeDef)) {

@@ -119,7 +134,10 @@ this.dynamicInputFields[typeDef.name] = typeDef;

}
if (isNexusMeta(typeDef)) {
this.addToNexusMeta(typeDef);
return;
}
// Don't worry about internal types.
if (((_a = typeDef.name) === null || _a === void 0 ? void 0 : _a.indexOf('__')) === 0) {
if ((_a = typeDef.name) === null || _a === void 0 ? void 0 : _a.startsWith('__')) {
return;
}
const existingType = this.definedTypeMap[typeDef.name] || this.pendingTypeMap[typeDef.name];
if (isNexusExtendTypeDef(typeDef)) {

@@ -138,50 +156,60 @@ const typeExtensions = (this.typeExtendMap[typeDef.name] = this.typeExtendMap[typeDef.name] || []);

}
// Check the "defined" type map for existing Nexus types. We are able to conflict with external types,
// as we assume that locally defined types take precedence.
const existingType = this.pendingTypeMap[typeDef.name];
// If we already have a "Nexus" type, but it's not the same, trigger mark as an error,
// otherwise early exit
if (existingType) {
// Allow importing the same exact type more than once.
if (existingType === typeDef) {
return;
if (existingType !== typeDef) {
throw extendError(typeDef.name);
}
throw extendError(typeDef.name);
return;
}
if (isNexusScalarTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicInputFields[typeDef.value.asNexusMethod] = typeDef.name;
this.dynamicOutputFields[typeDef.value.asNexusMethod] = typeDef.name;
if (typeDef.value.sourceType) {
if (isNexusNamedTypeDef(typeDef)) {
if (isNexusNamedOuputTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicOutputFields[typeDef.value.asNexusMethod] = typeDef.name;
}
if (isNexusNamedInputTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicInputFields[typeDef.value.asNexusMethod] = typeDef.name;
}
if (isNexusScalarTypeDef(typeDef) && typeDef.value.sourceType) {
this.sourceTypings[typeDef.name] = typeDef.value.sourceType;
}
}
else if (isScalarType(typeDef)) {
const scalarDef = typeDef;
if ((_b = scalarDef.extensions) === null || _b === void 0 ? void 0 : _b.nexus) {
const { asNexusMethod, sourceType: rootTyping } = scalarDef.extensions.nexus;
// If it's a concrete GraphQL type, we handle it directly by convering the
// type to a Nexus structure, and capturing all of the referenced types
// while we're reconstructing.
if (isNamedType(typeDef)) {
// If we've already captured the named type, we can skip it
if (this.graphqlNamedTypeMap[typeDef.name]) {
return;
}
// If we've used decorateType to wrap, then we can grab the types off
if ((_b = typeDef.extensions) === null || _b === void 0 ? void 0 : _b.nexus) {
const { asNexusMethod, sourceType } = typeDef.extensions.nexus;
if (asNexusMethod) {
this.dynamicInputFields[asNexusMethod] = scalarDef.name;
this.dynamicOutputFields[asNexusMethod] = typeDef.name;
if (isInputType(typeDef)) {
this.dynamicInputFields[asNexusMethod] = typeDef.name;
}
if (isOutputType(typeDef)) {
this.dynamicOutputFields[asNexusMethod] = typeDef.name;
}
}
if (rootTyping) {
this.sourceTypings[scalarDef.name] = rootTyping;
if (sourceType) {
this.sourceTypings[typeDef.name] = sourceType;
}
}
}
if (isNamedType(typeDef)) {
let finalTypeDef = typeDef;
if (isObjectType(typeDef)) {
const config = typeDef.toConfig();
finalTypeDef = new GraphQLObjectType(Object.assign(Object.assign({}, config), { fields: () => this.rebuildNamedOutputFields(config), interfaces: () => config.interfaces.map((t) => this.getInterface(t.name)) }));
this.graphqlNamedTypeMap[typeDef.name] = this.handleNativeType(typeDef, {
captureLeafType: (t) => {
if (!this.graphqlNamedTypeMap[t.name] && t.name !== typeDef.name) {
this.addType(t);
}
},
});
if ((_c = typeDef.extensions) === null || _c === void 0 ? void 0 : _c.nexus) {
this.addType(this.graphqlNamedTypeMap[typeDef.name]);
}
else if (isInterfaceType(typeDef)) {
const config = graphql15InterfaceConfig(typeDef.toConfig());
finalTypeDef = new GraphQLInterfaceType(Object.assign(Object.assign({}, config), { fields: () => this.rebuildNamedOutputFields(config), interfaces: () => config.interfaces.map((t) => this.getInterface(t.name)) }));
}
else if (isUnionType(typeDef)) {
const config = typeDef.toConfig();
finalTypeDef = new GraphQLUnionType(Object.assign(Object.assign({}, config), { types: () => config.types.map((t) => this.getObjectType(t.name)) }));
}
this.finalTypeMap[typeDef.name] = finalTypeDef;
this.definedTypeMap[typeDef.name] = typeDef;
this.typesToWalk.push({ type: 'named', value: typeDef });
return;
}
else {
this.pendingTypeMap[typeDef.name] = typeDef;
}
this.pendingTypeMap[typeDef.name] = typeDef;
if (isNexusInputObjectTypeDef(typeDef)) {

@@ -210,2 +238,5 @@ this.typesToWalk.push({ type: 'input', value: typeDef.value });

});
if (config.mergeSchema) {
this.graphqlMergeSchemaMap = this.handleMergeSchema(config.mergeSchema);
}
}

@@ -220,3 +251,3 @@ get schemaExtension() {

addTypes(types) {
var _a;
var _a, _b;
if (!types) {

@@ -226,7 +257,18 @@ return;

if (isSchema(types)) {
this.addTypes(types.getTypeMap());
if (((_a = this.config.mergeSchema) === null || _a === void 0 ? void 0 : _a.schema) === types) {
return;
}
else if (!this.config.mergeSchema) {
if (Object.keys(this.graphqlMergeSchemaMap).length) {
console.error(new Error(`It looks like you're trying to merge multiple GraphQL schemas.\n Please open a GitHub ticket with more info about your use case.`));
}
this.graphqlMergeSchemaMap = this.handleMergeSchema({ schema: types });
}
else {
this.addTypes(types.getTypeMap());
}
return;
}
if (isNexusPlugin(types)) {
if (!((_a = this.plugins) === null || _a === void 0 ? void 0 : _a.includes(types))) {
if (!((_b = this.plugins) === null || _b === void 0 ? void 0 : _b.includes(types))) {
throw new Error(`Nexus plugin ${types.config.name} was seen in the "types" config, but should instead be provided to the "plugins" array.`);

@@ -266,17 +308,2 @@ }

}
rebuildNamedOutputFields(config) {
const { fields } = config, rest = __rest(config, ["fields"]);
const fieldsConfig = typeof fields === 'function' ? fields() : fields;
return mapValues(fieldsConfig, (val, key) => {
const { resolve, type } = val, fieldConfig = __rest(val, ["resolve", "type"]);
const finalType = this.replaceNamedType(type);
return Object.assign(Object.assign({}, fieldConfig), { type: finalType, resolve: this.makeFinalResolver({
builder: this.builderLens,
fieldConfig: Object.assign(Object.assign({}, fieldConfig), { type: finalType, name: key }),
schemaConfig: this.config,
parentTypeConfig: rest,
schemaExtension: this.schemaExtension,
}, resolve) });
});
}
walkTypes() {

@@ -292,5 +319,2 @@ let obj;

break;
case 'named':
this.walkNamedTypes(obj.value);
break;
case 'object':

@@ -402,3 +426,3 @@ this.walkOutputType(obj.value);

// If Query isn't defined, set it to null so it falls through to "missingType"
if (!this.pendingTypeMap.Query && !((_a = this.config.schemaRoots) === null || _a === void 0 ? void 0 : _a.query)) {
if (!this.pendingTypeMap.Query && !((_a = this.config.schemaRoots) === null || _a === void 0 ? void 0 : _a.query) && !this.typeExtendMap.Query) {
this.pendingTypeMap.Query = null;

@@ -423,3 +447,3 @@ }

// If we haven't defined the type, assume it's an object type
if (this.typeExtendMap[key] !== null) {
if (this.typeExtendMap[key] !== null && !this.hasType(key)) {
this.buildObjectType({

@@ -433,3 +457,3 @@ name: key,

// If we haven't defined the type, assume it's an input object type
if (this.inputTypeExtendMap[key] !== null) {
if (this.inputTypeExtendMap[key] !== null && !this.hasType(key)) {
this.buildInputObjectType({

@@ -464,2 +488,9 @@ name: key,

}
shouldMerge(typeName) {
if (!this.config.mergeSchema) {
return false;
}
const { mergeTypes = ['Query', 'Mutation'] } = this.config.mergeSchema;
return Boolean(mergeTypes === true || mergeTypes.includes(typeName));
}
buildInputObjectType(config) {

@@ -473,2 +504,6 @@ const fields = [];

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && isNexusInputObjectTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -505,2 +540,6 @@ this.onInputObjectDefinitionFns.forEach((fn) => {

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && isNexusObjectTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -544,2 +583,6 @@ this.onObjectDefinitionFns.forEach((fn) => {

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && isNexusInterfaceTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -681,3 +724,4 @@ if (config.sourceType) {

}
return UNKNOWN_TYPE_SCALAR;
this.addType(UNKNOWN_TYPE_SCALAR);
return this.getOrBuildType(UNKNOWN_TYPE_SCALAR);
}

@@ -734,3 +778,3 @@ buildUnionMembers(unionName, members) {

if (typeof args !== 'undefined') {
interfaceFieldsMap[field].args = Object.assign(Object.assign({}, this.buildArgs(args, forTypeConfig, field)), interfaceFieldsMap[field].args);
interfaceFieldsMap[field].args = Object.assign(Object.assign({}, this.buildArgs(args !== null && args !== void 0 ? args : {}, forTypeConfig, field)), interfaceFieldsMap[field].args);
}

@@ -809,9 +853,9 @@ }

buildArgs(args, typeConfig, fieldName) {
var _a, _b, _c, _d;
const allArgs = {};
Object.keys(args).forEach((argName) => {
var _a, _b, _c, _d;
for (const [argName, arg] of Object.entries(args)) {
const nonNullDefault = this.getNonNullDefault((_b = (_a = typeConfig.extensions) === null || _a === void 0 ? void 0 : _a.nexus) === null || _b === void 0 ? void 0 : _b.config, 'input');
let finalArgDef = Object.assign(Object.assign({}, normalizeArgWrapping(args[argName]).value), { fieldName,
let finalArgDef = Object.assign(Object.assign({}, normalizeArgWrapping(arg).value), { fieldName,
argName, parentType: typeConfig.name, configFor: 'arg' });
this.onAddArgFns.forEach((onArgDef) => {
for (const onArgDef of this.onAddArgFns) {
const result = onArgDef(finalArgDef);

@@ -821,3 +865,3 @@ if (result != null) {

}
});
}
const { namedType, wrapping } = unwrapNexusDef(finalArgDef.type);

@@ -831,3 +875,3 @@ const finalWrap = finalizeWrapping(nonNullDefault, wrapping);

};
});
}
return allArgs;

@@ -860,13 +904,2 @@ }

}
getObjectOrInterfaceType(name) {
if (isNexusNamedTypeDef(name)) {
return this.getObjectOrInterfaceType(name.name);
}
const type = this.getOrBuildType(name);
if (!isObjectType(type) && !isInterfaceType(type)) {
/* istanbul ignore next */
throw new Error(`Expected ${name} to be a objectType / interfaceType, saw ${type.constructor.name}`);
}
return type;
}
getObjectType(name) {

@@ -884,2 +917,3 @@ if (isNexusNamedTypeDef(name)) {

getOrBuildType(type, fromObject = false) {
var _a, _b;
invariantGuard(type);

@@ -902,3 +936,3 @@ if (isNamedType(type)) {

}
const pendingType = this.pendingTypeMap[type];
const pendingType = (_b = (_a = this.pendingTypeMap[type]) !== null && _a !== void 0 ? _a : this.graphqlNamedTypeMap[type]) !== null && _b !== void 0 ? _b : this.graphqlMergeSchemaMap[type];
if (isNexusNamedTypeDef(pendingType)) {

@@ -943,3 +977,3 @@ this.buildingTypes.add(pendingType.name);

if (typeof val === 'string') {
return this.addDynamicScalar(methodName, val, block);
return this.addDynamicField(methodName, val, block);
}

@@ -961,3 +995,3 @@ // @ts-ignore

if (typeof val === 'string') {
return this.addDynamicScalar(methodName, val, block);
return this.addDynamicField(methodName, val, block);
}

@@ -990,3 +1024,3 @@ // @ts-ignore

}
addDynamicScalar(methodName, typeName, block) {
addDynamicField(methodName, typeName, block) {
// @ts-ignore

@@ -1081,41 +1115,34 @@ block[methodName] = (fieldName, opts) => {

}
walkNamedTypes(namedType) {
if (isObjectType(namedType) || isInterfaceType(namedType)) {
eachObj(namedType.getFields(), (val) => this.addNamedTypeOutputField(val));
/**
* Given a "mergeSchema", gathers all of the types and constructs them
* into a map of types that we keep as a "merge schema"
*
* @param config
*/
handleMergeSchema(config) {
var _a;
const { types } = config.schema.toConfig();
const mergedTypes = {};
// We don't need to worry about capturing any types while walking,
// because we have the entire schema
for (const type of types) {
if (type.name.startsWith('__')) {
continue;
}
if ((_a = config.skipTypes) === null || _a === void 0 ? void 0 : _a.includes(type.name)) {
continue;
}
mergedTypes[type.name] = this.handleNativeType(type, config);
}
if (isObjectType(namedType)) {
namedType.getInterfaces().forEach((i) => this.addUnknownTypeInternal(i));
}
if (isInputObjectType(namedType)) {
eachObj(namedType.getFields(), (val) => this.addUnknownTypeInternal(getNamedType(val.type)));
}
if (isUnionType(namedType)) {
namedType.getTypes().forEach((type) => this.addUnknownTypeInternal(type));
}
return mergedTypes;
}
addUnknownTypeInternal(t) {
if (!this.definedTypeMap[t.name]) {
this.addType(t);
handleNativeType(type, config) {
var _a;
var _b, _c;
while (isWrappingType(type)) {
type = type.ofType;
}
(_a = (_b = this.pendingTypeMap)[_c = type.name]) !== null && _a !== void 0 ? _a : (_b[_c] = null);
return rebuildNamedType(type, config);
}
addNamedTypeOutputField(obj) {
this.addUnknownTypeInternal(getNamedType(obj.type));
if (obj.args) {
obj.args.forEach((val) => this.addType(getNamedType(val.type)));
}
}
replaceNamedType(type) {
let wrappingTypes = [];
let finalType = type;
while (isWrappingType(finalType)) {
wrappingTypes.unshift(finalType.constructor);
finalType = finalType.ofType;
}
if (this.finalTypeMap[finalType.name] === this.definedTypeMap[finalType.name]) {
return type;
}
return wrappingTypes.reduce((result, Wrapper) => {
return new Wrapper(result);
}, this.finalTypeMap[finalType.name]);
}
}

@@ -1122,0 +1149,0 @@ function extendError(name) {

@@ -29,2 +29,3 @@ export * from './builder';

export * from './plugins';
export * from './rebuildType';
export * from './sdlConverter';

@@ -31,0 +32,0 @@ export * from './typegenAutoConfig';

@@ -31,2 +31,3 @@ // The "core" is used as a namespace to re-export everything,

export * from './plugins';
export * from './rebuildType';
export * from './sdlConverter';

@@ -33,0 +34,0 @@ export * from './typegenAutoConfig';

import type { GraphQLScalarTypeConfig } from 'graphql';
import type { AllNexusInputTypeDefs } from '../core';
import type { AllInputTypes, GetGen2 } from '../typegenTypeHelpers';
import type { AllNexusArgsDefs } from './wrapping';
import type { AllNexusArgsDefs, AllNexusInputTypeDefs } from './wrapping';
import { Maybe } from './_types';

@@ -6,0 +5,0 @@ export declare type ArgsRecord = Record<string, AllNexusArgsDefs>;

@@ -7,5 +7,2 @@ import type { GraphQLNamedType } from 'graphql';

}
export declare type NexusTypeExtensions = {
nexus: TypeExtensionConfig;
};
export declare function decorateType<T extends GraphQLNamedType>(type: T, config: TypeExtensionConfig): T;
export function decorateType(type, config) {
type.extensions = Object.assign(Object.assign({}, type.extensions), { nexus: {
asNexusMethod: config.asNexusMethod,
sourceType: config.sourceType,
} });
var _a;
type.extensions = Object.assign(Object.assign({}, type.extensions), { nexus: Object.assign(Object.assign({}, (_a = type.extensions) === null || _a === void 0 ? void 0 : _a.nexus), config) });
return type;
}
//# sourceMappingURL=decorateType.js.map

@@ -66,3 +66,3 @@ import type { GraphQLFieldConfig, GraphQLFieldResolver, GraphQLInputFieldConfig } from 'graphql';

*/
args?: ArgsRecord;
args?: Maybe<ArgsRecord>;
/**

@@ -69,0 +69,0 @@ * Data that will be added to the field-level [extensions field on the graphql-js type def

@@ -40,2 +40,4 @@ import { GraphQLEnumTypeConfig, GraphQLEnumValueConfig } from 'graphql';

extensions?: GraphQLEnumTypeConfig['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
}

@@ -42,0 +44,0 @@ export declare class NexusEnumTypeDef<TypeName extends string> {

@@ -23,2 +23,4 @@ import { GraphQLInputObjectTypeConfig } from 'graphql';

extensions?: GraphQLInputObjectTypeConfig['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & NexusGenPluginInputTypeConfig<TypeName>;

@@ -25,0 +27,0 @@ export declare class NexusInputObjectTypeDef<TypeName extends string> {

@@ -14,3 +14,3 @@ import { GraphQLInterfaceTypeConfig } from 'graphql';

/** You are allowed to add non-required args when modifying a field */
args?: ArgsRecord;
args?: Maybe<ArgsRecord>;
/**

@@ -44,2 +44,4 @@ * Custom extensions, as supported in graphql-js

extensions?: GraphQLInterfaceTypeConfig<any, any>['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>;

@@ -46,0 +48,0 @@ export interface InterfaceDefinitionBuilder<TypeName extends string> extends OutputDefinitionBuilder {

@@ -181,2 +181,4 @@ import { GraphQLObjectType } from 'graphql';

definition(t: ObjectDefinitionBlock<TypeName>): void;
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldIsTypeOf<TypeName> & NexusGenPluginTypeConfig<TypeName>;

@@ -183,0 +185,0 @@ export declare class NexusObjectTypeDef<TypeName extends string> {

@@ -1,3 +0,4 @@

import { GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql';
import { Maybe, SourceTypingDef } from './_types';
import { GraphQLNamedType, GraphQLScalarTypeConfig } from 'graphql';
import type { AllNexusInputTypeDefs, AllNexusOutputTypeDefs } from '../core';
import { GraphQLNamedOutputType, Maybe, SourceTypingDef } from './_types';
export interface ScalarBase extends Pick<GraphQLScalarTypeConfig<any, any>, 'description' | 'serialize' | 'parseValue' | 'parseLiteral'> {

@@ -30,2 +31,2 @@ }

export declare function scalarType<TypeName extends string>(options: NexusScalarTypeConfig<TypeName>): NexusScalarTypeDef<TypeName>;
export declare function asNexusMethod<T extends GraphQLScalarType>(scalar: T, methodName: string, sourceType?: SourceTypingDef): T;
export declare function asNexusMethod<T extends GraphQLNamedType>(namedType: T, methodName: string, sourceType?: SourceTypingDef): T extends GraphQLNamedOutputType ? AllNexusOutputTypeDefs : AllNexusInputTypeDefs;

@@ -18,4 +18,4 @@ import { assertValidName } from 'graphql';

}
export function asNexusMethod(scalar, methodName, sourceType) {
return decorateType(scalar, {
export function asNexusMethod(namedType, methodName, sourceType) {
return decorateType(namedType, {
asNexusMethod: methodName,

@@ -22,0 +22,0 @@ sourceType,

@@ -39,2 +39,4 @@ import { GraphQLUnionTypeConfig } from 'graphql';

extensions?: GraphQLUnionTypeConfig<any, any>['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>;

@@ -41,0 +43,0 @@ export declare class NexusUnionTypeDef<TypeName extends string> {

@@ -87,2 +87,4 @@ import { GraphQLInputType, GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLType } from 'graphql';

export declare function isNexusArgDef(obj: any): obj is NexusArgDef<AllInputTypes>;
export declare function isNexusNamedOuputTypeDef(obj: any): obj is AllNexusNamedOutputTypeDefs;
export declare function isNexusNamedInputTypeDef(obj: any): obj is AllNexusNamedInputTypeDefs;
export declare function isNexusDynamicOutputProperty<T extends string>(obj: any): obj is DynamicOutputPropertyDef<T>;

@@ -89,0 +91,0 @@ export declare function isNexusDynamicOutputMethod<T extends string>(obj: any): obj is DynamicOutputMethodDef<T>;

@@ -66,2 +66,8 @@ import { GraphQLList, GraphQLNonNull, isWrappingType, isListType, isNonNullType, } from 'graphql';

}
export function isNexusNamedOuputTypeDef(obj) {
return isNexusNamedTypeDef(obj) && !isNexusInputObjectTypeDef(obj);
}
export function isNexusNamedInputTypeDef(obj) {
return isNexusNamedTypeDef(obj) && !isNexusObjectTypeDef(obj) && !isNexusInterfaceTypeDef(obj);
}
export function isNexusDynamicOutputProperty(obj) {

@@ -68,0 +74,0 @@ return isNexusStruct(obj) && obj[NexusWrappedSymbol] === NexusTypes.DynamicOutputProperty;

import { GraphQLNamedType } from 'graphql';
import type { DynamicFieldDefs, SchemaConfig } from './builder';
import type { SourceTypingDef, SourceTypings } from './definitions/_types';
import type { SourceTypings } from './definitions/_types';
import type { NexusOutputFieldConfig } from './definitions/definitionBlocks';

@@ -52,7 +52,1 @@ import type { NexusInputObjectTypeConfig } from './definitions/inputObjectType';

}
export declare type NexusScalarExtensions = {
nexus: {
asNexusMethod?: string;
sourceType?: SourceTypingDef;
};
};

@@ -102,3 +102,3 @@ import { __awaiter } from "tslib";

Object.keys(typeMap).forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return;

@@ -105,0 +105,0 @@ }

@@ -120,1 +120,2 @@ import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLInterfaceTypeConfig, GraphQLNamedType, GraphQLObjectType, GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema, GraphQLType, GraphQLUnionType } from 'graphql';

};
export declare function result<T>(val: T | (() => T)): T;

@@ -113,3 +113,3 @@ import * as fs from 'fs';

.forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return;

@@ -484,2 +484,8 @@ }

};
export function result(val) {
if (val instanceof Function) {
return val();
}
return val;
}
//# sourceMappingURL=utils.js.map

@@ -1,16 +0,13 @@

import { GraphQLField, GraphQLFieldConfig, GraphQLFieldConfigArgumentMap, GraphQLFieldConfigMap, GraphQLFieldResolver, GraphQLInputFieldConfig, GraphQLInputFieldConfigMap, GraphQLInputObjectType, GraphQLInputType, GraphQLInterfaceType, GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLObjectType, GraphQLOutputType, GraphQLSchemaConfig, GraphQLType, printSchema } from 'graphql';
import type { ArgsRecord } from './definitions/args';
import { InputDefinitionBlock, NexusInputFieldDef, NexusOutputFieldDef, OutputDefinitionBlock } from './definitions/definitionBlocks';
import type { NexusExtendInputTypeConfig, NexusExtendInputTypeDef } from './definitions/extendInputType';
import type { NexusExtendTypeConfig, NexusExtendTypeDef } from './definitions/extendType';
import type { NexusInputObjectTypeConfig } from './definitions/inputObjectType';
import { FieldModificationDef, NexusInterfaceTypeConfig, NexusInterfaceTypeDef } from './definitions/interfaceType';
import { NexusObjectTypeConfig, NexusObjectTypeDef, ObjectDefinitionBlock } from './definitions/objectType';
import { UnionMembers } from './definitions/unionType';
import { AllNexusNamedInputTypeDefs, AllNexusNamedOutputTypeDefs, AllNexusNamedTypeDefs, AllNexusOutputTypeDefs, NexusWrapKind } from './definitions/wrapping';
import type { MissingType, NexusFeaturesInput, NexusGraphQLInputObjectTypeConfig, NexusGraphQLInterfaceTypeConfig, NexusGraphQLObjectTypeConfig, NexusGraphQLSchema, NonNullConfig, SourceTypings, TypingImport } from './definitions/_types';
import { GraphQLNamedType, GraphQLSchema, GraphQLSchemaConfig, printSchema } from 'graphql';
import { InputDefinitionBlock } from './definitions/definitionBlocks';
import type { NexusExtendInputTypeDef } from './definitions/extendInputType';
import type { NexusExtendTypeDef } from './definitions/extendType';
import { NexusInterfaceTypeConfig } from './definitions/interfaceType';
import { ObjectDefinitionBlock } from './definitions/objectType';
import { AllNexusNamedTypeDefs, AllNexusOutputTypeDefs } from './definitions/wrapping';
import type { MissingType, NexusFeaturesInput, NexusGraphQLSchema, NonNullConfig, TypingImport } from './definitions/_types';
import type { DynamicInputMethodDef, DynamicOutputMethodDef } from './dynamicMethod';
import type { DynamicOutputPropertyDef } from './dynamicProperty';
import { NexusSchemaExtension } from './extensions';
import { CreateFieldResolverInfo, NexusPlugin, PluginConfig } from './plugin';
import { NexusPlugin } from './plugin';
import type { SourceTypesConfigOptions } from './typegenAutoConfig';

@@ -29,4 +26,2 @@ import type { TypegenFormatFn } from './typegenFormatPrettier';

};
declare type PossibleOutputType = string | AllNexusNamedOutputTypeDefs | Exclude<GraphQLOutputType, GraphQLNonNull<any> | GraphQLList<any>>;
declare type PossibleInputType = string | AllNexusNamedInputTypeDefs | GraphQLType;
export interface ConfiguredTypegen {

@@ -52,4 +47,51 @@ /** Path for the generated type defs */

}
export interface MergeSchemaConfig {
/**
* GraphQL Schema to merge into the Nexus type definitions.
*
* We unwrap each type, preserve the "nullable/nonNull" status of any fields &
* arguments, and then combine with the local Nexus GraphQL types.
*
* If you have multiple schemas
*/
schema: GraphQLSchema;
/**
* If we want to "merge" specific types, provide a list of the types you wish to merge here.
*
* @default ['Query', 'Mutation']
*/
mergeTypes?: string[] | true;
/**
* If there are types that we don't want to include from the external schema in our final
* Nexus generated schema, provide them here.
*/
skipTypes?: string[];
/**
* If there are certain "fields" that we want to skip, we can specify
* the fields here and we'll ensure they don't get merged into the schema
*/
skipFields?: Record<string, string[]>;
/**
* If there are certain arguments for any type fields that we want to skip, we can specify
* the fields here & ensure they don't get merged into the final schema.
*
* @example
* skipArgs: {
* Mutation: {
* createAccount: ['internalId']
* }
* }
*/
skipArgs?: Record<string, Record<string, string[]>>;
}
export interface BuilderConfigInput {
/**
* If we have an external schema that we want to "merge into" our local Nexus schema definitions,
* we can configure it here.
*
* If you have more than one schema that needs merging, you can look into using
* graphql-tools to pre-merge into a single schema: https://www.graphql-tools.com/docs/schema-merging
*/
mergeSchema?: MergeSchemaConfig;
/**
* Generated artifact settings. Set to false to disable all. Set to true to enable all and use default

@@ -177,5 +219,2 @@ * paths. Leave undefined for default behaviour of each artifact.

export declare type TypeToWalk = {
type: 'named';
value: GraphQLNamedType;
} | {
type: 'input';

@@ -212,5 +251,5 @@ value: NexusShapedInput;

/** Used to check for circular references. */
protected buildingTypes: Set<unknown>;
private buildingTypes;
/** The "final type" map contains all types as they are built. */
protected finalTypeMap: Record<string, GraphQLNamedType>;
private finalTypeMap;
/**

@@ -220,3 +259,3 @@ * The "defined type" map keeps track of all of the types that were defined directly as `GraphQL*Type`

*/
protected definedTypeMap: Record<string, GraphQLNamedType>;
private definedTypeMap;
/**

@@ -226,47 +265,62 @@ * The "pending type" map keeps track of all types that were defined w/ GraphQL Nexus and haven't been

*/
protected pendingTypeMap: Record<string, AllNexusNamedTypeDefs>;
/** All "extensions" to types (adding fields on types from many locations) */
protected typeExtendMap: Record<string, NexusExtendTypeConfig<string>[] | null>;
/** All "extensions" to input types (adding fields on types from many locations) */
protected inputTypeExtendMap: Record<string, NexusExtendInputTypeConfig<string>[] | null>;
protected dynamicInputFields: DynamicInputFields;
protected dynamicOutputFields: DynamicOutputFields;
protected dynamicOutputProperties: DynamicOutputProperties;
protected plugins: NexusPlugin[];
private pendingTypeMap;
/**
* All "extensions" to types (adding fields on types from many locations)
*/
private typeExtendMap;
/**
* All "extensions" to input types (adding fields on types from many locations)
*/
private inputTypeExtendMap;
/**
* When we encounter "named" types from graphql-js, we keep them separate from Nexus definitions.
* This way we can have Nexus definitions take precedence without worrying about conflicts,
* particularly when we're looking to override behavior from inherited types.
*/
private graphqlNamedTypeMap;
/**
* If we're merging against a remote schema, the types from the schema are kept here,
* for fallbacks / merging when we're building the actual Schema
*/
private graphqlMergeSchemaMap;
private dynamicInputFields;
private dynamicOutputFields;
private dynamicOutputProperties;
private plugins;
/** All types that need to be traversed for children types */
protected typesToWalk: TypeToWalk[];
private typesToWalk;
/** Root type mapping information annotated on the type definitions */
protected sourceTypings: SourceTypings;
private sourceTypings;
/** Array of missing types */
protected missingTypes: Record<string, MissingType>;
private missingTypes;
/** Methods we are able to access to read/modify builder state from plugins */
protected builderLens: PluginBuilderLens;
private builderLens;
/** Created just before types are walked, this keeps track of all of the resolvers */
protected onMissingTypeFns: Exclude<PluginConfig['onMissingType'], undefined>[];
private onMissingTypeFns;
/** Executed just before types are walked */
protected onBeforeBuildFns: Exclude<PluginConfig['onBeforeBuild'], undefined>[];
private onBeforeBuildFns;
/** Executed as the field resolvers are included on the field */
protected onCreateResolverFns: Exclude<PluginConfig['onCreateFieldResolver'], undefined>[];
private onCreateResolverFns;
/** Executed as the field "subscribe" fields are included on the schema */
protected onCreateSubscribeFns: Exclude<PluginConfig['onCreateFieldSubscribe'], undefined>[];
private onCreateSubscribeFns;
/** Executed after the schema is constructed, for any final verification */
protected onAfterBuildFns: Exclude<PluginConfig['onAfterBuild'], undefined>[];
private onAfterBuildFns;
/** Executed after the object is defined, allowing us to add additional fields to the object */
protected onObjectDefinitionFns: Exclude<PluginConfig['onObjectDefinition'], undefined>[];
private onObjectDefinitionFns;
/** Executed after the object is defined, allowing us to add additional fields to the object */
protected onInputObjectDefinitionFns: Exclude<PluginConfig['onInputObjectDefinition'], undefined>[];
private onInputObjectDefinitionFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddArgFns: Exclude<PluginConfig['onAddArg'], undefined>[];
private onAddArgFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddOutputFieldFns: Exclude<PluginConfig['onAddOutputField'], undefined>[];
private onAddOutputFieldFns;
/** Called immediately after the field is defined, allows for using metadata to define the shape of the field. */
protected onAddInputFieldFns: Exclude<PluginConfig['onAddInputField'], undefined>[];
private onAddInputFieldFns;
/** The `schemaExtension` is created just after the types are walked, but before the fields are materialized. */
protected _schemaExtension?: NexusSchemaExtension;
protected config: BuilderConfig;
get schemaExtension(): NexusSchemaExtension;
private _schemaExtension?;
private config;
private get schemaExtension();
constructor(config: BuilderConfigInput);
setConfigOption: <K extends "features" | "nonNullDefaults" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K, value: BuilderConfigInput[K]) => void;
setConfigOption: <K extends "features" | "nonNullDefaults" | "mergeSchema" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K, value: BuilderConfigInput[K]) => void;
hasConfigOption: (key: keyof BuilderConfigInput) => boolean;
getConfigOption: <K extends "features" | "nonNullDefaults" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K) => BuilderConfigInput[K];
getConfigOption: <K extends "features" | "nonNullDefaults" | "mergeSchema" | "outputs" | "shouldGenerateArtifacts" | "sourceTypes" | "prettierConfig" | "formatTypegen" | "plugins" | "customPrintSchemaFn" | "contextType" | "schemaRoots">(key: K) => BuilderConfigInput[K];
hasType: (typeName: string) => boolean;

@@ -278,16 +332,16 @@ /**

*/
addType: (typeDef: NexusAcceptedTypeDef) => void;
private addType;
addTypes(types: any): void;
private addToNexusMeta;
rebuildNamedOutputFields(config: ReturnType<GraphQLObjectType['toConfig'] | GraphQLInterfaceType['toConfig']>): Record<string, any>;
walkTypes(): void;
beforeWalkTypes(): void;
beforeBuildTypes(): void;
checkForInterfaceCircularDependencies(): void;
buildNexusTypes(): void;
createSchemaExtension(): void;
private walkTypes;
private beforeWalkTypes;
private beforeBuildTypes;
private checkForInterfaceCircularDependencies;
private buildNexusTypes;
private createSchemaExtension;
getFinalTypeMap(): BuildTypes<any>;
buildInputObjectType(config: NexusInputObjectTypeConfig<any>): GraphQLInputObjectType;
buildObjectType(config: NexusObjectTypeConfig<string>): GraphQLObjectType<any, any>;
buildInterfaceType(config: NexusInterfaceTypeConfig<any>): GraphQLInterfaceType;
private shouldMerge;
private buildInputObjectType;
private buildObjectType;
private buildInterfaceType;
private addOutputField;

@@ -298,38 +352,37 @@ private addInputField;

private buildScalarType;
protected finalize<T extends GraphQLNamedType>(type: T): T;
protected missingType(typeName: string, fromObject?: boolean): GraphQLNamedType;
protected buildUnionMembers(unionName: string, members: UnionMembers | undefined): GraphQLObjectType<any, any>[];
protected buildInterfaceList(interfaces: (string | NexusInterfaceTypeDef<any>)[]): GraphQLInterfaceType[];
protected buildInterfaceFields(forTypeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig, interfaces: (string | NexusInterfaceTypeDef<any>)[], modifications: Record<string, FieldModificationDef<any, any>>): GraphQLFieldConfigMap<any, any>;
protected buildOutputFields(fields: NexusOutputFieldDef[], typeConfig: NexusGraphQLInterfaceTypeConfig | NexusGraphQLObjectTypeConfig, intoObject: GraphQLFieldConfigMap<any, any>): GraphQLFieldConfigMap<any, any>;
protected buildInputObjectFields(fields: NexusInputFieldDef[], typeConfig: NexusGraphQLInputObjectTypeConfig): GraphQLInputFieldConfigMap;
protected getNonNullDefault(nonNullDefaultConfig: {
nonNullDefaults?: NonNullConfig;
} | undefined, kind: 'input' | 'output'): boolean;
protected buildOutputField(fieldConfig: NexusOutputFieldDef, typeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig): GraphQLFieldConfig<any, any>;
protected makeFinalResolver(info: CreateFieldResolverInfo, resolver?: GraphQLFieldResolver<any, any>): GraphQLFieldResolver<any, any, {
[argName: string]: any;
}>;
protected buildInputObjectField(fieldConfig: NexusInputFieldDef, typeConfig: NexusGraphQLInputObjectTypeConfig): GraphQLInputFieldConfig;
protected buildArgs(args: ArgsRecord, typeConfig: NexusGraphQLObjectTypeConfig | NexusGraphQLInterfaceTypeConfig, fieldName: string): GraphQLFieldConfigArgumentMap;
protected getInterface(name: string | NexusInterfaceTypeDef<any>): GraphQLInterfaceType;
protected getInputType(possibleInputType: PossibleInputType): Exclude<GraphQLInputType, GraphQLNonNull<any> | GraphQLList<any>>;
protected getOutputType(possibleOutputType: PossibleOutputType): Exclude<GraphQLOutputType, GraphQLNonNull<any> | GraphQLList<any>>;
protected getObjectOrInterfaceType(name: string | NexusObjectTypeDef<string>): GraphQLObjectType | GraphQLInterfaceType;
protected getObjectType(name: string | NexusObjectTypeDef<string>): GraphQLObjectType;
protected getOrBuildType(type: string | AllNexusNamedTypeDefs | GraphQLNamedType, fromObject?: boolean): GraphQLNamedType;
protected walkInputType<T extends NexusShapedInput>(obj: T): T;
addDynamicInputFields(block: InputDefinitionBlock<any>, wrapping?: NexusWrapKind[]): void;
addDynamicOutputMembers(block: OutputDefinitionBlock<any>, stage: 'walk' | 'build', wrapping?: NexusWrapKind[]): void;
addDynamicScalar(methodName: string, typeName: string, block: OutputDefinitionBlock<any> | InputDefinitionBlock<any>): void;
protected walkOutputType<T extends NexusShapedOutput>(obj: T): T;
protected walkInterfaceType(obj: NexusInterfaceTypeConfig<any>): NexusInterfaceTypeConfig<any>;
protected maybeTraverseModification(mod: FieldModificationDef<any, any>): void;
protected maybeTraverseOutputFieldType(type: NexusOutputFieldDef): void;
private finalize;
private missingType;
private buildUnionMembers;
private buildInterfaceList;
private buildInterfaceFields;
private buildOutputFields;
private buildInputObjectFields;
private getNonNullDefault;
private buildOutputField;
private makeFinalResolver;
private buildInputObjectField;
private buildArgs;
private getInterface;
private getInputType;
private getOutputType;
private getObjectType;
private getOrBuildType;
private walkInputType;
private addDynamicInputFields;
private addDynamicOutputMembers;
private addDynamicField;
private walkOutputType;
private walkInterfaceType;
private maybeTraverseModification;
private maybeTraverseOutputFieldType;
private traverseArgs;
protected maybeTraverseInputFieldType(type: NexusInputFieldDef): void;
protected walkNamedTypes(namedType: GraphQLNamedType): void;
protected addUnknownTypeInternal(t: GraphQLNamedType): void;
protected addNamedTypeOutputField(obj: GraphQLField<any, any>): void;
protected replaceNamedType(type: GraphQLType): any;
private maybeTraverseInputFieldType;
/**
* Given a "mergeSchema", gathers all of the types and constructs them
* into a map of types that we keep as a "merge schema"
*
* @param config
*/
private handleMergeSchema;
private handleNativeType;
}

@@ -336,0 +389,0 @@ export declare type DynamicFieldDefs = {

@@ -18,2 +18,3 @@ "use strict";

const nexusMeta_1 = require("./definitions/nexusMeta");
const rebuildType_1 = require("./rebuildType");
const SCALARS = {

@@ -49,6 +50,21 @@ String: graphql_1.GraphQLString,

this.pendingTypeMap = {};
/** All "extensions" to types (adding fields on types from many locations) */
/**
* All "extensions" to types (adding fields on types from many locations)
*/
this.typeExtendMap = {};
/** All "extensions" to input types (adding fields on types from many locations) */
/**
* All "extensions" to input types (adding fields on types from many locations)
*/
this.inputTypeExtendMap = {};
/**
* When we encounter "named" types from graphql-js, we keep them separate from Nexus definitions.
* This way we can have Nexus definitions take precedence without worrying about conflicts,
* particularly when we're looking to override behavior from inherited types.
*/
this.graphqlNamedTypeMap = {};
/**
* If we're merging against a remote schema, the types from the schema are kept here,
* for fallbacks / merging when we're building the actual Schema
*/
this.graphqlMergeSchemaMap = {};
this.dynamicInputFields = {};

@@ -94,3 +110,6 @@ this.dynamicOutputFields = {};

this.hasType = (typeName) => {
return Boolean(this.pendingTypeMap[typeName] || this.finalTypeMap[typeName]);
return Boolean(this.pendingTypeMap[typeName] ||
this.finalTypeMap[typeName] ||
this.graphqlNamedTypeMap[typeName] ||
this.graphqlMergeSchemaMap[typeName]);
};

@@ -103,7 +122,3 @@ /**

this.addType = (typeDef) => {
var _a, _b;
if (nexusMeta_1.isNexusMeta(typeDef)) {
this.addToNexusMeta(typeDef);
return;
}
var _a, _b, _c;
if (wrapping_1.isNexusDynamicInputMethod(typeDef)) {

@@ -121,7 +136,10 @@ this.dynamicInputFields[typeDef.name] = typeDef;

}
if (nexusMeta_1.isNexusMeta(typeDef)) {
this.addToNexusMeta(typeDef);
return;
}
// Don't worry about internal types.
if (((_a = typeDef.name) === null || _a === void 0 ? void 0 : _a.indexOf('__')) === 0) {
if ((_a = typeDef.name) === null || _a === void 0 ? void 0 : _a.startsWith('__')) {
return;
}
const existingType = this.definedTypeMap[typeDef.name] || this.pendingTypeMap[typeDef.name];
if (wrapping_1.isNexusExtendTypeDef(typeDef)) {

@@ -140,50 +158,60 @@ const typeExtensions = (this.typeExtendMap[typeDef.name] = this.typeExtendMap[typeDef.name] || []);

}
// Check the "defined" type map for existing Nexus types. We are able to conflict with external types,
// as we assume that locally defined types take precedence.
const existingType = this.pendingTypeMap[typeDef.name];
// If we already have a "Nexus" type, but it's not the same, trigger mark as an error,
// otherwise early exit
if (existingType) {
// Allow importing the same exact type more than once.
if (existingType === typeDef) {
return;
if (existingType !== typeDef) {
throw extendError(typeDef.name);
}
throw extendError(typeDef.name);
return;
}
if (wrapping_1.isNexusScalarTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicInputFields[typeDef.value.asNexusMethod] = typeDef.name;
this.dynamicOutputFields[typeDef.value.asNexusMethod] = typeDef.name;
if (typeDef.value.sourceType) {
if (wrapping_1.isNexusNamedTypeDef(typeDef)) {
if (wrapping_1.isNexusNamedOuputTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicOutputFields[typeDef.value.asNexusMethod] = typeDef.name;
}
if (wrapping_1.isNexusNamedInputTypeDef(typeDef) && typeDef.value.asNexusMethod) {
this.dynamicInputFields[typeDef.value.asNexusMethod] = typeDef.name;
}
if (wrapping_1.isNexusScalarTypeDef(typeDef) && typeDef.value.sourceType) {
this.sourceTypings[typeDef.name] = typeDef.value.sourceType;
}
}
else if (graphql_1.isScalarType(typeDef)) {
const scalarDef = typeDef;
if ((_b = scalarDef.extensions) === null || _b === void 0 ? void 0 : _b.nexus) {
const { asNexusMethod, sourceType: rootTyping } = scalarDef.extensions.nexus;
// If it's a concrete GraphQL type, we handle it directly by convering the
// type to a Nexus structure, and capturing all of the referenced types
// while we're reconstructing.
if (graphql_1.isNamedType(typeDef)) {
// If we've already captured the named type, we can skip it
if (this.graphqlNamedTypeMap[typeDef.name]) {
return;
}
// If we've used decorateType to wrap, then we can grab the types off
if ((_b = typeDef.extensions) === null || _b === void 0 ? void 0 : _b.nexus) {
const { asNexusMethod, sourceType } = typeDef.extensions.nexus;
if (asNexusMethod) {
this.dynamicInputFields[asNexusMethod] = scalarDef.name;
this.dynamicOutputFields[asNexusMethod] = typeDef.name;
if (graphql_1.isInputType(typeDef)) {
this.dynamicInputFields[asNexusMethod] = typeDef.name;
}
if (graphql_1.isOutputType(typeDef)) {
this.dynamicOutputFields[asNexusMethod] = typeDef.name;
}
}
if (rootTyping) {
this.sourceTypings[scalarDef.name] = rootTyping;
if (sourceType) {
this.sourceTypings[typeDef.name] = sourceType;
}
}
}
if (graphql_1.isNamedType(typeDef)) {
let finalTypeDef = typeDef;
if (graphql_1.isObjectType(typeDef)) {
const config = typeDef.toConfig();
finalTypeDef = new graphql_1.GraphQLObjectType(Object.assign(Object.assign({}, config), { fields: () => this.rebuildNamedOutputFields(config), interfaces: () => config.interfaces.map((t) => this.getInterface(t.name)) }));
this.graphqlNamedTypeMap[typeDef.name] = this.handleNativeType(typeDef, {
captureLeafType: (t) => {
if (!this.graphqlNamedTypeMap[t.name] && t.name !== typeDef.name) {
this.addType(t);
}
},
});
if ((_c = typeDef.extensions) === null || _c === void 0 ? void 0 : _c.nexus) {
this.addType(this.graphqlNamedTypeMap[typeDef.name]);
}
else if (graphql_1.isInterfaceType(typeDef)) {
const config = utils_1.graphql15InterfaceConfig(typeDef.toConfig());
finalTypeDef = new graphql_1.GraphQLInterfaceType(Object.assign(Object.assign({}, config), { fields: () => this.rebuildNamedOutputFields(config), interfaces: () => config.interfaces.map((t) => this.getInterface(t.name)) }));
}
else if (graphql_1.isUnionType(typeDef)) {
const config = typeDef.toConfig();
finalTypeDef = new graphql_1.GraphQLUnionType(Object.assign(Object.assign({}, config), { types: () => config.types.map((t) => this.getObjectType(t.name)) }));
}
this.finalTypeMap[typeDef.name] = finalTypeDef;
this.definedTypeMap[typeDef.name] = typeDef;
this.typesToWalk.push({ type: 'named', value: typeDef });
return;
}
else {
this.pendingTypeMap[typeDef.name] = typeDef;
}
this.pendingTypeMap[typeDef.name] = typeDef;
if (wrapping_1.isNexusInputObjectTypeDef(typeDef)) {

@@ -212,2 +240,5 @@ this.typesToWalk.push({ type: 'input', value: typeDef.value });

});
if (config.mergeSchema) {
this.graphqlMergeSchemaMap = this.handleMergeSchema(config.mergeSchema);
}
}

@@ -222,3 +253,3 @@ get schemaExtension() {

addTypes(types) {
var _a;
var _a, _b;
if (!types) {

@@ -228,7 +259,18 @@ return;

if (graphql_1.isSchema(types)) {
this.addTypes(types.getTypeMap());
if (((_a = this.config.mergeSchema) === null || _a === void 0 ? void 0 : _a.schema) === types) {
return;
}
else if (!this.config.mergeSchema) {
if (Object.keys(this.graphqlMergeSchemaMap).length) {
console.error(new Error(`It looks like you're trying to merge multiple GraphQL schemas.\n Please open a GitHub ticket with more info about your use case.`));
}
this.graphqlMergeSchemaMap = this.handleMergeSchema({ schema: types });
}
else {
this.addTypes(types.getTypeMap());
}
return;
}
if (wrapping_1.isNexusPlugin(types)) {
if (!((_a = this.plugins) === null || _a === void 0 ? void 0 : _a.includes(types))) {
if (!((_b = this.plugins) === null || _b === void 0 ? void 0 : _b.includes(types))) {
throw new Error(`Nexus plugin ${types.config.name} was seen in the "types" config, but should instead be provided to the "plugins" array.`);

@@ -268,17 +310,2 @@ }

}
rebuildNamedOutputFields(config) {
const { fields } = config, rest = tslib_1.__rest(config, ["fields"]);
const fieldsConfig = typeof fields === 'function' ? fields() : fields;
return utils_1.mapValues(fieldsConfig, (val, key) => {
const { resolve, type } = val, fieldConfig = tslib_1.__rest(val, ["resolve", "type"]);
const finalType = this.replaceNamedType(type);
return Object.assign(Object.assign({}, fieldConfig), { type: finalType, resolve: this.makeFinalResolver({
builder: this.builderLens,
fieldConfig: Object.assign(Object.assign({}, fieldConfig), { type: finalType, name: key }),
schemaConfig: this.config,
parentTypeConfig: rest,
schemaExtension: this.schemaExtension,
}, resolve) });
});
}
walkTypes() {

@@ -294,5 +321,2 @@ let obj;

break;
case 'named':
this.walkNamedTypes(obj.value);
break;
case 'object':

@@ -404,3 +428,3 @@ this.walkOutputType(obj.value);

// If Query isn't defined, set it to null so it falls through to "missingType"
if (!this.pendingTypeMap.Query && !((_a = this.config.schemaRoots) === null || _a === void 0 ? void 0 : _a.query)) {
if (!this.pendingTypeMap.Query && !((_a = this.config.schemaRoots) === null || _a === void 0 ? void 0 : _a.query) && !this.typeExtendMap.Query) {
this.pendingTypeMap.Query = null;

@@ -425,3 +449,3 @@ }

// If we haven't defined the type, assume it's an object type
if (this.typeExtendMap[key] !== null) {
if (this.typeExtendMap[key] !== null && !this.hasType(key)) {
this.buildObjectType({

@@ -435,3 +459,3 @@ name: key,

// If we haven't defined the type, assume it's an input object type
if (this.inputTypeExtendMap[key] !== null) {
if (this.inputTypeExtendMap[key] !== null && !this.hasType(key)) {
this.buildInputObjectType({

@@ -466,2 +490,9 @@ name: key,

}
shouldMerge(typeName) {
if (!this.config.mergeSchema) {
return false;
}
const { mergeTypes = ['Query', 'Mutation'] } = this.config.mergeSchema;
return Boolean(mergeTypes === true || mergeTypes.includes(typeName));
}
buildInputObjectType(config) {

@@ -475,2 +506,6 @@ const fields = [];

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && wrapping_1.isNexusInputObjectTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -507,2 +542,6 @@ this.onInputObjectDefinitionFns.forEach((fn) => {

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && wrapping_1.isNexusObjectTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -546,2 +585,6 @@ this.onObjectDefinitionFns.forEach((fn) => {

});
const externalNamedType = this.graphqlMergeSchemaMap[config.name];
if (this.shouldMerge(config.name) && wrapping_1.isNexusInterfaceTypeDef(externalNamedType)) {
externalNamedType.value.definition(definitionBlock);
}
config.definition(definitionBlock);

@@ -683,3 +726,4 @@ if (config.sourceType) {

}
return utils_1.UNKNOWN_TYPE_SCALAR;
this.addType(utils_1.UNKNOWN_TYPE_SCALAR);
return this.getOrBuildType(utils_1.UNKNOWN_TYPE_SCALAR);
}

@@ -736,3 +780,3 @@ buildUnionMembers(unionName, members) {

if (typeof args !== 'undefined') {
interfaceFieldsMap[field].args = Object.assign(Object.assign({}, this.buildArgs(args, forTypeConfig, field)), interfaceFieldsMap[field].args);
interfaceFieldsMap[field].args = Object.assign(Object.assign({}, this.buildArgs(args !== null && args !== void 0 ? args : {}, forTypeConfig, field)), interfaceFieldsMap[field].args);
}

@@ -811,9 +855,9 @@ }

buildArgs(args, typeConfig, fieldName) {
var _a, _b, _c, _d;
const allArgs = {};
Object.keys(args).forEach((argName) => {
var _a, _b, _c, _d;
for (const [argName, arg] of Object.entries(args)) {
const nonNullDefault = this.getNonNullDefault((_b = (_a = typeConfig.extensions) === null || _a === void 0 ? void 0 : _a.nexus) === null || _b === void 0 ? void 0 : _b.config, 'input');
let finalArgDef = Object.assign(Object.assign({}, wrapping_1.normalizeArgWrapping(args[argName]).value), { fieldName,
let finalArgDef = Object.assign(Object.assign({}, wrapping_1.normalizeArgWrapping(arg).value), { fieldName,
argName, parentType: typeConfig.name, configFor: 'arg' });
this.onAddArgFns.forEach((onArgDef) => {
for (const onArgDef of this.onAddArgFns) {
const result = onArgDef(finalArgDef);

@@ -823,3 +867,3 @@ if (result != null) {

}
});
}
const { namedType, wrapping } = wrapping_1.unwrapNexusDef(finalArgDef.type);

@@ -833,3 +877,3 @@ const finalWrap = wrapping_1.finalizeWrapping(nonNullDefault, wrapping);

};
});
}
return allArgs;

@@ -862,13 +906,2 @@ }

}
getObjectOrInterfaceType(name) {
if (wrapping_1.isNexusNamedTypeDef(name)) {
return this.getObjectOrInterfaceType(name.name);
}
const type = this.getOrBuildType(name);
if (!graphql_1.isObjectType(type) && !graphql_1.isInterfaceType(type)) {
/* istanbul ignore next */
throw new Error(`Expected ${name} to be a objectType / interfaceType, saw ${type.constructor.name}`);
}
return type;
}
getObjectType(name) {

@@ -886,2 +919,3 @@ if (wrapping_1.isNexusNamedTypeDef(name)) {

getOrBuildType(type, fromObject = false) {
var _a, _b;
utils_1.invariantGuard(type);

@@ -904,3 +938,3 @@ if (graphql_1.isNamedType(type)) {

}
const pendingType = this.pendingTypeMap[type];
const pendingType = (_b = (_a = this.pendingTypeMap[type]) !== null && _a !== void 0 ? _a : this.graphqlNamedTypeMap[type]) !== null && _b !== void 0 ? _b : this.graphqlMergeSchemaMap[type];
if (wrapping_1.isNexusNamedTypeDef(pendingType)) {

@@ -945,3 +979,3 @@ this.buildingTypes.add(pendingType.name);

if (typeof val === 'string') {
return this.addDynamicScalar(methodName, val, block);
return this.addDynamicField(methodName, val, block);
}

@@ -963,3 +997,3 @@ // @ts-ignore

if (typeof val === 'string') {
return this.addDynamicScalar(methodName, val, block);
return this.addDynamicField(methodName, val, block);
}

@@ -992,3 +1026,3 @@ // @ts-ignore

}
addDynamicScalar(methodName, typeName, block) {
addDynamicField(methodName, typeName, block) {
// @ts-ignore

@@ -1083,41 +1117,34 @@ block[methodName] = (fieldName, opts) => {

}
walkNamedTypes(namedType) {
if (graphql_1.isObjectType(namedType) || graphql_1.isInterfaceType(namedType)) {
utils_1.eachObj(namedType.getFields(), (val) => this.addNamedTypeOutputField(val));
/**
* Given a "mergeSchema", gathers all of the types and constructs them
* into a map of types that we keep as a "merge schema"
*
* @param config
*/
handleMergeSchema(config) {
var _a;
const { types } = config.schema.toConfig();
const mergedTypes = {};
// We don't need to worry about capturing any types while walking,
// because we have the entire schema
for (const type of types) {
if (type.name.startsWith('__')) {
continue;
}
if ((_a = config.skipTypes) === null || _a === void 0 ? void 0 : _a.includes(type.name)) {
continue;
}
mergedTypes[type.name] = this.handleNativeType(type, config);
}
if (graphql_1.isObjectType(namedType)) {
namedType.getInterfaces().forEach((i) => this.addUnknownTypeInternal(i));
}
if (graphql_1.isInputObjectType(namedType)) {
utils_1.eachObj(namedType.getFields(), (val) => this.addUnknownTypeInternal(graphql_1.getNamedType(val.type)));
}
if (graphql_1.isUnionType(namedType)) {
namedType.getTypes().forEach((type) => this.addUnknownTypeInternal(type));
}
return mergedTypes;
}
addUnknownTypeInternal(t) {
if (!this.definedTypeMap[t.name]) {
this.addType(t);
handleNativeType(type, config) {
var _a;
var _b, _c;
while (graphql_1.isWrappingType(type)) {
type = type.ofType;
}
(_a = (_b = this.pendingTypeMap)[_c = type.name]) !== null && _a !== void 0 ? _a : (_b[_c] = null);
return rebuildType_1.rebuildNamedType(type, config);
}
addNamedTypeOutputField(obj) {
this.addUnknownTypeInternal(graphql_1.getNamedType(obj.type));
if (obj.args) {
obj.args.forEach((val) => this.addType(graphql_1.getNamedType(val.type)));
}
}
replaceNamedType(type) {
let wrappingTypes = [];
let finalType = type;
while (graphql_1.isWrappingType(finalType)) {
wrappingTypes.unshift(finalType.constructor);
finalType = finalType.ofType;
}
if (this.finalTypeMap[finalType.name] === this.definedTypeMap[finalType.name]) {
return type;
}
return wrappingTypes.reduce((result, Wrapper) => {
return new Wrapper(result);
}, this.finalTypeMap[finalType.name]);
}
}

@@ -1124,0 +1151,0 @@ exports.SchemaBuilder = SchemaBuilder;

@@ -29,2 +29,3 @@ export * from './builder';

export * from './plugins';
export * from './rebuildType';
export * from './sdlConverter';

@@ -31,0 +32,0 @@ export * from './typegenAutoConfig';

@@ -34,2 +34,3 @@ "use strict";

tslib_1.__exportStar(require("./plugins"), exports);
tslib_1.__exportStar(require("./rebuildType"), exports);
tslib_1.__exportStar(require("./sdlConverter"), exports);

@@ -36,0 +37,0 @@ tslib_1.__exportStar(require("./typegenAutoConfig"), exports);

import type { GraphQLScalarTypeConfig } from 'graphql';
import type { AllNexusInputTypeDefs } from '../core';
import type { AllInputTypes, GetGen2 } from '../typegenTypeHelpers';
import type { AllNexusArgsDefs } from './wrapping';
import type { AllNexusArgsDefs, AllNexusInputTypeDefs } from './wrapping';
import { Maybe } from './_types';

@@ -6,0 +5,0 @@ export declare type ArgsRecord = Record<string, AllNexusArgsDefs>;

@@ -7,5 +7,2 @@ import type { GraphQLNamedType } from 'graphql';

}
export declare type NexusTypeExtensions = {
nexus: TypeExtensionConfig;
};
export declare function decorateType<T extends GraphQLNamedType>(type: T, config: TypeExtensionConfig): T;

@@ -5,6 +5,4 @@ "use strict";

function decorateType(type, config) {
type.extensions = Object.assign(Object.assign({}, type.extensions), { nexus: {
asNexusMethod: config.asNexusMethod,
sourceType: config.sourceType,
} });
var _a;
type.extensions = Object.assign(Object.assign({}, type.extensions), { nexus: Object.assign(Object.assign({}, (_a = type.extensions) === null || _a === void 0 ? void 0 : _a.nexus), config) });
return type;

@@ -11,0 +9,0 @@ }

@@ -66,3 +66,3 @@ import type { GraphQLFieldConfig, GraphQLFieldResolver, GraphQLInputFieldConfig } from 'graphql';

*/
args?: ArgsRecord;
args?: Maybe<ArgsRecord>;
/**

@@ -69,0 +69,0 @@ * Data that will be added to the field-level [extensions field on the graphql-js type def

@@ -40,2 +40,4 @@ import { GraphQLEnumTypeConfig, GraphQLEnumValueConfig } from 'graphql';

extensions?: GraphQLEnumTypeConfig['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
}

@@ -42,0 +44,0 @@ export declare class NexusEnumTypeDef<TypeName extends string> {

@@ -23,2 +23,4 @@ import { GraphQLInputObjectTypeConfig } from 'graphql';

extensions?: GraphQLInputObjectTypeConfig['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & NexusGenPluginInputTypeConfig<TypeName>;

@@ -25,0 +27,0 @@ export declare class NexusInputObjectTypeDef<TypeName extends string> {

@@ -14,3 +14,3 @@ import { GraphQLInterfaceTypeConfig } from 'graphql';

/** You are allowed to add non-required args when modifying a field */
args?: ArgsRecord;
args?: Maybe<ArgsRecord>;
/**

@@ -44,2 +44,4 @@ * Custom extensions, as supported in graphql-js

extensions?: GraphQLInterfaceTypeConfig<any, any>['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>;

@@ -46,0 +48,0 @@ export interface InterfaceDefinitionBuilder<TypeName extends string> extends OutputDefinitionBuilder {

@@ -181,2 +181,4 @@ import { GraphQLObjectType } from 'graphql';

definition(t: ObjectDefinitionBlock<TypeName>): void;
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldIsTypeOf<TypeName> & NexusGenPluginTypeConfig<TypeName>;

@@ -183,0 +185,0 @@ export declare class NexusObjectTypeDef<TypeName extends string> {

@@ -1,3 +0,4 @@

import { GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql';
import { Maybe, SourceTypingDef } from './_types';
import { GraphQLNamedType, GraphQLScalarTypeConfig } from 'graphql';
import type { AllNexusInputTypeDefs, AllNexusOutputTypeDefs } from '../core';
import { GraphQLNamedOutputType, Maybe, SourceTypingDef } from './_types';
export interface ScalarBase extends Pick<GraphQLScalarTypeConfig<any, any>, 'description' | 'serialize' | 'parseValue' | 'parseLiteral'> {

@@ -30,2 +31,2 @@ }

export declare function scalarType<TypeName extends string>(options: NexusScalarTypeConfig<TypeName>): NexusScalarTypeDef<TypeName>;
export declare function asNexusMethod<T extends GraphQLScalarType>(scalar: T, methodName: string, sourceType?: SourceTypingDef): T;
export declare function asNexusMethod<T extends GraphQLNamedType>(namedType: T, methodName: string, sourceType?: SourceTypingDef): T extends GraphQLNamedOutputType ? AllNexusOutputTypeDefs : AllNexusInputTypeDefs;

@@ -23,4 +23,4 @@ "use strict";

exports.scalarType = scalarType;
function asNexusMethod(scalar, methodName, sourceType) {
return decorateType_1.decorateType(scalar, {
function asNexusMethod(namedType, methodName, sourceType) {
return decorateType_1.decorateType(namedType, {
asNexusMethod: methodName,

@@ -27,0 +27,0 @@ sourceType,

@@ -39,2 +39,4 @@ import { GraphQLUnionTypeConfig } from 'graphql';

extensions?: GraphQLUnionTypeConfig<any, any>['extensions'];
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string;
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>;

@@ -41,0 +43,0 @@ export declare class NexusUnionTypeDef<TypeName extends string> {

@@ -87,2 +87,4 @@ import { GraphQLInputType, GraphQLList, GraphQLNamedType, GraphQLNonNull, GraphQLType } from 'graphql';

export declare function isNexusArgDef(obj: any): obj is NexusArgDef<AllInputTypes>;
export declare function isNexusNamedOuputTypeDef(obj: any): obj is AllNexusNamedOutputTypeDefs;
export declare function isNexusNamedInputTypeDef(obj: any): obj is AllNexusNamedInputTypeDefs;
export declare function isNexusDynamicOutputProperty<T extends string>(obj: any): obj is DynamicOutputPropertyDef<T>;

@@ -89,0 +91,0 @@ export declare function isNexusDynamicOutputMethod<T extends string>(obj: any): obj is DynamicOutputMethodDef<T>;

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.finalizeWrapping = exports.applyNexusWrapping = exports.normalizeArgWrapping = exports.rewrapAsGraphQLType = exports.unwrapNexusDef = exports.unwrapGraphQLDef = exports.isNexusPlugin = exports.isNexusPrintedGenTypingImport = exports.isNexusPrintedGenTyping = exports.isNexusDynamicInputMethod = exports.isNexusDynamicOutputMethod = exports.isNexusDynamicOutputProperty = exports.isNexusArgDef = exports.isNexusInterfaceTypeDef = exports.isNexusUnionTypeDef = exports.isNexusScalarTypeDef = exports.isNexusObjectTypeDef = exports.isNexusInputObjectTypeDef = exports.isNexusEnumTypeDef = exports.isNexusExtendTypeDef = exports.isNexusExtendInputTypeDef = exports.isNexusWrappingType = exports.isNexusNullTypeDef = exports.isNexusNonNullTypeDef = exports.isNexusListTypeDef = exports.isNexusNamedTypeDef = exports.isNexusStruct = exports.isNexusTypeDef = void 0;
exports.finalizeWrapping = exports.applyNexusWrapping = exports.normalizeArgWrapping = exports.rewrapAsGraphQLType = exports.unwrapNexusDef = exports.unwrapGraphQLDef = exports.isNexusPlugin = exports.isNexusPrintedGenTypingImport = exports.isNexusPrintedGenTyping = exports.isNexusDynamicInputMethod = exports.isNexusDynamicOutputMethod = exports.isNexusDynamicOutputProperty = exports.isNexusNamedInputTypeDef = exports.isNexusNamedOuputTypeDef = exports.isNexusArgDef = exports.isNexusInterfaceTypeDef = exports.isNexusUnionTypeDef = exports.isNexusScalarTypeDef = exports.isNexusObjectTypeDef = exports.isNexusInputObjectTypeDef = exports.isNexusEnumTypeDef = exports.isNexusExtendTypeDef = exports.isNexusExtendInputTypeDef = exports.isNexusWrappingType = exports.isNexusNullTypeDef = exports.isNexusNonNullTypeDef = exports.isNexusListTypeDef = exports.isNexusNamedTypeDef = exports.isNexusStruct = exports.isNexusTypeDef = void 0;
const graphql_1 = require("graphql");

@@ -85,2 +85,10 @@ const utils_1 = require("../utils");

exports.isNexusArgDef = isNexusArgDef;
function isNexusNamedOuputTypeDef(obj) {
return isNexusNamedTypeDef(obj) && !isNexusInputObjectTypeDef(obj);
}
exports.isNexusNamedOuputTypeDef = isNexusNamedOuputTypeDef;
function isNexusNamedInputTypeDef(obj) {
return isNexusNamedTypeDef(obj) && !isNexusObjectTypeDef(obj) && !isNexusInterfaceTypeDef(obj);
}
exports.isNexusNamedInputTypeDef = isNexusNamedInputTypeDef;
function isNexusDynamicOutputProperty(obj) {

@@ -87,0 +95,0 @@ return isNexusStruct(obj) && obj[_types_1.NexusWrappedSymbol] === _types_1.NexusTypes.DynamicOutputProperty;

import { GraphQLNamedType } from 'graphql';
import type { DynamicFieldDefs, SchemaConfig } from './builder';
import type { SourceTypingDef, SourceTypings } from './definitions/_types';
import type { SourceTypings } from './definitions/_types';
import type { NexusOutputFieldConfig } from './definitions/definitionBlocks';

@@ -52,7 +52,1 @@ import type { NexusInputObjectTypeConfig } from './definitions/inputObjectType';

}
export declare type NexusScalarExtensions = {
nexus: {
asNexusMethod?: string;
sourceType?: SourceTypingDef;
};
};

@@ -105,3 +105,3 @@ "use strict";

Object.keys(typeMap).forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return;

@@ -108,0 +108,0 @@ }

@@ -120,1 +120,2 @@ import { GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLInterfaceTypeConfig, GraphQLNamedType, GraphQLObjectType, GraphQLResolveInfo, GraphQLScalarType, GraphQLSchema, GraphQLType, GraphQLUnionType } from 'graphql';

};
export declare function result<T>(val: T | (() => T)): T;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ownProp = exports.isArray = exports.graphql15InterfaceType = exports.graphql15InterfaceConfig = exports.Unreachable = exports.raiseProgrammerError = exports.isProductionStage = exports.invariantGuard = exports.getNexusNamedType = exports.getArgNamedType = exports.resolveImportPath = exports.dump = exports.casesHandled = exports.getOwnPackage = exports.pathToArray = exports.UNKNOWN_TYPE_SCALAR = exports.venn = exports.log = exports.consoleWarn = exports.runAbstractTypeRuntimeChecks = exports.assertNoMissingTypes = exports.printedGenTyping = exports.PrintedGenTyping = exports.printedGenTypingImport = exports.PrintedGenTypingImport = exports.relativePathTo = exports.formatPathForModuleImport = exports.typeScriptFileExtension = exports.isPromiseLike = exports.firstDefined = exports.isUnknownType = exports.groupTypes = exports.assertAbsolutePath = exports.isObject = exports.eachObj = exports.mapValues = exports.mapObj = exports.objValues = exports.suggestionList = exports.isInterfaceField = void 0;
exports.result = exports.ownProp = exports.isArray = exports.graphql15InterfaceType = exports.graphql15InterfaceConfig = exports.Unreachable = exports.raiseProgrammerError = exports.isProductionStage = exports.invariantGuard = exports.getNexusNamedType = exports.getArgNamedType = exports.resolveImportPath = exports.dump = exports.casesHandled = exports.getOwnPackage = exports.pathToArray = exports.UNKNOWN_TYPE_SCALAR = exports.venn = exports.log = exports.consoleWarn = exports.runAbstractTypeRuntimeChecks = exports.assertNoMissingTypes = exports.printedGenTyping = exports.PrintedGenTyping = exports.printedGenTypingImport = exports.PrintedGenTypingImport = exports.relativePathTo = exports.formatPathForModuleImport = exports.typeScriptFileExtension = exports.isPromiseLike = exports.firstDefined = exports.isUnknownType = exports.groupTypes = exports.assertAbsolutePath = exports.isObject = exports.eachObj = exports.mapValues = exports.mapObj = exports.objValues = exports.suggestionList = exports.isInterfaceField = void 0;
const tslib_1 = require("tslib");

@@ -125,3 +125,3 @@ const fs = tslib_1.__importStar(require("fs"));

.forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return;

@@ -525,2 +525,9 @@ }

};
function result(val) {
if (val instanceof Function) {
return val();
}
return val;
}
exports.result = result;
//# sourceMappingURL=utils.js.map
{
"name": "nexus",
"version": "1.2.0-next.13",
"version": "1.2.0-next.14",
"description": "Scalable, strongly typed GraphQL schema development",

@@ -5,0 +5,0 @@ "keywords": [

@@ -31,2 +31,3 @@ // The "core" is used as a namespace to re-export everything,

export * from './plugins'
export * from './rebuildType'
export * from './sdlConverter'

@@ -33,0 +34,0 @@ export * from './typegenAutoConfig'

import type { GraphQLScalarTypeConfig } from 'graphql'
import type { AllNexusInputTypeDefs } from '../core'
import type { AllInputTypes, GetGen2 } from '../typegenTypeHelpers'
import type { AllNexusArgsDefs } from './wrapping'
import type { AllNexusArgsDefs, AllNexusInputTypeDefs } from './wrapping'
import { Maybe, NexusTypes, withNexusSymbol } from './_types'

@@ -6,0 +5,0 @@

@@ -9,6 +9,2 @@ import type { GraphQLNamedType } from 'graphql'

export type NexusTypeExtensions = {
nexus: TypeExtensionConfig
}
export function decorateType<T extends GraphQLNamedType>(type: T, config: TypeExtensionConfig): T {

@@ -18,7 +14,7 @@ type.extensions = {

nexus: {
asNexusMethod: config.asNexusMethod,
sourceType: config.sourceType,
...type.extensions?.nexus,
...config,
},
}
return type as any
return type
}

@@ -17,6 +17,4 @@ import type { GraphQLFieldConfig, GraphQLFieldResolver, GraphQLInputFieldConfig } from 'graphql'

export interface CommonFieldConfig {
//todo
/** The description to annotate the GraphQL SDL */
description?: Maybe<string>
//todo
/**

@@ -79,3 +77,3 @@ * Info about a field deprecation. Formatted as a string and provided with the deprecated directive on

*/
args?: ArgsRecord
args?: Maybe<ArgsRecord>
/**

@@ -82,0 +80,0 @@ * Data that will be added to the field-level [extensions field on the graphql-js type def

@@ -46,2 +46,4 @@ import { assertValidName, GraphQLEnumTypeConfig, GraphQLEnumValueConfig } from 'graphql'

extensions?: GraphQLEnumTypeConfig['extensions']
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
}

@@ -48,0 +50,0 @@

@@ -24,2 +24,4 @@ import { assertValidName, GraphQLInputObjectTypeConfig } from 'graphql'

extensions?: GraphQLInputObjectTypeConfig['extensions']
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
} & NexusGenPluginInputTypeConfig<TypeName>

@@ -26,0 +28,0 @@

@@ -16,3 +16,3 @@ import { assertValidName, GraphQLInterfaceTypeConfig } from 'graphql'

/** You are allowed to add non-required args when modifying a field */
args?: ArgsRecord
args?: Maybe<ArgsRecord>
/**

@@ -57,2 +57,4 @@ * Custom extensions, as supported in graphql-js

extensions?: GraphQLInterfaceTypeConfig<any, any>['extensions']
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>

@@ -59,0 +61,0 @@

@@ -192,2 +192,4 @@ import { assertValidName, GraphQLObjectType } from 'graphql'

definition(t: ObjectDefinitionBlock<TypeName>): void
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
} & AbstractTypes.MaybeTypeDefConfigFieldIsTypeOf<TypeName> &

@@ -194,0 +196,0 @@ NexusGenPluginTypeConfig<TypeName>

@@ -1,4 +0,5 @@

import { assertValidName, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'
import { assertValidName, GraphQLNamedType, GraphQLScalarTypeConfig } from 'graphql'
import type { AllNexusInputTypeDefs, AllNexusOutputTypeDefs } from '../core'
import { decorateType } from './decorateType'
import { Maybe, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'
import { GraphQLNamedOutputType, Maybe, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'

@@ -46,11 +47,11 @@ export interface ScalarBase

export function asNexusMethod<T extends GraphQLScalarType>(
scalar: T,
export function asNexusMethod<T extends GraphQLNamedType>(
namedType: T,
methodName: string,
sourceType?: SourceTypingDef
): T {
return decorateType(scalar, {
): T extends GraphQLNamedOutputType ? AllNexusOutputTypeDefs : AllNexusInputTypeDefs {
return decorateType(namedType, {
asNexusMethod: methodName,
sourceType,
})
}) as any
}

@@ -44,2 +44,4 @@ import { assertValidName, GraphQLUnionTypeConfig } from 'graphql'

extensions?: GraphQLUnionTypeConfig<any, any>['extensions']
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
} & AbstractTypes.MaybeTypeDefConfigFieldResolveType<TypeName>

@@ -46,0 +48,0 @@

@@ -204,2 +204,9 @@ import {

export function isNexusNamedOuputTypeDef(obj: any): obj is AllNexusNamedOutputTypeDefs {
return isNexusNamedTypeDef(obj) && !isNexusInputObjectTypeDef(obj)
}
export function isNexusNamedInputTypeDef(obj: any): obj is AllNexusNamedInputTypeDefs {
return isNexusNamedTypeDef(obj) && !isNexusObjectTypeDef(obj) && !isNexusInterfaceTypeDef(obj)
}
export function isNexusDynamicOutputProperty<T extends string>(obj: any): obj is DynamicOutputPropertyDef<T> {

@@ -206,0 +213,0 @@ return isNexusStruct(obj) && obj[NexusWrappedSymbol] === NexusTypes.DynamicOutputProperty

import { defaultFieldResolver, GraphQLNamedType } from 'graphql'
import type { DynamicFieldDefs, SchemaConfig } from './builder'
import type { SourceTypingDef, SourceTypings } from './definitions/_types'
import type { SourceTypings } from './definitions/_types'
import type { NexusOutputFieldConfig } from './definitions/definitionBlocks'

@@ -74,8 +74,1 @@ import type { NexusInputObjectTypeConfig } from './definitions/inputObjectType'

}
export type NexusScalarExtensions = {
nexus: {
asNexusMethod?: string
sourceType?: SourceTypingDef
}
}

@@ -197,3 +197,3 @@ import { GraphQLNamedType, GraphQLSchema, isOutputType } from 'graphql'

Object.keys(typeMap).forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return

@@ -200,0 +200,0 @@ }

@@ -181,3 +181,3 @@ import * as fs from 'fs'

.forEach((typeName) => {
if (typeName.indexOf('__') === 0) {
if (typeName.startsWith('__')) {
return

@@ -632,1 +632,8 @@ }

}
export function result<T>(val: T | (() => T)): T {
if (val instanceof Function) {
return val()
}
return val as T
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc