nexus-prisma
Advanced tools
Comparing version 0.0.11 to 0.0.12
@@ -23,7 +23,8 @@ #!/usr/bin/env node | ||
var inputTypes = types.types.filter(function (t) { return t.type.isInput; }); | ||
return "// GENERATED TYPES FOR PRISMA PLUGIN. /!\\ DO NOT EDIT MANUALLY\n\nimport {\n ArgDefinition,\n ContextValue,\n RootValue,\n} from 'nexus/dist/types'\nimport { GraphQLResolveInfo } from 'graphql'\n\nimport * as prisma from './prisma-client'\n\n" + objectTypes.map(renderType).join(os_1.EOL) + "\n\n" + inputTypes.map(renderInputType).join(os_1.EOL) + "\n\nexport interface PluginTypes {\n fields: {\n" + objectTypes | ||
var enumTypes = types.enums; | ||
return "// GENERATED TYPES FOR PRISMA PLUGIN. /!\\ DO NOT EDIT MANUALLY\n\nimport {\n ArgDefinition,\n ContextValue,\n RootValue,\n} from 'nexus/dist/types'\nimport { GraphQLResolveInfo } from 'graphql'\n\nimport * as prisma from './prisma-client'\n\n" + objectTypes.map(renderType).join(os_1.EOL) + "\n\n" + inputTypes.map(renderInputType).join(os_1.EOL) + "\n\n" + renderEnumTypes(enumTypes) + "\n\nexport interface PluginTypes {\n fields: {\n" + objectTypes | ||
.map(function (type) { return " " + type.name + ": " + getExposableObjectsTypeName(type); }) | ||
.join(os_1.EOL) + "\n }\n fieldsDetails: {\n" + objectTypes | ||
.map(function (type) { return " " + type.name + ": " + getTypeObjectName(type); }) | ||
.join(os_1.EOL) + "\n }\n}\n\ndeclare global {\n interface GraphQLNexusGen extends PluginTypes {}\n}\n "; | ||
.join(os_1.EOL) + "\n }\n enumTypesNames: " + getEnumTypesName() + "\n}\n\ndeclare global {\n interface GraphQLNexusGen extends PluginTypes {}\n}\n "; | ||
} | ||
@@ -102,2 +103,5 @@ exports.render = render; | ||
} | ||
function renderEnumTypes(enums) { | ||
return "export type " + getEnumTypesName() + " =\n" + enums.map(function (e) { return " | '" + e.name + "'"; }).join(os_1.EOL) + "\n "; | ||
} | ||
function getExposableFieldsTypeName(type) { | ||
@@ -121,2 +125,5 @@ return type.name + "Fields"; | ||
} | ||
function getEnumTypesName() { | ||
return 'enumTypesNames'; | ||
} | ||
//# sourceMappingURL=codegen.js.map |
import { PrismaSchemaConfig } from './types'; | ||
import { SchemaBuilder, Metadata } from 'nexus/dist/core'; | ||
export { prismaObjectType } from './prisma'; | ||
export { prismaObjectType, prismaEnumType } from './prisma'; | ||
export declare class PrismaSchemaBuilder extends SchemaBuilder { | ||
@@ -5,0 +5,0 @@ protected metadata: Metadata; |
@@ -20,2 +20,3 @@ "use strict"; | ||
exports.prismaObjectType = prisma_1.prismaObjectType; | ||
exports.prismaEnumType = prisma_1.prismaEnumType; | ||
var PrismaSchemaBuilder = /** @class */ (function (_super) { | ||
@@ -22,0 +23,0 @@ __extends(PrismaSchemaBuilder, _super); |
import { ObjectTypeDef, Types, WrappedType } from 'nexus/dist/core'; | ||
import { GraphQLEnumObject, GraphQLTypeObject } from './source-helper'; | ||
import { FilterInputField, InputField, PickInputField, PrismaObject, PrismaOutputOptsMap, PrismaTypeNames, PrismaSchemaConfig } from './types'; | ||
import { PrismaSchemaBuilder } from '.'; | ||
import { FilterInputField, InputField, PickInputField, PrismaObject, PrismaOutputOptsMap, PrismaTypeNames, PrismaSchemaConfig, PrismaEnumTypeNames } from './types'; | ||
interface Dictionary<T> { | ||
@@ -28,3 +27,4 @@ [key: string]: T; | ||
objectTypeName?: string; | ||
}, fn?: (t: PrismaObjectType<GenTypes, TypeName>) => void): (schema: PrismaSchemaBuilder) => WrappedType[]; | ||
}, fn?: (t: PrismaObjectType<GenTypes, TypeName>) => void): WrappedType; | ||
export declare function prismaEnumType<GenTypes = GraphQLNexusGen>(typeName: PrismaEnumTypeNames<GenTypes>): WrappedType; | ||
export {}; |
@@ -108,2 +108,5 @@ "use strict"; | ||
} | ||
else if (field.type.isEnum) { | ||
typesToExport.push(exportEnumType(typesMap.enums[field.type.name])); | ||
} | ||
else { | ||
@@ -257,10 +260,13 @@ typesToExport.push.apply(typesToExport, exportInputObjectType(typesMap.types[field.type.name], typesMap, seen)); | ||
} | ||
function createRelayConnectionType(typeName, schema) { | ||
function createRelayConnectionType(typeName) { | ||
var normalTypeName = typeName.split('Connection')[0]; | ||
var edgeTypeName = normalTypeName + "Edge"; | ||
return prismaObjectType(typeName, function (t) { | ||
t.prismaFields(['edges', 'pageInfo']); | ||
})(schema).concat(prismaObjectType(edgeTypeName)(schema)); | ||
return [ | ||
prismaObjectType(typeName, function (t) { | ||
t.prismaFields(['edges', 'pageInfo']); | ||
}), | ||
prismaObjectType(edgeTypeName), | ||
]; | ||
} | ||
function getRelayConnectionTypesToExport(typeConfig, schema) { | ||
function getRelayConnectionTypesToExport(typeConfig) { | ||
var exportedTypesMap = getExportedTypesMap(); | ||
@@ -274,9 +280,7 @@ var connectionTypes = _(typeConfig.fields) | ||
}) | ||
.flatMap(function (field) { | ||
return createRelayConnectionType(field.config.type, schema); | ||
}) | ||
.flatMap(function (field) { return createRelayConnectionType(field.config.type); }) | ||
.value(); | ||
if (connectionTypes.length > 0 && | ||
exportedTypesMap['PageInfo'] === undefined) { | ||
connectionTypes.push.apply(connectionTypes, prismaObjectType('PageInfo')(schema)); | ||
connectionTypes.push(prismaObjectType('PageInfo')); | ||
} | ||
@@ -286,3 +290,3 @@ return connectionTypes; | ||
function prismaObjectType(typeName, fn) { | ||
return function (schema) { | ||
return new core_1.WrappedType(function (schema) { | ||
// TODO refactor + make use of `objectTypeName` | ||
@@ -301,10 +305,25 @@ var realTypeName = typeof typeName === 'string' ? typeName : typeName.prismaTypeName; | ||
var inputTypesToExport = getInputTypesToExport(typeConfig, typesMap); | ||
var connectionTypesToExport = getRelayConnectionTypesToExport(typeConfig, schema); | ||
addExportedTypesToGlobalCache(inputTypesToExport); | ||
var connectionTypesToExport = getRelayConnectionTypesToExport(typeConfig); | ||
addExportedTypesToGlobalCache(inputTypesToExport.concat(connectionTypesToExport)); | ||
return [ | ||
new core_1.WrappedType(objectType) | ||
].concat(inputTypesToExport, connectionTypesToExport); | ||
}; | ||
}); | ||
} | ||
exports.prismaObjectType = prismaObjectType; | ||
function prismaEnumType(typeName) { | ||
return new core_1.WrappedType(function (schema) { | ||
var typesMap = getTypesMap(schema.getConfig().prisma.schemaPath); | ||
var graphqlEnumType = typesMap.enums[typeName]; | ||
if (graphqlEnumType === undefined) { | ||
throw new Error("Unknown enum '" + typeName + "' in Prisma API"); | ||
} | ||
var exportedTypesMap = getExportedTypesMap(); | ||
if (exportedTypesMap[typeName]) { | ||
return; | ||
} | ||
return nexus_1.enumType(typeName, graphqlEnumType.values); | ||
}); | ||
} | ||
exports.prismaEnumType = prismaEnumType; | ||
//# sourceMappingURL=prisma.js.map |
@@ -5,2 +5,3 @@ import { ArgDefinition, SchemaConfig } from 'nexus/dist/types'; | ||
fieldsDetails: Record<string, any>; | ||
enumTypesNames: string; | ||
} | ||
@@ -28,2 +29,3 @@ export interface ObjectField { | ||
export declare type PrismaTypeNames<GenTypes = GraphQLNexusGen> = GenTypes extends GenTypesShape ? Extract<keyof GenTypes['fields'], string> : string; | ||
export declare type PrismaEnumTypeNames<GenTypes = GraphQLNexusGen> = GenTypes extends GenTypesShape ? GenTypes['enumTypesNames'] : string; | ||
export interface PickInputField<GenTypes, TypeName extends string> { | ||
@@ -30,0 +32,0 @@ pick: InputField<GenTypes, TypeName>[]; |
{ | ||
"name": "nexus-prisma", | ||
"version": "0.0.11", | ||
"version": "0.0.12", | ||
"main": "dist/index.js", | ||
@@ -32,3 +32,3 @@ "typings": "dist/index.d.ts", | ||
"lodash": "^4.17.11", | ||
"nexus": "^0.5.1" | ||
"nexus": "^0.6.0" | ||
}, | ||
@@ -43,3 +43,3 @@ "peerDependencies": { | ||
"prettier": "1.15.3", | ||
"prisma": "1.22.2", | ||
"prisma": "1.23.1", | ||
"ts-jest": "23.10.5", | ||
@@ -46,0 +46,0 @@ "typescript": "3.2.2" |
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
72741
1032
+ Addednexus@0.6.2(transitive)
- Removednexus@0.5.1(transitive)
Updatednexus@^0.6.0