Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
fieldArg.type.name as any,
typeToFieldOpts(fieldArg.type),
)
return acc
},
{},
)
return {
args: gqliteralArgs,
typesToExport,
}
}
const PageInfo = objectType('PageInfo', t => {
t.boolean('hasSomething')
})
// function relayConnection(field: string) {
// const Edge = objectType(`${field}Edge`, t => {
// t.id('id')
// t.field('node', field)
// })
// const Connection = objectType(`${field}Connection`, t => {
// t.field('edges', `${field}Edge`)
// })
// return [PageInfo, Edge, Connection]
// }
function exportRelayConnectionTypes(
prisma: path.join(__dirname, '../generated/prisma-client/index.ts'),
ctx: path.join(__dirname, '../context.ts'),
},
contextType: 'ctx.Context',
rootTypes: {
User: 'prisma.User',
//Post: 'prisma.Post',
},
},
// plugins: [prismaPlugin],
})
export const schema = buildSchema({
types: allTypes,
outputs: {
schema: path.join(__dirname, '../../schema.graphql'),
typegen: path.join(__dirname, '../generated/gqliteral.ts'),
},
typegen: {
imports: {
prisma: path.join(__dirname, '../generated/prisma-client/index.ts'),
ctx: path.join(__dirname, '../context.ts'),
},
contextType: 'ctx.Context',
rootTypes: {
export function buildPrismaSchema(options: PrismaSchemaConfig) {
const { schema, metadata } = makeSchemaWithMetadata(
options,
PrismaSchemaBuilder,
)
// Only in development envs do we want to worry about regenerating the
// schema definition and/or generated types.
const {
shouldGenerateArtifacts = process.env.NODE_ENV !== "production",
} = options;
if (shouldGenerateArtifacts) {
// Generating in the next tick allows us to use the schema
// in the optional thunk for the typegen config
metadata.generateArtifacts(schema);
}
},
fn?: (t: PrismaObjectType) => void,
): WrappedType[] {
// TODO refactor + make use of `objectTypeName`
const realTypeName =
typeof typeName === 'string' ? typeName : typeName.prismaTypeName
const objectType = new PrismaObjectType(realTypeName)
if (fn === undefined) {
return [new WrappedType(objectType), ...objectType.prismaFields()]
}
// mutate objectType
fn(objectType)
return [new WrappedType(objectType), ...objectType.getTypesToExport()]
}
})
export const CreateVariantInput = inputObjectType('CreateVariantInput', t => {
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const CreateProductInput = inputObjectType('CreateProductInput', t => {
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'CreateVariantInput', { required: true, list: true })
})
export const UpdateVariantInput = inputObjectType('UpdateVariantInput', t => {
t.id('id', { required: true })
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const UpdateProductInput = inputObjectType('UpdateProductInput', t => {
t.id('id', { required: true })
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'UpdateVariantInput', { required: true, list: true })
})
export const Mutation = prismaObjectType('Mutation', t => {
t.field('addProductsToCollection', 'Collection', {
import { arg, idArg, inputObjectType } from 'gqliteral'
import { prismaObjectType } from '../../../src'
import { VariantCreateInput } from '../../generated/prisma-client'
export const UniqueInput = inputObjectType('UniqueInput', t => {
t.id('id', { required: true })
})
export const CreateVariantInput = inputObjectType('CreateVariantInput', t => {
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const CreateProductInput = inputObjectType('CreateProductInput', t => {
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'CreateVariantInput', { required: true, list: true })
})
function exportInputObjectType(
inputType: GraphQLTypeObject,
typesMap: TypesMap,
seen: Dictionary,
): WrappedType[] {
seen[inputType.name] = true
const typesToExport: WrappedType[] = []
const inputObject = inputObjectType(inputType.name, arg => {
inputType.fields.forEach(field => {
if (field.type.isScalar) {
return getObjectInputArg(arg, field, typeToFieldOpts(field.type))
}
if (!seen[field.type.name]) {
typesToExport.push(
...exportInputObjectType(
typesMap.types[field.type.name],
typesMap,
seen,
),
)
}
arg.field(field.name, field.type.name as any, typeToFieldOpts(field.type))
import { arg, idArg, inputObjectType } from 'gqliteral'
import { prismaObjectType } from '../../../src'
import { VariantCreateInput } from '../../generated/prisma-client'
export const UniqueInput = inputObjectType('UniqueInput', t => {
t.id('id', { required: true })
})
export const CreateVariantInput = inputObjectType('CreateVariantInput', t => {
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const CreateProductInput = inputObjectType('CreateProductInput', t => {
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'CreateVariantInput', { required: true, list: true })
})
export const UpdateVariantInput = inputObjectType('UpdateVariantInput', t => {
t.id('id', { required: true })
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
export const CreateProductInput = inputObjectType('CreateProductInput', t => {
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'CreateVariantInput', { required: true, list: true })
})
export const UpdateVariantInput = inputObjectType('UpdateVariantInput', t => {
t.id('id', { required: true })
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const UpdateProductInput = inputObjectType('UpdateProductInput', t => {
t.id('id', { required: true })
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'UpdateVariantInput', { required: true, list: true })
})
export const Mutation = prismaObjectType('Mutation', t => {
t.field('addProductsToCollection', 'Collection', {
args: {
productIds: idArg({ required: true, list: true }),
collectionId: idArg({ required: true }),
},
resolve: async (_, args, ctx) => {
const collection = await ctx.prisma.updateCollection({
where: { id: args.collectionId },
import { arg, idArg, inputObjectType } from 'gqliteral'
import { prismaObjectType } from '../../../src'
import { VariantCreateInput } from '../../generated/prisma-client'
export const UniqueInput = inputObjectType('UniqueInput', t => {
t.id('id', { required: true })
})
export const CreateVariantInput = inputObjectType('CreateVariantInput', t => {
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const CreateProductInput = inputObjectType('CreateProductInput', t => {
t.string('name', { required: true })
t.field('brand', 'UniqueInput', { required: true })
t.field('attributesIds', 'UniqueInput', { required: true, list: true })
t.field('variants', 'CreateVariantInput', { required: true, list: true })
})
export const UpdateVariantInput = inputObjectType('UpdateVariantInput', t => {
t.id('id', { required: true })
t.field('optionsValueIds', 'UniqueInput', { list: true, required: true })
t.boolean('availableForSale', { required: true })
t.int('price', { required: true })
})
export const UpdateProductInput = inputObjectType('UpdateProductInput', t => {
t.id('id', { required: true })
t.string('name', { required: true })