https://www.prisma.io/ logo
Join Slack
Powered by
# graphql-nexus
  • b

    Brannon

    03/10/2022, 12:00 AM
    there is no
    t.decimal
    though (for example:
    <http://t.nonNull.int|t.nonNull.int>('orderId')
    )
    a
    • 2
    • 5
  • j

    Jonathan

    03/15/2022, 8:23 PM
    Does anyone have a good way of counting the number of
    prisma 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 buggy
    w
    y
    • 3
    • 3
  • k

    Kelly Copley

    03/20/2022, 4:39 PM
    Does anyone have a working example of using Nexus with graphql-codegen to generate apollo query hooks?
    n
    • 2
    • 1
  • j

    James Kienle

    03/30/2022, 2:52 AM
    Hey all! Question on the
    nexus-prisma
    module. I have the following model in
    schema.prisma
    Copy code
    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
    Copy code
    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 possible
    šŸ™Œ 1
    w
    • 2
    • 1
  • a

    Aniket Chavan

    04/04/2022, 2:59 PM
    I can only assume this question has been asked a million times so I apologise in advance but it is the sole reason I'm here šŸ˜… Is federation support coming to nexus any time soon? I'm currently trying to build out a backend which I want to split into microservices with a federated graph. Currently I'm using typescript + prisma + typegraphql + apollo server. The major issue I've been finding is how to handle both the data API as well as the backend API. I see both nexus and tgql offer tools to generate a code-first gql schema based on a prisma schema, but I don't know how to mark certain fields with @extends decorators for example if the type definitions are largely generated from the prisma schema.
    e
    • 2
    • 1
  • u

    Ulisses Cruz

    04/05/2022, 9:28 AM
    Hello, is it possible to autogenerate the prisma input filters to the graphql SDL?
  • y

    YeonHoPark

    04/06/2022, 10:01 AM
    Hi. why isn’t age defined in the User type of NexusGenObjects(i know that NexusGenObjects is the ā€œrootā€ type) ? the difference between the age field and other field’s is that the age field implements a resolver directly. In the picture of the official document below, the field that implements the resolver is also defined in the type.
    Copy code
    type User {
      age: String
      fullName: String
      name: String
    }
    j
    h
    w
    • 4
    • 8
  • e

    Erik

    04/11/2022, 2:32 PM
    i have a problem with the code below: running the mutation
    deleteOneTournament
    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?
    stuff_ts.ts
    • 1
    • 1
  • j

    John Smeeth

    04/12/2022, 2:55 PM
    hi all, I'm using prisma and nexus. I have a prisma model as below
    Copy code
    model 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
    Copy code
    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
    Copy code
    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
    Copy code
    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
    Copy code
    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 you
    e
    • 2
    • 1
  • j

    John Smeeth

    04/12/2022, 2:56 PM
    More information, this is type generated by nexus
    Copy code
    ServiceProject: { // root type
        displayOnServicePage?: boolean | null; // Boolean
        id?: string | null; // String
        name?: string | null; // String
        serviceId?: string | null; // String
        thumbnailUrl?: string | null; // String
      }
  • m

    Martin Pinnau

    05/09/2022, 2:44 PM
    Hi, is there an updated version of this upgrade guide available ? https://www.prisma.io/docs/guides/upgrade-guides/upgrade-from-prisma-1/upgrading-nexus-prisma-to-nexus
    n
    n
    • 3
    • 4
  • m

    Martin Pinnau

    05/09/2022, 2:46 PM
    It still uses
    nexus-plugin-prisma
    , I already removed it and installed
    nexus-prisma
    missing the corresponding steps for upgrade šŸ˜‰
  • s

    Shan8851

    05/14/2022, 8:57 AM
    šŸ‘‹ all, just looking with some help, pretty new to nexus and gql. I have a project that looks like so:
    Copy code
    type 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:
    Copy code
    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
    Copy code
    Object literal may only specify known properties, and 'stories' does not exist in type '(Without<ProjectCreateInput, ProjectUncheckedCreateInput> & ProjectUncheckedCreateInput) | (Without<...> & ProjectCreateInput)'.
    d
    n
    • 3
    • 2
  • m

    Martin Pinnau

    05/16/2022, 3:10 PM
    Hi there, is there a new way to set properties of a nexus stringArg to not required ? With prisma1 and nexus 0.11.7 this was done by
    Copy code
    args: {
            buttonName: stringArg({ required: false }),
          },
    this doesn't work anymore with @nexus/schema 0.20.1
  • m

    Martin Pinnau

    05/16/2022, 3:10 PM
    ...also searching for an alternative for
    Copy code
    stringArg({ list: [false] }),
  • w

    Will Potter

    05/25/2022, 11:35 PM
    Hi all, I’m pretty new to Prisma + Nexus but I’m very impressed so far. I’m using the new
    nexus-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.
    Copy code
    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:
    Copy 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:
    Copy code
    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
    n
    • 2
    • 3
  • w

    Will Potter

    05/25/2022, 11:38 PM
    I guess my question is, is this not supported? or is it a bug?
    t
    • 2
    • 2
  • d

    DaVinciLord

    06/01/2022, 8:17 PM
    [RESOLVED] Hi all, I have a problem on a project I'm currently working on with nexus and a custom graphQL Type My error is this :
    Copy code
    Property '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.ts
    āœ… 1
    • 1
    • 1
  • n

    Nathan Froese

    06/15/2022, 8:32 PM
    Has anyone used
    extendInputType
    in nexus successfully recently? I’m getting an error on the type for extendInputType and inputObjectType
    Copy code
    Type '"extendGetBookingByIdInput"' is not assignable to type 'keyof NexusGenInputs | keyof NexusGenEnums | keyof NexusGenScalars | AllNexusInputTypeDefs<any>'.
    here is the example code for inputs
    Copy code
    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
    Copy code
    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);
    	},
    });
  • t

    Travis James

    06/24/2022, 2:13 AM
    Is this GraphQL Nexus project even viable? It seems there is very little work done and the plugins are always pre-release.
    āœ… 1
    n
    • 2
    • 4
  • h

    hayes

    06/24/2022, 5:53 AM
    If you are looking for alternatives, you could check out https://pothos-graphql.dev/. Pothos has a lot in common with Nexus, but the plugin ecosystem is a little more developed. Not quite a drop in replacement, but not too different
    šŸ’Æ 3
    šŸ‘€ 1
    l
    • 2
    • 2
  • t

    tgriesser

    06/28/2022, 3:25 PM
    Is 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.
    šŸ‘Œ 1
    šŸ™ 2
    šŸ’Æ 2
    nexus 2
    h
    n
    • 3
    • 8
  • y

    YeonHoPark

    07/12/2022, 9:42 AM
    Hi !! I am using graphql-iso-date for date custom scalar. why is the type of Date custom scalar specified as any type ? can’t i explicitly specify the type ?
    a
    • 2
    • 2
  • m

    Matheus Assis

    07/12/2022, 3:01 PM
    Is there a way to create a nexus type that’s equivalent of
    Record<string, MY_TYPE>
    ??
    Copy code
    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 numbers
    y
    y
    • 3
    • 2
  • y

    YeonHoPark

    07/26/2022, 2:09 AM
    Hi ! I found the following error when using nexus-shield and subscriptionType together.
    Copy code
    "Cannot read property '_shield' of undefined"
    I have already seen related issue, and modified the code as below, but the error is not resolved.
    Copy code
    const server = new ApolloServer({
        context: ({ req }) => {
          return { _shield: { cache: {} } }
        },
        schema,
    ...
    index.ts
    Copy code
    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
    Copy code
    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
    Copy code
    "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"
    āœ… 1
    n
    n
    • 3
    • 3
  • n

    Nathan Froese

    08/09/2022, 5:59 PM
    currently my team is having a weird state and I want to avoid putting eslint-disable for
    parent: any
    Copy code
    /* 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
    Copy code
    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?
  • l

    Lasha Kvantaliani

    08/09/2022, 10:00 PM
    Hi Guys, I'm trying to migrate to Nexus. I do have
    graphql-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 operation
    n
    • 2
    • 1
  • c

    Charles Dimino

    08/09/2022, 10:21 PM
    I had an idea to try something to combine https://node-postgres.com/api/client#clientonnotification-notification-notification--void--void and https://nexusjs.org/docs/adoption-guides/nexus-framework-users#subscriptions-server to get subscription support, but it does require dropping down into the base pg library — is there a way to feed prisma a SQL response and have it turn it into whatever model it represents?
  • l

    Lasha Kvantaliani

    08/10/2022, 2:16 PM
    Hello, is anyone here out of 688 who is part of Prisma/Nexsus team? Yesterday it was late in Germany - I see, but if this channel is not where we can get help, maybe would be better if you’ll mention on the website and we’ll move to stackoverflow
    l
    n
    • 3
    • 2
  • v

    Vladi Stevanovic

    09/23/2022, 10:45 AM
    šŸ‘‹ Hello everyone! To streamline support for our Community, all questions about the Prisma ORM toolkit will now be answered in #general channel, and this channel will be archived next week. is now archived. We hope that this will allow us to help you more quickly and share the knowledge among all our community members. 😊 If you have any pending questions / issues, feel free to resolve them in the current threads or move the conversation into #general! šŸ§‘ā€šŸ’» Happy coding!
    šŸ‘ 1