Brannon
03/10/2022, 12:00 AMt.decimal
though (for example: <http://t.nonNull.int|t.nonNull.int>('orderId')
)Jonathan
03/15/2022, 8:23 PMprisma queries
and collecting how many are run per resolver?
I want to add a Nexus plugin that can count them, but I worry due to the async nature of it all, storing queries on a global
object will simply be too buggyKelly Copley
03/20/2022, 4:39 PMJames Kienle
03/30/2022, 2:52 AMnexus-prisma
module. I have the following model in schema.prisma
model Product {
id String @id @default(uuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
category String @db.VarChar(64)
description String @db.Text
images String[] @db.VarChar(255)
name String @db.VarChar(64)
packageHeight Float
packageLength Float
packageWidth Float
price Int
quantity Int
shortDescription String @db.VarChar(255)
}
Inside of my schema, I have the following Nexus object
import { objectType } from 'nexus';
import { Product } from 'nexus-prisma';
export const product = objectType({
name: Product.$name,
description: Product.$description,
definition: (t) => {
t.field(Product.id);
t.field(Product.name);
t.field(Product.category);
t.field(Product.description);
t.field(Product.images);
t.field(Product.name);
t.field(Product.price);
t.field(Product.quantity);
t.field(Product.shortDescription);
},
});
Is there a way to automatically populate those fields in the object? I'd love to not have to repeat myself as much in my code where possibleAniket Chavan
04/04/2022, 2:59 PMUlisses Cruz
04/05/2022, 9:28 AMYeonHoPark
04/06/2022, 10:01 AMtype User {
age: String
fullName: String
name: String
}
Erik
04/11/2022, 2:32 PMdeleteOneTournament
and querying the "teams" field results in an error: Cannot return null for non-nullable field Tournament.teams.
. prisma.tournament.delete
does return an array with `Team`s, am I doing something wrong?John Smeeth
04/12/2022, 2:55 PMmodel ServiceProject {
id String @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
name String
thumbnailUrl String? @map("thumbnail_url")
displayOnServicePage Boolean @default(true) @map("display_on_service_page")
serviceId String
Service Service @relation(fields: [serviceId], references: [id])
ServiceProjectImage ServiceProjectImage[]
@@map("service_project")
}
And after run prisma generate
I got these
export type ServiceProjectCreateInput = {
id?: string
createdAt?: Date | string
updatedAt?: Date | string
name: string
thumbnailUrl?: string | null
displayOnServicePage?: boolean
Service: ServiceCreateNestedOneWithoutServiceProjectInput
ServiceProjectImage?: ServiceProjectImageCreateNestedManyWithoutServiceProjectInput
}
export type ServiceProjectUncheckedCreateInput = {
id?: string
createdAt?: Date | string
updatedAt?: Date | string
name: string
thumbnailUrl?: string | null
displayOnServicePage?: boolean
serviceId: string
ServiceProjectImage?: ServiceProjectImageUncheckedCreateNestedManyWithoutServiceProjectInput
}
I also define an inputObjectType via nexus as below
export const ServiceProjectCreateInput = inputObjectType({
name: 'ServiceProjectCreateInput',
definition(t) {
t.nonNull.string('name')
t.string('thumbnailUrl')
t.nonNull.boolean('displayOnServicePage')
t.nonNull.string('serviceId')
},
})
This is mutation
export const createServiceProject = mutationField('createServiceProject', {
type: 'ServiceProject',
args: {
data: arg({ type: 'ServiceProjectCreateInput' }),
},
resolve: async (_parent, { data }, context: Context) => {
return context.prisma.serviceProject.create({
data,
})
},
})
I got this error
Type '{ displayOnServicePage: boolean; name: string; serviceId: string; thumbnailUrl?: string | null | undefined; } | null | undefined' is not assignable to type '(Without<ServiceProjectCreateInput, ServiceProjectUncheckedCreateInput> & ServiceProjectUncheckedCreateInput) | (Without<...> & ServiceProjectCreateInput)'.
Type 'undefined' is not assignable to type '(Without<ServiceProjectCreateInput, ServiceProjectUncheckedCreateInput> & ServiceProjectUncheckedCreateInput) | (Without<...> & ServiceProjectCreateInput)'.ts(2322)
index.d.ts(5331, 5): The expected type comes from property 'data' which is declared here on type '{ select?: ServiceProjectSelect | null | undefined; include?: ServiceProjectInclude | null | undefined; data: (Without<ServiceProjectCreateInput, ServiceProjectUncheckedCreateInput> & ServiceProjectUncheckedCreateInput) | (Without<...> & ServiceProjectCreateInput); }'
ServiceCreateInput
What wrong with me? Can anybody give me an advise? thank youJohn Smeeth
04/12/2022, 2:56 PMServiceProject: { // root type
displayOnServicePage?: boolean | null; // Boolean
id?: string | null; // String
name?: string | null; // String
serviceId?: string | null; // String
thumbnailUrl?: string | null; // String
}
Martin Pinnau
05/09/2022, 2:44 PMMartin Pinnau
05/09/2022, 2:46 PMnexus-plugin-prisma
, I already removed it and installed nexus-prisma
missing the corresponding steps for upgrade šShan8851
05/14/2022, 8:57 AMtype Project {
createdAt: DateTime!
description: String!
examples: [String!]!
id: Int!
stories: [String!]!
title: String!
}
however I am struggling with the mutation for creating a project, my mutation currently looks like this:
export const ProjectMutation = extendType({
type: "Mutation",
definition(t) {
t.nonNull.field("add", {
type: "Project",
args: {
title: nonNull(stringArg()),
description: nonNull(stringArg()),
stories: nonNull(list(nonNull(stringArg()))),
examples: nonNull(list(nonNull(stringArg()))),
},
resolve(parent, args, context) {
const newProject = context.prisma.project.create({
data: {
title: args.title,
description: args.description,
stories: args.stories,
examples: args.examples,
},
})
return newProject
},
})
},
})
However it does not like stories or examples
Object literal may only specify known properties, and 'stories' does not exist in type '(Without<ProjectCreateInput, ProjectUncheckedCreateInput> & ProjectUncheckedCreateInput) | (Without<...> & ProjectCreateInput)'.
Martin Pinnau
05/16/2022, 3:10 PMargs: {
buttonName: stringArg({ required: false }),
},
this doesn't work anymore with @nexus/schema 0.20.1Martin Pinnau
05/16/2022, 3:10 PMstringArg({ list: [false] }),
Will Potter
05/25/2022, 11:35 PMnexus-prisma
plugin to create my Nexus objects and Iām running into an error when I try and add a field on a nexus schema that maps to another collection. Hereās the schema for reference.
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
homes Home[]
}
model Home {
id String @id @default(auto()) @map("_id") @db.ObjectId
userId String @db.ObjectId
user User @relation(fields: [userId], references: [id])
}
Hereās the nexus code:
export const User = objectType({
name: PrismaUser.$name,
description: PrismaUser.$description,
definition(t) {
t.field(PrismaUser.id);
t.field(PrismaUser.homes);
}
});
And hereās the error:
return new Error(`${name} was already defined and imported as a type, check the docs for extending types`)
^
Error: NEXUS__UNKNOWN__TYPE was already defined and imported as a type, check the docs for extending types
Will Potter
05/25/2022, 11:38 PMDaVinciLord
06/01/2022, 8:17 PMProperty 'buttons' does not exist on type '{ columns: number; id: string; name: string; rows: number; }'.
You can check-out the repo if you want to have an idea on how this is implemented => https://github.com/DaVinciLord/streamdeck-api/tree/SDAPI-20-add-button-mutation
Especially the code in this file https://github.com/DaVinciLord/streamdeck-api/blob/SDAPI-20-add-button-mutation/src/adapters/primaries/graphQL/grid/types.tsNathan Froese
06/15/2022, 8:32 PMextendInputType
in nexus successfully recently? Iām getting an error on the type for extendInputType and inputObjectType
Type '"extendGetBookingByIdInput"' is not assignable to type 'keyof NexusGenInputs | keyof NexusGenEnums | keyof NexusGenScalars | AllNexusInputTypeDefs<any>'.
here is the example code for inputs
export const extendGetBookingByIdInput = extendInputType({
type: "extendGetBookingByIdInput",
definition(t) {
t.field("hello", {
type: "String",
description: "a extended input",
});
},
});
export const GetBookingByIdInputWithExtended = inputObjectType({
name: "GetBookingByIdInputWithExtended",
definition(t) {
t.field("extentedInput", {
type: "extendGetBookingByIdInput",
description: "booking extednded attributes",
});
},
});
and here is the query
const getBookingByIdFoo: NexusExtendTypeDef<"Query"> = queryField("getBookingByIdFoo", {
type: nullable(Booking),
args: {
GetBookingByIdInputWithExtended: nonNull(
arg({
type: "GetBookingByIdInputWithExtended",
}),
),
},
resolve(src, args) {
return Services.Booking.getBookingById(args.extendGetBookingByIdInput.extentedInput);
},
});
Travis James
06/24/2022, 2:13 AMhayes
06/24/2022, 5:53 AMtgriesser
06/28/2022, 3:25 PMIs this GraphQL Nexus project even viable? It seems there is very little work done and the plugins are always pre-release.Creator of Nexus here - I canāt speak to the Prisma integration for it, but Nexus its-self will continue to be developed, weāre actively using it at Cypress (sans-Prisma) and I use it a bit on my own side projects. That said, I donāt have as much free time these days as I used to, so the development on the project might seem a bit stagnant at times / come in bursts when I have time to focus on it. Iāve been playing around with Pothos a bit recently and it seems like an excellent code-first option as well, great out-of-the-box plugin support and a lot of very well thought out APIs. So if youāre looking for something a bit more actively maintained, itās definitely another great option.
YeonHoPark
07/12/2022, 9:42 AMMatheus Assis
07/12/2022, 3:01 PMRecord<string, MY_TYPE>
??
export const PageState = objectType({
name: 'PageState',
definition(t) {
t.nonNull.string('id');
<http://t.nonNull.int|t.nonNull.int>('lastModified');
t.nonNull.string('rootId');
t.nonNull.field('root', {
type: ?????????? // <-- Here
});
}
});
MY_TYPE
is also another objectType
Basically more like a typed array but where indexes are strings and not numbersYeonHoPark
07/26/2022, 2:09 AM"Cannot read property '_shield' of undefined"
I have already seen related issue, and modified the code as below, but the error is not resolved.
const server = new ApolloServer({
context: ({ req }) => {
return { _shield: { cache: {} } }
},
schema,
...
index.ts
import { ApolloServer } from "apollo-server-express"
import express from "express"
import { WebSocketServer } from "ws"
import { createServer } from "http"
import { useServer } from "graphql-ws/lib/use/ws"
import { ApolloServerPluginDrainHttpServer } from "apollo-server-core"
import { makeSchema } from "nexus"
import { nexusShield } from "nexus-shield"
import { join } from "path"
import types from "./types"
export const schema = makeSchema({
types,
plugins: [nexusShield({})],
outputs: {
typegen: join(__dirname, "./src/generated", "nexus-typegen.ts"),
schema: join(__dirname, "./src/generated", "schema.graphql"),
},
})
const start = async () => {
const app = express()
const httpServer = createServer(app)
const wsServer = new WebSocketServer({
server: httpServer,
})
const serverCleanup = useServer({ schema }, wsServer)
const server = new ApolloServer({
context: ({ req }) => {
return { _shield: { cache: {} } }
},
schema,
plugins: [
ApolloServerPluginDrainHttpServer({ httpServer }),
{
async serverWillStart() {
return {
async drainServer() {
await serverCleanup.dispose()
},
}
},
},
],
})
await server.start()
server.applyMiddleware({
app,
path: "/",
})
const port = 4793
httpServer.listen(port, () => {
console.log(`š Server ready at <http://localhost>:${port}`)
})
}
start()
type.ts
import { extendType, objectType, stringArg, subscriptionType } from "nexus"
import { PubSub } from "graphql-subscriptions"
const pubsub = new PubSub()
const mutations = extendType({
type: "Mutation",
definition(t) {
t.field("createPost", {
type: "Post",
args: {
content: stringArg(),
author: stringArg(),
},
resolve: async (parent, args, ctx, info) => {
await pubsub.publish("createPost", {
data: {
author: "author",
content: "content",
},
})
return {
author: args.author,
content: args.content,
}
},
})
},
})
const subscription = subscriptionType({
definition(t) {
t.field("createPost", {
type: "Post",
subscribe() {
return pubsub.asyncIterator("createPost")
},
async resolve(eventPromise) {
const event: any = await eventPromise
return event.data
},
})
},
})
const Post = objectType({
name: "Post",
definition(t) {
t.id("id")
t.string("author")
t.string("content")
},
})
export default {
mutations,
subscription,
Post,
}
package.json
"apollo-server-core": "^3.10.0",
"apollo-server-express": "^3.10.0",
"express": "^4.18.1",
"graphql": "^16.5.0",
"graphql-subscriptions": "^2.0.0",
"graphql-ws": "^5.9.1",
"nexus": "^1.3.0",
"nexus-shield": "^2.2.0",
"ts-node-dev": "^2.0.0",
"ws": "^8.8.0"
Nathan Froese
08/09/2022, 5:59 PMparent: any
/* eslint-disable @typescript-eslint/no-explicit-any */
export const Booking = objectType({
name: NexusPrisma.Booking.$name,
description: NexusPrisma.Booking.$description,
definition(t) {
t.field(NexusPrisma.Booking.id);
t.field(NexusPrisma.Booking.readableId);
t.field(NexusPrisma.Booking.createdAt);
t.field(NexusPrisma.Booking.updatedAt);
t.field("bookingTimes", {
type: nonNull(list(nonNull(BookingTime))),
async resolve(parent: any) {
if (Object.prototype.hasOwnProperty.call(parent, "BookingTimes")) {
return parent.BookingTimes;
}
return await Services.Booking.getBookingTimesByBookingId(parent.id);
},
});
},
});
The type when hovered over t.field bookingTimes
(method) OutputDefinitionBlock<"Booking">.field<"bookingTimes">(name: "bookingTimes", config: NexusOutputFieldConfig<"Booking", "bookingTimes"> & { resolve: FieldResolver<"Booking", "bookingTimes">; }): void (+1 overload)
my work around for bookingTimes is this
t.field({ ...NexusPrisma.Booking.BookingTimes });
The type when hovered over t.field
(method) OutputDefinitionBlock<"Booking">.field<"BookingTimes">(config: NexusOutputFieldConfigWithName<"Booking", "BookingTimes">): void (+1 overload)
it works but does nexus and nexus-prisma resolves the join automatically in this case?Lasha Kvantaliani
08/09/2022, 10:00 PMgraphql-shield
which requires to return
errors instead of throw
them.
So, question: what is best practice to have ability to return for example ApolloError object and whatever type my graphql endpoint is returning?
Also, I had a case when I wanted to return 2 simple types: string and float. is there any simple way to set type string | float
? I've seen unions but to be honest sounds complicated for this kind of simple operationCharles Dimino
08/09/2022, 10:21 PMLasha Kvantaliani
08/10/2022, 2:16 PMVladi Stevanovic
09/23/2022, 10:45 AM