Skip to content

Commit

Permalink
refactor: Internal type cleanup (graphql-nexus#980)
Browse files Browse the repository at this point in the history
* refactor: Internal type cleanup
* chore: Remove prettier-plugin-jsdoc as its output is non-determinstic
  • Loading branch information
tgriesser authored Sep 3, 2021
1 parent e65b5a7 commit 7e744aa
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 214 deletions.
3 changes: 0 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
"release:pr": "dripip pr",
"release:preview": "dripip preview",
"release:stable": "dripip stable",
"pretest": "yarn patch-package",
"test": "yarn test:types && jest --testTimeout 10000",
"test:ci": "yarn test:types && jest --maxWorkers 2 --coverage --testTimeout 10000",
"test:debug": "node --inspect-brk $(yarn bin)/jest -i --watch",
Expand Down Expand Up @@ -92,9 +91,7 @@
"jest": "^26.6.3",
"jest-watch-typeahead": "^0.6.1",
"lint-staged": "^7.3.0",
"patch-package": "6.2.2",
"prettier": "^2.3.1",
"prettier-plugin-jsdoc": "^0.3.23",
"sort-package-json": "^1.22.1",
"ts-jest": "^26.4.4",
"ts-morph": "^8.2.0",
Expand Down
7 changes: 4 additions & 3 deletions src/definitions/args.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { GraphQLScalarTypeConfig } from 'graphql'
import type { AllNexusInputTypeDefs } from '../core'
import type { AllInputTypes, GetGen2 } from '../typegenTypeHelpers'
import type { AllNexusArgsDefs, AllNexusInputTypeDefs } from './wrapping'
import { NexusTypes, withNexusSymbol } from './_types'
import type { AllNexusArgsDefs } from './wrapping'
import { Maybe, NexusTypes, withNexusSymbol } from './_types'

export type ArgsRecord = Record<string, AllNexusArgsDefs>

Expand Down Expand Up @@ -39,7 +40,7 @@ export type CommonArgConfig = {
* // ): [Int]
* // }
*/
description?: string
description?: Maybe<string>

/**
* Data that will be added to the arg-level [extensions field on the graphql-js type def
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/definitionBlocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ import type {
import type { ArgsRecord } from './args'
import type { NexusMetaType } from './nexusMeta'
import type { AllNexusInputTypeDefs, AllNexusOutputTypeDefs, NexusWrapKind } from './wrapping'
import type { BaseScalars } from './_types'
import type { BaseScalars, Maybe } from './_types'

export interface CommonFieldConfig {
//todo
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
//todo
/**
* Info about a field deprecation. Formatted as a string and provided with the deprecated directive on
* field/enum types and as a comment on input fields.
*/
deprecation?: string // | DeprecationInfo;
deprecation?: Maybe<string> // | DeprecationInfo;
}

export type CommonOutputFieldConfig<TypeName extends string, FieldName extends string> = CommonFieldConfig & {
Expand Down
8 changes: 4 additions & 4 deletions src/definitions/enumType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertValidName, GraphQLEnumTypeConfig, GraphQLEnumValueConfig } from 'graphql'
import { arg, NexusArgDef, NexusAsArgConfig } from './args'
import { NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'
import { Maybe, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'

type TypeScriptEnumLike = {
[key: number]: string
Expand All @@ -12,12 +12,12 @@ export interface EnumMemberInfo {
/** The internal representation of the enum */
value?: string | number | object | boolean
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/**
* Info about a field deprecation. Formatted as a string and provided with the deprecated directive on
* field/enum types and as a comment on input fields.
*/
deprecation?: string // | DeprecationInfo;
deprecation?: Maybe<string> // | DeprecationInfo;
/**
* Custom extensions, as supported in graphql-js
*
Expand All @@ -29,7 +29,7 @@ export interface EnumMemberInfo {
export interface NexusEnumTypeConfig<TypeName extends string> {
name: TypeName
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/** Source type information for this type */
sourceType?: SourceTypingDef
/** All members of the enum, either as an array of strings/definition objects, as an object, or as a TypeScript enum */
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/inputObjectType.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { assertValidName, GraphQLInputObjectTypeConfig } from 'graphql'
import { arg, NexusArgDef, NexusAsArgConfig } from './args'
import type { InputDefinitionBlock } from './definitionBlocks'
import { NexusTypes, NonNullConfig, withNexusSymbol } from './_types'
import { Maybe, NexusTypes, NonNullConfig, withNexusSymbol } from './_types'

export type NexusInputObjectTypeConfig<TypeName extends string> = {
/** Name of the input object type */
name: TypeName
/** Definition block for the input type */
definition(t: InputDefinitionBlock<TypeName>): void
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/**
* Configures the nullability for the type, check the documentation's "Getting Started" section to learn
* more about GraphQL Nexus's assumptions and configuration on nullability.
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/interfaceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { assertValidName, GraphQLInterfaceTypeConfig } from 'graphql'
import type { FieldResolver, GetGen, InterfaceFieldsFor, ModificationType } from '../typegenTypeHelpers'
import type { ArgsRecord } from './args'
import { OutputDefinitionBlock, OutputDefinitionBuilder } from './definitionBlocks'
import { AbstractTypes, NexusTypes, NonNullConfig, SourceTypingDef, withNexusSymbol } from './_types'
import { AbstractTypes, Maybe, NexusTypes, NonNullConfig, SourceTypingDef, withNexusSymbol } from './_types'

export type Implemented = GetGen<'interfaceNames'> | NexusInterfaceTypeDef<any>

export interface FieldModification<TypeName extends string, FieldName extends string> {
type?: ModificationType<TypeName, FieldName>
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/** The resolve method we should be resolving the field with */
resolve?: FieldResolver<TypeName, FieldName>
/** You are allowed to add non-required args when modifying a field */
Expand Down Expand Up @@ -44,7 +44,7 @@ export type NexusInterfaceTypeConfig<TypeName extends string> = {
*/
nonNullDefaults?: NonNullConfig
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/** Source type information for this type */
sourceType?: SourceTypingDef
/**
Expand Down
6 changes: 1 addition & 5 deletions src/definitions/list.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { isType } from 'graphql'
import { isNexusMeta } from './nexusMeta'
import { AllNamedTypeDefs, isNexusStruct, NexusListableTypes } from './wrapping'
import { isNexusStruct, NexusListableTypes } from './wrapping'
import { NexusTypes, withNexusSymbol } from './_types'
/** List() */
export type NexusListDefConfig<TypeName extends AllNamedTypeDefs> = {
type: TypeName
}

export class NexusListDef<TypeName extends NexusListableTypes> {
// @ts-ignore
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/mutationField.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FieldOutConfig, OutputDefinitionBlock } from '../core'
import type { FieldOutConfig, OutputDefinitionBlock } from './definitionBlocks'
import { extendType, NexusExtendTypeDef } from './extendType'

export type MutationFieldConfig<FieldName extends string> =
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/objectType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { assertValidName, GraphQLObjectType } from 'graphql'
import type { InterfaceFieldsFor } from '../typegenTypeHelpers'
import { OutputDefinitionBlock, OutputDefinitionBuilder } from './definitionBlocks'
import type { FieldModification, FieldModificationDef, Implemented } from './interfaceType'
import { AbstractTypes, NexusTypes, NonNullConfig, SourceTypingDef, withNexusSymbol } from './_types'
import { AbstractTypes, Maybe, NexusTypes, NonNullConfig, SourceTypingDef, withNexusSymbol } from './_types'

export interface ObjectDefinitionBuilder extends OutputDefinitionBuilder {
addInterfaces(toAdd: Implemented[]): void
Expand Down Expand Up @@ -102,7 +102,7 @@ export type NexusObjectTypeConfig<TypeName extends string> = {
* // # ...
* // }
*/
description?: string
description?: Maybe<string>
/**
* [Source Types Guide](https://nxs.li/guides/backing-types)
*
Expand Down
2 changes: 1 addition & 1 deletion src/definitions/queryField.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { FieldOutConfig, OutputDefinitionBlock } from '../core'
import type { FieldOutConfig, OutputDefinitionBlock } from './definitionBlocks'
import { extendType, NexusExtendTypeDef } from './extendType'

export type QueryFieldConfig<FieldName extends string> =
Expand Down
4 changes: 2 additions & 2 deletions src/definitions/scalarType.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assertValidName, GraphQLScalarType, GraphQLScalarTypeConfig } from 'graphql'
import { decorateType } from './decorateType'
import { NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'
import { Maybe, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'

export interface ScalarBase
extends Pick<
Expand All @@ -10,7 +10,7 @@ export interface ScalarBase

export interface ScalarConfig {
/** Any deprecation info for this scalar type */
deprecation?: string // | DeprecationInfo;
deprecation?: Maybe<string> // | DeprecationInfo;
/** Adds this type as a method on the Object/Interface definition blocks */
asNexusMethod?: string
/** Source type information for this type */
Expand Down
6 changes: 3 additions & 3 deletions src/definitions/unionType.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assertValidName, GraphQLUnionTypeConfig } from 'graphql'
import type { GetGen } from '../typegenTypeHelpers'
import type { NexusObjectTypeDef } from './objectType'
import { AbstractTypes, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'
import { AbstractTypes, Maybe, NexusTypes, SourceTypingDef, withNexusSymbol } from './_types'

export interface UnionDefinitionBuilder {
typeName: string
Expand All @@ -27,12 +27,12 @@ export type NexusUnionTypeConfig<TypeName extends string> = {
/** Builds the definition for the union */
definition(t: UnionDefinitionBlock): void
/** The description to annotate the GraphQL SDL */
description?: string
description?: Maybe<string>
/**
* Info about a field deprecation. Formatted as a string and provided with the deprecated directive on
* field/enum types and as a comment on input fields.
*/
deprecation?: string // | DeprecationInfo;
deprecation?: Maybe<string> // | DeprecationInfo;
/** Source type information for this type */
sourceType?: SourceTypingDef
/**
Expand Down
47 changes: 43 additions & 4 deletions src/definitions/wrapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,38 +28,71 @@ import { isNexusMetaType, NexusMetaType, resolveNexusMetaType } from './nexusMet
import type { NexusUnionTypeDef } from './unionType'
import { NexusTypes, NexusWrappedSymbol } from './_types'

/**
* input(named): Nexus only
*/
export type AllNexusNamedInputTypeDefs<T extends string = any> =
| NexusInputObjectTypeDef<T>
| NexusEnumTypeDef<T>
| NexusScalarTypeDef<T>

/**
* input(named): Nexus + GraphQLInput
*/
export type AllNamedInputTypeDefs<T extends string = any> =
| AllNexusNamedInputTypeDefs<T>
| Exclude<GraphQLInputType, GraphQLList<any> | GraphQLNonNull<any>>

/**
* input(all): Nexus + GraphQL
*/
export type AllNexusInputTypeDefs<T extends string = any> =
| AllNexusNamedInputTypeDefs<T>
| AllNamedInputTypeDefs<T>
| NexusListDef<any>
| NexusNonNullDef<any>
| NexusNullDef<any>
| GraphQLList<any>
| GraphQLNonNull<any>

/**
* output(named): Nexus only
*/
export type AllNexusNamedOutputTypeDefs =
| NexusObjectTypeDef<any>
| NexusInterfaceTypeDef<any>
| NexusUnionTypeDef<any>
| NexusEnumTypeDef<any>
| NexusScalarTypeDef<any>

/**
* output(all): Nexus only
*/
export type AllNexusOutputTypeDefs =
| AllNexusNamedOutputTypeDefs
| NexusListDef<any>
| NexusNonNullDef<any>
| NexusNullDef<any>

/**
* input + output(named): Nexus only
*/
export type AllNexusNamedTypeDefs = AllNexusNamedInputTypeDefs | AllNexusNamedOutputTypeDefs

/**
* input + output(all): Nexus only
*/
export type AllNexusTypeDefs = AllNexusOutputTypeDefs | AllNexusInputTypeDefs

/**
* input + output(all): Nexus only + Name
*/
export type AllNamedTypeDefs = AllNexusNamedTypeDefs | GraphQLNamedType

/**
* All inputs to list(...)
*/
export type NexusListableTypes =
| GetGen<'allNamedTypes', string>
| AllNamedTypeDefs
| NexusArgDef<any>
| NexusListDef<NexusListableTypes>
Expand All @@ -68,24 +101,30 @@ export type NexusListableTypes =
| GraphQLType
| NexusMetaType

/**
* All inputs to nonNull(...)
*/
export type NexusNonNullableTypes =
| GetGen<'allNamedTypes', string>
| AllNamedTypeDefs
| NexusListDef<NexusListableTypes>
| NexusArgDef<any>
| NexusMetaType

/**
* All inputs to nullable(...)
*/
export type NexusNullableTypes =
| GetGen<'allNamedTypes', string>
| AllNamedTypeDefs
| NexusListDef<NexusListableTypes>
| NexusArgDef<any>
| NexusMetaType

export type AllNamedTypeDefs = GetGen<'allNamedTypes', string> | AllNexusNamedTypeDefs

export type AllNexusNamedArgsDefs<T extends AllInputTypes = AllInputTypes> =
| T
| NexusArgDef<T>
| AllNexusNamedInputTypeDefs<T>
| AllNamedInputTypeDefs<T>
| GraphQLInputType

export type AllNexusArgsDefs =
Expand Down
2 changes: 1 addition & 1 deletion src/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface PluginConfig {
/** A name for the plugin, useful for errors, etc. */
name: string
/** A description for the plugin */
description?: string
description?: Maybe<string>
/** Any type definitions we want to add to output field definitions */
fieldDefTypes?: StringLike | StringLike[]
/** Any type definitions we want to add to input field definitions */
Expand Down
7 changes: 4 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ import {
AllNexusTypeDefs,
isNexusWrappingType,
isNexusArgDef,
AllNexusNamedInputTypeDefs,
AllNamedInputTypeDefs,
} from './definitions/wrapping'
import {
Maybe,
MissingType,
NexusFeatures,
NexusGraphQLSchema,
Expand Down Expand Up @@ -266,7 +267,7 @@ export interface PrintedGenTypingConfig {
name: string
optional: boolean
type: string
description?: string
description?: Maybe<string>
imports?: PrintedGenTypingImport[]
}

Expand Down Expand Up @@ -517,7 +518,7 @@ export function resolveImportPath(rootType: TypingImport, typeName: string, outp
}

/** Given the right hand side of an arg definition, returns the underlying "named type" for us to add to the builder */
export function getArgNamedType(argDef: AllNexusArgsDefs | string): AllNexusNamedInputTypeDefs | string {
export function getArgNamedType(argDef: AllNexusArgsDefs | string): AllNamedInputTypeDefs | string {
let finalValue = argDef
if (typeof finalValue === 'string') {
return finalValue
Expand Down
Loading

0 comments on commit 7e744aa

Please sign in to comment.