nexus-prisma
Advanced tools
Comparing version 0.0.10 to 0.0.11
import { PrismaSchemaConfig } from './types'; | ||
import { SchemaBuilder, Metadata } from 'nexus/dist/core'; | ||
export { prismaObjectType } from './prisma'; | ||
export declare class PrismaSchemaBuilder extends SchemaBuilder { | ||
protected metadata: Metadata; | ||
protected config: PrismaSchemaConfig; | ||
constructor(metadata: Metadata, config: PrismaSchemaConfig); | ||
getConfig(): PrismaSchemaConfig; | ||
} | ||
export declare function buildPrismaSchema(options: PrismaSchemaConfig): import("graphql").GraphQLSchema; |
@@ -23,3 +23,6 @@ "use strict"; | ||
function PrismaSchemaBuilder(metadata, config) { | ||
return _super.call(this, metadata, config) || this; | ||
var _this = _super.call(this, metadata, config) || this; | ||
_this.metadata = metadata; | ||
_this.config = config; | ||
return _this; | ||
} | ||
@@ -31,2 +34,3 @@ PrismaSchemaBuilder.prototype.getConfig = function () { | ||
}(core_1.SchemaBuilder)); | ||
exports.PrismaSchemaBuilder = PrismaSchemaBuilder; | ||
function buildPrismaSchema(options) { | ||
@@ -33,0 +37,0 @@ var _a = nexus_1.makeSchemaWithMetadata(options, PrismaSchemaBuilder), schema = _a.schema, metadata = _a.metadata; |
import { ObjectTypeDef, Types, WrappedType } from 'nexus/dist/core'; | ||
import { GraphQLEnumObject, GraphQLTypeObject } from './source-helper'; | ||
import { FilterInputField, InputField, PickInputField, PrismaObject, PrismaOutputOptsMap, PrismaTypeNames } from './types'; | ||
import { FilterInputField, InputField, PickInputField, PrismaObject, PrismaOutputOptsMap, PrismaTypeNames, PrismaSchemaConfig } from './types'; | ||
import { PrismaSchemaBuilder } from '.'; | ||
interface Dictionary<T> { | ||
@@ -11,11 +12,8 @@ [key: string]: T; | ||
} | ||
interface PrismaConfig { | ||
schemaPath: string; | ||
contextClientName: string; | ||
} | ||
declare class PrismaObjectType<GenTypes, TypeName extends string> extends ObjectTypeDef<GenTypes, TypeName> { | ||
protected typeName: string; | ||
protected config: PrismaSchemaConfig; | ||
protected typesMap: TypesMap; | ||
protected config: PrismaConfig; | ||
prismaType: PrismaObject<GenTypes, TypeName>; | ||
constructor(typeName: string); | ||
constructor(typeName: string, config: PrismaSchemaConfig); | ||
prismaFields(inputFields?: InputField<GenTypes, TypeName>[]): void; | ||
@@ -31,3 +29,3 @@ prismaFields(pickFields: PickInputField<GenTypes, TypeName>): void; | ||
objectTypeName?: string; | ||
}, fn?: (t: PrismaObjectType<GenTypes, TypeName>) => void): WrappedType[]; | ||
}, fn?: (t: PrismaObjectType<GenTypes, TypeName>) => void): (schema: PrismaSchemaBuilder) => WrappedType[]; | ||
export {}; |
@@ -31,3 +31,2 @@ "use strict"; | ||
var _ = require("lodash"); | ||
var path = require("path"); | ||
var source_helper_1 = require("./source-helper"); | ||
@@ -168,14 +167,10 @@ var throw_1 = require("./throw"); | ||
__extends(PrismaObjectType, _super); | ||
function PrismaObjectType(typeName) { | ||
function PrismaObjectType(typeName, config) { | ||
var _this = _super.call(this, typeName) || this; | ||
// TODO: Fix this once we have access to the config | ||
var schemaPath = path.join(process.cwd(), './src/generated/prisma.graphql'); | ||
if (!fs_1.existsSync(schemaPath)) { | ||
throw new Error('prisma.graphql should be located in ./src/generated/prisma.graphql'); | ||
_this.typeName = typeName; | ||
_this.config = config; | ||
if (!fs_1.existsSync(config.prisma.schemaPath)) { | ||
throw new Error('Prisma GraphQL API not found'); | ||
} | ||
_this.config = { | ||
schemaPath: schemaPath, | ||
contextClientName: 'prisma' | ||
}; | ||
_this.typesMap = getTypesMap(_this.config.schemaPath); | ||
_this.typesMap = getTypesMap(config.prisma.schemaPath); | ||
_this.prismaType = _this.generatePrismaTypes(); | ||
@@ -215,3 +210,3 @@ return _this; | ||
}, {}), | ||
resolve: generateDefaultResolver(typeName, field, _this.config.contextClientName) | ||
resolve: generateDefaultResolver(typeName, field, _this.config.prisma.contextClientName) | ||
}; | ||
@@ -264,3 +259,3 @@ return acc; | ||
} | ||
function createRelayConnectionType(typeName) { | ||
function createRelayConnectionType(typeName, schema) { | ||
var normalTypeName = typeName.split('Connection')[0]; | ||
@@ -270,5 +265,5 @@ var edgeTypeName = normalTypeName + "Edge"; | ||
t.prismaFields(['edges', 'pageInfo']); | ||
}).concat(prismaObjectType(edgeTypeName)); | ||
})(schema).concat(prismaObjectType(edgeTypeName)(schema)); | ||
} | ||
function getRelayConnectionTypesToExport(typeConfig) { | ||
function getRelayConnectionTypesToExport(typeConfig, schema) { | ||
var exportedTypesMap = getExportedTypesMap(); | ||
@@ -283,3 +278,3 @@ var connectionTypes = _(typeConfig.fields) | ||
.flatMap(function (field) { | ||
return createRelayConnectionType(field.config.type); | ||
return createRelayConnectionType(field.config.type, schema); | ||
}) | ||
@@ -289,3 +284,3 @@ .value(); | ||
exportedTypesMap['PageInfo'] === undefined) { | ||
connectionTypes.push.apply(connectionTypes, prismaObjectType('PageInfo')); | ||
connectionTypes.push.apply(connectionTypes, prismaObjectType('PageInfo')(schema)); | ||
} | ||
@@ -295,22 +290,24 @@ return connectionTypes; | ||
function prismaObjectType(typeName, fn) { | ||
// TODO refactor + make use of `objectTypeName` | ||
var realTypeName = typeof typeName === 'string' ? typeName : typeName.prismaTypeName; | ||
var objectType = new PrismaObjectType(realTypeName); | ||
// mutate objectType | ||
if (fn === undefined) { | ||
objectType.prismaFields(); | ||
} | ||
else { | ||
fn(objectType); | ||
} | ||
var typesMap = objectType.getTypesMap(); | ||
var typeConfig = objectType.getTypeConfig(); | ||
var inputTypesToExport = getInputTypesToExport(typeConfig, typesMap); | ||
var connectionTypesToExport = getRelayConnectionTypesToExport(typeConfig); | ||
addExportedTypesToGlobalCache(inputTypesToExport); | ||
return [ | ||
new core_1.WrappedType(objectType) | ||
].concat(inputTypesToExport, connectionTypesToExport); | ||
return function (schema) { | ||
// TODO refactor + make use of `objectTypeName` | ||
var realTypeName = typeof typeName === 'string' ? typeName : typeName.prismaTypeName; | ||
var objectType = new PrismaObjectType(realTypeName, schema.getConfig()); | ||
// mutate objectType | ||
if (fn === undefined) { | ||
objectType.prismaFields(); | ||
} | ||
else { | ||
fn(objectType); | ||
} | ||
var typesMap = objectType.getTypesMap(); | ||
var typeConfig = objectType.getTypeConfig(); | ||
var inputTypesToExport = getInputTypesToExport(typeConfig, typesMap); | ||
var connectionTypesToExport = getRelayConnectionTypesToExport(typeConfig, schema); | ||
addExportedTypesToGlobalCache(inputTypesToExport); | ||
return [ | ||
new core_1.WrappedType(objectType) | ||
].concat(inputTypesToExport, connectionTypesToExport); | ||
}; | ||
} | ||
exports.prismaObjectType = prismaObjectType; | ||
//# sourceMappingURL=prisma.js.map |
@@ -1,3 +0,2 @@ | ||
import { ArgDefinition } from 'nexus/dist/types'; | ||
import { core } from 'nexus'; | ||
import { ArgDefinition, SchemaConfig } from 'nexus/dist/types'; | ||
interface GenTypesShape { | ||
@@ -36,3 +35,3 @@ fields: Record<string, any>; | ||
export declare type PrismaObject<GenTypes, TypeName extends string> = GenTypes extends GenTypesShape ? TypeName extends keyof GenTypes['fieldsDetails'] ? GenTypes['fieldsDetails'][TypeName] : any : any; | ||
export interface PrismaSchemaConfig extends core.Types.SchemaConfig { | ||
export interface PrismaSchemaConfig extends SchemaConfig { | ||
prisma: { | ||
@@ -39,0 +38,0 @@ schemaPath: string; |
{ | ||
"name": "nexus-prisma", | ||
"version": "0.0.10", | ||
"version": "0.0.11", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "typings": "dist/index.d.ts", |
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
70398
1003