Comparing version 0.9.2 to 0.9.3
# Changelog | ||
### 0.9.3 | ||
- Minor internal changes | ||
### 0.9.2 | ||
@@ -4,0 +8,0 @@ |
@@ -289,3 +289,3 @@ import { | ||
config?: BuilderConfig, | ||
SchemaBuilderClass?: typeof SchemaBuilder | ||
schemaBuilder?: SchemaBuilder | ||
): BuildTypes<TypeMapDefs>; | ||
@@ -298,3 +298,3 @@ /** | ||
options: SchemaConfig, | ||
SchemaBuilderClass?: typeof SchemaBuilder | ||
schemaBuilder?: SchemaBuilder | ||
): { | ||
@@ -301,0 +301,0 @@ schema: GraphQLSchema; |
@@ -5,3 +5,2 @@ "use strict"; | ||
var graphql_1 = require("graphql"); | ||
var util_1 = require("util"); | ||
var definitionBlocks_1 = require("./definitions/definitionBlocks"); | ||
@@ -526,6 +525,5 @@ var interfaceType_1 = require("./definitions/interfaceType"); | ||
*/ | ||
function buildTypes(types, config, SchemaBuilderClass) { | ||
function buildTypes(types, config, schemaBuilder) { | ||
if (config === void 0) { config = { outputs: false }; } | ||
if (SchemaBuilderClass === void 0) { SchemaBuilderClass = SchemaBuilder; } | ||
var builder = new SchemaBuilderClass(config); | ||
var builder = schemaBuilder || new SchemaBuilder(config); | ||
addTypes(builder, types); | ||
@@ -551,3 +549,3 @@ return builder.getFinalTypeMap(); | ||
} | ||
else if (util_1.isObject(types)) { | ||
else if (utils_1.isObject(types)) { | ||
Object.keys(types).forEach(function (key) { return addTypes(builder, types[key]); }); | ||
@@ -560,5 +558,4 @@ } | ||
*/ | ||
function makeSchemaInternal(options, SchemaBuilderClass) { | ||
if (SchemaBuilderClass === void 0) { SchemaBuilderClass = SchemaBuilder; } | ||
var typeMap = buildTypes(options.types, options, SchemaBuilderClass).typeMap; | ||
function makeSchemaInternal(options, schemaBuilder) { | ||
var typeMap = buildTypes(options.types, options, schemaBuilder).typeMap; | ||
var Query = typeMap.Query, Mutation = typeMap.Mutation, Subscription = typeMap.Subscription; | ||
@@ -565,0 +562,0 @@ if (!Query) { |
@@ -6,3 +6,2 @@ import { | ||
} from "graphql"; | ||
export declare type MaybeThunk<T> = T | (() => T); | ||
export declare type BaseScalars = "String" | "Int" | "Float" | "ID" | "Boolean"; | ||
@@ -9,0 +8,0 @@ export declare enum NexusTypes { |
@@ -92,5 +92,10 @@ import { | ||
> = NeedsResolver<TypeName, FieldName> extends true | ||
? NexusOutputFieldConfig<TypeName, FieldName> & { | ||
resolve: FieldResolver<TypeName, FieldName>; | ||
} | ||
? NexusOutputFieldConfig<TypeName, FieldName> & | ||
( | ||
| { | ||
resolve: FieldResolver<TypeName, FieldName>; | ||
} | ||
| { | ||
nullable: true; | ||
}) | ||
: NexusOutputFieldConfig<TypeName, FieldName>; | ||
@@ -97,0 +102,0 @@ export interface OutputDefinitionBuilder { |
@@ -37,5 +37,3 @@ import { GraphQLNamedType } from "graphql"; | ||
| GraphQLNamedType; | ||
export declare type WrappedFnType = ( | ||
builder: SchemaBuilder | ||
) => AllTypeDefs | AllTypeDefs[] | Record<string, AllTypeDefs>; | ||
export declare type WrappedFnType = (builder: SchemaBuilder) => any; | ||
/** | ||
@@ -42,0 +40,0 @@ * Container object for a "wrapped function" |
@@ -10,5 +10,12 @@ import { | ||
GraphQLNamedType, | ||
GraphQLField, | ||
GraphQLOutputType, | ||
GraphQLWrappingType, | ||
} from "graphql"; | ||
import { GroupedTypes } from "./utils"; | ||
export declare function convertSDL(sdl: string, commonjs?: boolean): string; | ||
export declare function convertSDL( | ||
sdl: string, | ||
commonjs?: null | boolean, | ||
json?: JSON | ||
): string; | ||
/** | ||
@@ -18,9 +25,19 @@ * Convert an existing SDL schema into a Nexus GraphQL format | ||
export declare class SDLConverter { | ||
protected json: JSON; | ||
protected export: string; | ||
protected schema: GraphQLSchema; | ||
protected schema: GraphQLSchema | null; | ||
protected groupedTypes: GroupedTypes; | ||
constructor(commonjs: boolean | undefined, sdl: string); | ||
constructor(sdl: string, commonjs?: null | boolean, json?: JSON); | ||
print(): string; | ||
printObjectTypes(): string; | ||
printObjectType(type: GraphQLObjectType): string; | ||
printObjectFields(type: GraphQLObjectType | GraphQLInterfaceType): string; | ||
printField(source: "input" | "output", field: GraphQLField<any, any>): string; | ||
printFieldMethod( | ||
source: "input" | "output", | ||
field: GraphQLField<any, any>, | ||
type: Exclude<GraphQLOutputType, GraphQLWrappingType>, | ||
list: boolean[], | ||
isNonNull: boolean | ||
): string; | ||
printInterfaceTypes(): string; | ||
@@ -30,3 +47,3 @@ printInterfaceType(type: GraphQLInterfaceType): string; | ||
printEnumType(type: GraphQLEnumType): string; | ||
printInputObjectTypes(): string[] | ""; | ||
printInputObjectTypes(): string; | ||
printInputObjectType(type: GraphQLInputObjectType): string; | ||
@@ -37,4 +54,5 @@ printUnionTypes(): string; | ||
printScalarType(type: GraphQLScalarType): string; | ||
maybeAsNexusType(type: GraphQLScalarType): string | null; | ||
maybeDescription(type: GraphQLNamedType): string | null; | ||
printBlock(block: (string | null)[]): string; | ||
} |
@@ -5,5 +5,11 @@ "use strict"; | ||
var utils_1 = require("./utils"); | ||
function convertSDL(sdl, commonjs) { | ||
function convertSDL(sdl, commonjs, json) { | ||
if (commonjs === void 0) { commonjs = false; } | ||
return new SDLConverter(commonjs, sdl).print(); | ||
if (json === void 0) { json = JSON; } | ||
try { | ||
return new SDLConverter(sdl, commonjs, json).print(); | ||
} | ||
catch (e) { | ||
return "Error Parsing SDL into Schema: " + e.stack; | ||
} | ||
} | ||
@@ -15,5 +21,8 @@ exports.convertSDL = convertSDL; | ||
var SDLConverter = /** @class */ (function () { | ||
function SDLConverter(commonjs, sdl) { | ||
function SDLConverter(sdl, commonjs, json) { | ||
if (commonjs === void 0) { commonjs = false; } | ||
this.export = commonjs ? "exports." : "export const "; | ||
if (json === void 0) { json = JSON; } | ||
this.json = json; | ||
this.export = | ||
commonjs === null ? "const " : commonjs ? "exports." : "export const "; | ||
this.schema = graphql_1.buildSchema(sdl); | ||
@@ -30,3 +39,5 @@ this.groupedTypes = utils_1.groupTypes(this.schema); | ||
this.printScalarTypes(), | ||
].join("\n\n"); | ||
] | ||
.filter(function (f) { return f; }) | ||
.join("\n\n"); | ||
}; | ||
@@ -43,24 +54,84 @@ SDLConverter.prototype.printObjectTypes = function () { | ||
SDLConverter.prototype.printObjectType = function (type) { | ||
var _this = this; | ||
var implementing = type.getInterfaces().map(function (i) { return i.name; }); | ||
var implementsInterfaces = implementing.length > 0 | ||
? " t.implements(" + implementing | ||
.map(function (i) { return _this.json.stringify(i); }) | ||
.join(", ") + ")" | ||
: ""; | ||
return this.printBlock([ | ||
"" + this.export + type.name + " = objectType({", | ||
" name: \"" + type.name + "\"", | ||
" name: \"" + type.name + "\",", | ||
" definition(t) {", | ||
implementsInterfaces, | ||
this.printObjectFields(type), | ||
" }", | ||
"})", | ||
]); | ||
// if (type.getInterfaces().length > 0) { | ||
// const interfaceNames = type | ||
// .getInterfaces() | ||
// .map((i) => JSON.stringify(i.name)) | ||
// .join(", "); | ||
// str.push(` t.implements(${interfaceNames})`); | ||
// } | ||
// Object.keys(type.getFields()).forEach((fieldName) => { | ||
// if (isInterfaceField(type, fieldName)) { | ||
// return; | ||
// } | ||
// eachObj(type.getFields(), (field, key) => { | ||
// getFieldType(field); | ||
// }); | ||
// }); | ||
// return str.join("\n"); | ||
}; | ||
SDLConverter.prototype.printObjectFields = function (type) { | ||
var _this = this; | ||
return utils_1.objValues(type.getFields()) | ||
.map(function (field) { | ||
if (graphql_1.isObjectType(type) && utils_1.isInterfaceField(type, field.name)) { | ||
return; | ||
} | ||
return _this.printField("output", field); | ||
}) | ||
.filter(function (f) { return f; }) | ||
.join("\n"); | ||
}; | ||
SDLConverter.prototype.printField = function (source, field) { | ||
var fieldType = field.type; | ||
var isNonNull = false; | ||
var list = []; | ||
while (graphql_1.isWrappingType(fieldType)) { | ||
while (graphql_1.isListType(fieldType)) { | ||
fieldType = fieldType.ofType; | ||
if (graphql_1.isNonNullType(fieldType)) { | ||
fieldType = fieldType.ofType; | ||
list.unshift(true); | ||
} | ||
else { | ||
list.unshift(false); | ||
} | ||
} | ||
if (graphql_1.isNonNullType(fieldType)) { | ||
isNonNull = true; | ||
fieldType = fieldType.ofType; | ||
} | ||
} | ||
var prefix = list.length === 1 ? "t.list." : "t."; | ||
return " " + prefix + this.printFieldMethod(source, field, fieldType, list, isNonNull); | ||
}; | ||
SDLConverter.prototype.printFieldMethod = function (source, field, type, list, isNonNull) { | ||
var objectMeta = {}; | ||
if (field.description) { | ||
objectMeta.description = field.description; | ||
} | ||
if (field.deprecationReason) { | ||
objectMeta.deprecation = field.deprecationReason; | ||
} | ||
if (list.length > 1) { | ||
objectMeta.list = list; | ||
} | ||
if (!isNonNull && source === "output") { | ||
objectMeta.nullable = true; | ||
} | ||
else if (isNonNull && source === "input") { | ||
objectMeta.required = true; | ||
} | ||
var str = ""; | ||
if (isCommonScalar(type)) { | ||
str += type.name.toLowerCase() + "(\"" + field.name + "\""; | ||
} | ||
else { | ||
objectMeta.type = type; | ||
str += "field(\"" + field.name + "\""; | ||
} | ||
if (Object.keys(objectMeta).length > 0) { | ||
str += ", " + this.json.stringify(objectMeta); | ||
} | ||
return str + ")"; | ||
}; | ||
SDLConverter.prototype.printInterfaceTypes = function () { | ||
@@ -81,9 +152,6 @@ var _this = this; | ||
" definition(t) {", | ||
this.printObjectFields(type), | ||
" }", | ||
"});", | ||
]); | ||
// eachObj(type.getFields(), (field, key) => { | ||
// getFieldType(field); | ||
// }); | ||
// return str.join("\n"); | ||
}; | ||
@@ -100,2 +168,9 @@ SDLConverter.prototype.printEnumTypes = function () { | ||
SDLConverter.prototype.printEnumType = function (type) { | ||
var members = type.getValues().map(function (val) { | ||
var description = val.description, name = val.name, deprecationReason = val.deprecationReason, value = val.value; | ||
if (!description && !deprecationReason && name === value) { | ||
return val.name; | ||
} | ||
return { description: description, name: name, deprecated: deprecationReason, value: value }; | ||
}); | ||
return this.printBlock([ | ||
@@ -105,4 +180,3 @@ "" + this.export + type.name + " = enumType({", | ||
this.maybeDescription(type), | ||
" definition(t) {", | ||
" }", | ||
" members: " + this.json.stringify(members) + ",", | ||
"});", | ||
@@ -114,3 +188,5 @@ ]); | ||
if (this.groupedTypes.input.length) { | ||
return this.groupedTypes.input.map(function (t) { return _this.printInputObjectType(t); }); | ||
return this.groupedTypes.input | ||
.map(function (t) { return _this.printInputObjectType(t); }) | ||
.join("\n"); | ||
} | ||
@@ -152,2 +228,3 @@ return ""; | ||
return this.groupedTypes.scalar | ||
.filter(function (s) { return !graphql_1.isSpecifiedScalarType(s); }) | ||
.map(function (t) { return _this.printScalarType(t); }) | ||
@@ -161,9 +238,17 @@ .join("\n"); | ||
"" + this.export + type.name + " = scalarType({", | ||
" name: " + type.name + "\",", | ||
" name: \"" + type.name + "\",", | ||
this.maybeDescription(type), | ||
" definition(t) {", | ||
" }", | ||
this.maybeAsNexusType(type), | ||
" serialize() { /* Todo */ },", | ||
" parseValue() { /* Todo */ },", | ||
" parseLiteral() { /* Todo */ }", | ||
"});", | ||
]); | ||
}; | ||
SDLConverter.prototype.maybeAsNexusType = function (type) { | ||
if (isCommonScalar(type)) { | ||
return " asNexusMethod: \"" + type.name.toLowerCase() + "\","; | ||
} | ||
return null; | ||
}; | ||
SDLConverter.prototype.maybeDescription = function (type) { | ||
@@ -176,3 +261,3 @@ if (type.description) { | ||
SDLConverter.prototype.printBlock = function (block) { | ||
return block.filter(function (t) { return t !== null; }).join("\n"); | ||
return block.filter(function (t) { return t !== null && t !== ""; }).join("\n"); | ||
}; | ||
@@ -182,8 +267,10 @@ return SDLConverter; | ||
exports.SDLConverter = SDLConverter; | ||
var getFieldType = function (type) { | ||
// | ||
}; | ||
var getInputFieldType = function (type) { | ||
// | ||
}; | ||
function isCommonScalar(field) { | ||
if (graphql_1.isScalarType(field)) { | ||
return (graphql_1.isSpecifiedScalarType(field) || | ||
field.name === "UUID" || | ||
field.name === "Date"); | ||
} | ||
return false; | ||
} | ||
//# sourceMappingURL=sdlConverter.js.map |
@@ -45,3 +45,2 @@ import { | ||
printHeaders(): string; | ||
printFooters(): string; | ||
printGenTypeMap(): string; | ||
@@ -48,0 +47,0 @@ printCustomScalarMethods(): string | never[]; |
@@ -59,3 +59,2 @@ "use strict"; | ||
this.printGenTypeMap(), | ||
this.printFooters(), | ||
].join("\n\n"); | ||
@@ -71,5 +70,2 @@ }; | ||
}; | ||
Typegen.prototype.printFooters = function () { | ||
return "export type Gen = NexusGenTypes;"; | ||
}; | ||
Typegen.prototype.printGenTypeMap = function () { | ||
@@ -76,0 +72,0 @@ return ["export interface NexusGenTypes {"] |
@@ -24,2 +24,4 @@ import { GraphQLResolveInfo } from "graphql"; | ||
? ReadonlyArray<MaybePromiseDeep<Y>> | ||
: Date extends T[P] | ||
? MaybePromise<T[P]> | ||
: MaybePromiseDeep<T[P]> | ||
@@ -206,2 +208,6 @@ } | ||
: true | ||
: HasGen3<"rootTypes", TypeName, FieldName> extends true | ||
? null extends GetGen3<"rootTypes", TypeName, FieldName> | ||
? true | ||
: false | ||
: false; |
{ | ||
"name": "nexus", | ||
"version": "0.9.2", | ||
"version": "0.9.3", | ||
"main": "dist", | ||
@@ -5,0 +5,0 @@ "types": "dist", |
@@ -36,3 +36,2 @@ import { | ||
} from "graphql"; | ||
import { isObject } from "util"; | ||
import { NexusArgConfig, NexusArgDef } from "./definitions/args"; | ||
@@ -90,3 +89,3 @@ import { | ||
import { AbstractTypeResolver, GetGen } from "./typegenTypeHelpers"; | ||
import { firstDefined, objValues, suggestionList } from "./utils"; | ||
import { firstDefined, objValues, suggestionList, isObject } from "./utils"; | ||
@@ -863,5 +862,5 @@ export type Maybe<T> = T | null; | ||
config: BuilderConfig = { outputs: false }, | ||
SchemaBuilderClass: typeof SchemaBuilder = SchemaBuilder | ||
schemaBuilder?: SchemaBuilder | ||
): BuildTypes<TypeMapDefs> { | ||
const builder = new SchemaBuilderClass(config); | ||
const builder = schemaBuilder || new SchemaBuilder(config); | ||
addTypes(builder, types); | ||
@@ -898,3 +897,3 @@ return builder.getFinalTypeMap(); | ||
options: SchemaConfig, | ||
SchemaBuilderClass: typeof SchemaBuilder = SchemaBuilder | ||
schemaBuilder?: SchemaBuilder | ||
): { schema: GraphQLSchema } { | ||
@@ -904,3 +903,3 @@ const { typeMap: typeMap } = buildTypes( | ||
options, | ||
SchemaBuilderClass | ||
schemaBuilder | ||
); | ||
@@ -907,0 +906,0 @@ |
@@ -6,6 +6,3 @@ import { | ||
} from "graphql"; | ||
import { GenTypesShape } from "../core"; | ||
export type MaybeThunk<T> = T | (() => T); | ||
export type BaseScalars = "String" | "Int" | "Float" | "ID" | "Boolean"; | ||
@@ -12,0 +9,0 @@ |
@@ -1,2 +0,2 @@ | ||
import { GetGen, HasGen, GetGen2 } from "../typegenTypeHelpers"; | ||
import { GetGen, GetGen2 } from "../typegenTypeHelpers"; | ||
import { AllNexusInputTypeDefs } from "./wrapping"; | ||
@@ -3,0 +3,0 @@ import { NexusTypes, withNexusSymbol } from "./_types"; |
@@ -96,5 +96,8 @@ import { | ||
> = NeedsResolver<TypeName, FieldName> extends true | ||
? NexusOutputFieldConfig<TypeName, FieldName> & { | ||
resolve: FieldResolver<TypeName, FieldName>; | ||
} | ||
? NexusOutputFieldConfig<TypeName, FieldName> & | ||
( | ||
| { | ||
resolve: FieldResolver<TypeName, FieldName>; | ||
} | ||
| { nullable: true }) | ||
: NexusOutputFieldConfig<TypeName, FieldName>; | ||
@@ -101,0 +104,0 @@ |
@@ -41,5 +41,3 @@ import { GraphQLNamedType } from "graphql"; | ||
export type WrappedFnType = ( | ||
builder: SchemaBuilder | ||
) => AllTypeDefs | AllTypeDefs[] | Record<string, AllTypeDefs>; | ||
export type WrappedFnType = (builder: SchemaBuilder) => any; | ||
@@ -46,0 +44,0 @@ /** |
@@ -9,10 +9,26 @@ import { | ||
GraphQLUnionType, | ||
GraphQLField, | ||
GraphQLSchema, | ||
GraphQLNamedType, | ||
isSpecifiedScalarType, | ||
GraphQLField, | ||
isWrappingType, | ||
isNonNullType, | ||
isListType, | ||
GraphQLOutputType, | ||
GraphQLWrappingType, | ||
isScalarType, | ||
isObjectType, | ||
} from "graphql"; | ||
import { groupTypes, GroupedTypes } from "./utils"; | ||
import { groupTypes, GroupedTypes, isInterfaceField, objValues } from "./utils"; | ||
export function convertSDL(sdl: string, commonjs: boolean = false) { | ||
return new SDLConverter(commonjs, sdl).print(); | ||
export function convertSDL( | ||
sdl: string, | ||
commonjs: null | boolean = false, | ||
json = JSON | ||
) { | ||
try { | ||
return new SDLConverter(sdl, commonjs, json).print(); | ||
} catch (e) { | ||
return `Error Parsing SDL into Schema: ${e.stack}`; | ||
} | ||
} | ||
@@ -25,7 +41,12 @@ | ||
protected export: string; | ||
protected schema: GraphQLSchema; | ||
protected schema: GraphQLSchema | null; | ||
protected groupedTypes: GroupedTypes; | ||
constructor(commonjs: boolean = false, sdl: string) { | ||
this.export = commonjs ? "exports." : "export const "; | ||
constructor( | ||
sdl: string, | ||
commonjs: null | boolean = false, | ||
protected json: JSON = JSON | ||
) { | ||
this.export = | ||
commonjs === null ? "const " : commonjs ? "exports." : "export const "; | ||
this.schema = buildSchema(sdl); | ||
@@ -43,3 +64,5 @@ this.groupedTypes = groupTypes(this.schema); | ||
this.printScalarTypes(), | ||
].join("\n\n"); | ||
] | ||
.filter((f) => f) | ||
.join("\n\n"); | ||
} | ||
@@ -57,25 +80,96 @@ | ||
printObjectType(type: GraphQLObjectType): string { | ||
const implementing = type.getInterfaces().map((i) => i.name); | ||
const implementsInterfaces = | ||
implementing.length > 0 | ||
? ` t.implements(${implementing | ||
.map((i) => this.json.stringify(i)) | ||
.join(", ")})` | ||
: ""; | ||
return this.printBlock([ | ||
`${this.export}${type.name} = objectType({`, | ||
` name: "${type.name}"`, | ||
` name: "${type.name}",`, | ||
` definition(t) {`, | ||
implementsInterfaces, | ||
this.printObjectFields(type), | ||
` }`, | ||
`})`, | ||
]); | ||
// if (type.getInterfaces().length > 0) { | ||
// const interfaceNames = type | ||
// .getInterfaces() | ||
// .map((i) => JSON.stringify(i.name)) | ||
// .join(", "); | ||
// str.push(` t.implements(${interfaceNames})`); | ||
// } | ||
// Object.keys(type.getFields()).forEach((fieldName) => { | ||
// if (isInterfaceField(type, fieldName)) { | ||
// return; | ||
// } | ||
// eachObj(type.getFields(), (field, key) => { | ||
// getFieldType(field); | ||
// }); | ||
// }); | ||
// return str.join("\n"); | ||
} | ||
printObjectFields(type: GraphQLObjectType | GraphQLInterfaceType) { | ||
return objValues(type.getFields()) | ||
.map((field) => { | ||
if (isObjectType(type) && isInterfaceField(type, field.name)) { | ||
return; | ||
} | ||
return this.printField("output", field); | ||
}) | ||
.filter((f) => f) | ||
.join("\n"); | ||
} | ||
printField(source: "input" | "output", field: GraphQLField<any, any>) { | ||
let fieldType = field.type; | ||
let isNonNull = false; | ||
const list = []; | ||
while (isWrappingType(fieldType)) { | ||
while (isListType(fieldType)) { | ||
fieldType = fieldType.ofType; | ||
if (isNonNullType(fieldType)) { | ||
fieldType = fieldType.ofType; | ||
list.unshift(true); | ||
} else { | ||
list.unshift(false); | ||
} | ||
} | ||
if (isNonNullType(fieldType)) { | ||
isNonNull = true; | ||
fieldType = fieldType.ofType; | ||
} | ||
} | ||
const prefix = list.length === 1 ? `t.list.` : `t.`; | ||
return ` ${prefix}${this.printFieldMethod( | ||
source, | ||
field, | ||
fieldType, | ||
list, | ||
isNonNull | ||
)}`; | ||
} | ||
printFieldMethod( | ||
source: "input" | "output", | ||
field: GraphQLField<any, any>, | ||
type: Exclude<GraphQLOutputType, GraphQLWrappingType>, | ||
list: boolean[], | ||
isNonNull: boolean | ||
) { | ||
const objectMeta: Record<string, any> = {}; | ||
if (field.description) { | ||
objectMeta.description = field.description; | ||
} | ||
if (field.deprecationReason) { | ||
objectMeta.deprecation = field.deprecationReason; | ||
} | ||
if (list.length > 1) { | ||
objectMeta.list = list; | ||
} | ||
if (!isNonNull && source === "output") { | ||
objectMeta.nullable = true; | ||
} else if (isNonNull && source === "input") { | ||
objectMeta.required = true; | ||
} | ||
let str = ""; | ||
if (isCommonScalar(type)) { | ||
str += `${type.name.toLowerCase()}("${field.name}"`; | ||
} else { | ||
objectMeta.type = type; | ||
str += `field("${field.name}"`; | ||
} | ||
if (Object.keys(objectMeta).length > 0) { | ||
str += `, ${this.json.stringify(objectMeta)}`; | ||
} | ||
return `${str})`; | ||
} | ||
printInterfaceTypes() { | ||
@@ -96,9 +190,6 @@ if (this.groupedTypes.interface.length) { | ||
` definition(t) {`, | ||
this.printObjectFields(type), | ||
` }`, | ||
`});`, | ||
]); | ||
// eachObj(type.getFields(), (field, key) => { | ||
// getFieldType(field); | ||
// }); | ||
// return str.join("\n"); | ||
} | ||
@@ -116,2 +207,9 @@ | ||
printEnumType(type: GraphQLEnumType): string { | ||
const members = type.getValues().map((val) => { | ||
const { description, name, deprecationReason, value } = val; | ||
if (!description && !deprecationReason && name === value) { | ||
return val.name; | ||
} | ||
return { description, name, deprecated: deprecationReason, value }; | ||
}); | ||
return this.printBlock([ | ||
@@ -121,4 +219,3 @@ `${this.export}${type.name} = enumType({`, | ||
this.maybeDescription(type), | ||
` definition(t) {`, | ||
` }`, | ||
` members: ${this.json.stringify(members)},`, | ||
`});`, | ||
@@ -130,3 +227,5 @@ ]); | ||
if (this.groupedTypes.input.length) { | ||
return this.groupedTypes.input.map((t) => this.printInputObjectType(t)); | ||
return this.groupedTypes.input | ||
.map((t) => this.printInputObjectType(t)) | ||
.join("\n"); | ||
} | ||
@@ -170,2 +269,3 @@ return ""; | ||
return this.groupedTypes.scalar | ||
.filter((s) => !isSpecifiedScalarType(s)) | ||
.map((t) => this.printScalarType(t)) | ||
@@ -180,6 +280,8 @@ .join("\n"); | ||
`${this.export}${type.name} = scalarType({`, | ||
` name: ${type.name}",`, | ||
` name: "${type.name}",`, | ||
this.maybeDescription(type), | ||
` definition(t) {`, | ||
` }`, | ||
this.maybeAsNexusType(type), | ||
` serialize() { /* Todo */ },`, | ||
` parseValue() { /* Todo */ },`, | ||
` parseLiteral() { /* Todo */ }`, | ||
`});`, | ||
@@ -189,2 +291,9 @@ ]); | ||
maybeAsNexusType(type: GraphQLScalarType) { | ||
if (isCommonScalar(type)) { | ||
return ` asNexusMethod: "${type.name.toLowerCase()}",`; | ||
} | ||
return null; | ||
} | ||
maybeDescription(type: GraphQLNamedType) { | ||
@@ -198,12 +307,15 @@ if (type.description) { | ||
printBlock(block: (string | null)[]) { | ||
return block.filter((t) => t !== null).join("\n"); | ||
return block.filter((t) => t !== null && t !== "").join("\n"); | ||
} | ||
} | ||
const getFieldType = (type: GraphQLField<any, any>) => { | ||
// | ||
}; | ||
const getInputFieldType = (type: GraphQLField<any, any>) => { | ||
// | ||
}; | ||
function isCommonScalar(field: GraphQLOutputType): boolean { | ||
if (isScalarType(field)) { | ||
return ( | ||
isSpecifiedScalarType(field) || | ||
field.name === "UUID" || | ||
field.name === "Date" | ||
); | ||
} | ||
return false; | ||
} |
@@ -87,3 +87,2 @@ import { | ||
this.printGenTypeMap(), | ||
this.printFooters(), | ||
].join("\n\n"); | ||
@@ -101,6 +100,2 @@ } | ||
printFooters() { | ||
return `export type Gen = NexusGenTypes;`; | ||
} | ||
printGenTypeMap() { | ||
@@ -107,0 +102,0 @@ return [`export interface NexusGenTypes {`] |
@@ -30,2 +30,4 @@ import { GraphQLResolveInfo } from "graphql"; | ||
? ReadonlyArray<MaybePromiseDeep<Y>> | ||
: Date extends T[P] | ||
? MaybePromise<T[P]> | ||
: MaybePromiseDeep<T[P]> | ||
@@ -222,2 +224,6 @@ } | ||
: true | ||
: HasGen3<"rootTypes", TypeName, FieldName> extends true | ||
? null extends GetGen3<"rootTypes", TypeName, FieldName> | ||
? true | ||
: false | ||
: false; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
520342
7939