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

    rdunk

    07/04/2020, 11:00 AM
    Is it possible to implement transactions with prisma & nexus as of the latest update?
    r
    • 2
    • 13
  • m

    mikkelsl

    07/06/2020, 8:14 AM
    Is it possible to make the nexus-plugin-prisma (inside packages/api) recognise the schema.prisma in a lerna setup like below?
    r
    • 2
    • 1
  • d

    Darryl

    07/06/2020, 3:21 PM
    Hi, everyone. I’m trying to migrate to Nexus Framework but I’m having trouble with input types in one of my mutations. Previously, using
    @nexus/schema
    , I had quite a complicated mutation and for the input arg types, I was using what was auto-generated by nexus. Example code in the thread.
    r
    e
    • 3
    • 10
  • a

    Alex Vilchis

    07/07/2020, 12:12 AM
    Hello 👋, has anyone got an example of how to implement file upload in Nexus Schema? I was trying to use graphql-upload like this
    Copy code
    import { GraphQLUpload } from 'graphql-upload';
    import { schema } from 'nexus';
    
    schema.scalarType({
      ...GraphQLUpload
    });
    
    export const Upload = GraphQLUpload;
    ...but I get an error in the console:
    BadRequestError: request.body json expected to have a query field
    👀 1
    🙄 1
    a
    • 2
    • 2
  • l

    Lucas Munhoz

    07/07/2020, 7:52 AM
    Hey guys, I've been using this library for a few months and there's also an issue that its been bothering me. Basically the chicken and egg problem and it comes to generate the types for a query or mutation. I wonder if other people I having this issue, but I find this very counter intuitive. If you're not familiar with it, basically nexus needs to compile the code to be able to generate the types, if you are writing a mutation and you need to access the args that suppose to be typed, but they are not. That puts the workflow in a weird stop where the code is correct but it cant compile itself to generate it's types.
    r
    • 2
    • 7
  • a

    Andre Gustavo

    07/08/2020, 8:24 PM
    Copy code
    import { schema } from 'nexus'
    import { getUserId } from '../utils'
    
    schema.enumType({
      name: 'RoleBookStatus',
      members: ['BLOCKED', 'BORROWED', 'DAMAGED', 'ENABLED', 'UNENABLED'],
    })
    
    schema.objectType({
      name: 'Book',
      definition(t) {
        t.model.id()
        t.model.createdAt()
        t.model.updatedAt()
        t.model.title()
        t.model.author()
        t.model.publishedYear()
        t.model.publishingCompany()
        t.model.copies()
        t.model.availability()
        t.model.status()
        t.model.categories()
        t.model.createdBy()
      },
    })
    
    schema.inputObjectType({
      name: 'CreateBookInput',
      definition(t) {
        t.string('title', { required: true })
        t.list.string('author', { required: true })
        t.int('publishedYear', { required: true })
        t.string('publishingCompany', { required: true })
        t.int('copies', { required: true })
        t.boolean('availability', { required: true })
        t.field('status', { type: 'RoleBookStatus', required: true })
        t.list.string('coverImage', { required: true })
      },
    })
    
    
    schema.extendType({
      type: 'Mutation',
      definition(t) {
        t.field('newBook', {
          type: 'Book',
          args: {
            createBookInput: 'CreateBookInput',
            categories: 'CategoryWhereUniqueInput',
          },
          resolve: async (_root, { createBookInput, categories }, ctx) => {
            const userId = getUserId(ctx.token)
            if (!userId) {
              throw new Error('User identification failed!')
            }
            if (ctx.token && ctx.token.role === 'DEFAULT') {
              throw new Error('Not Authorized user add this data!')
            }
            const createdBy = await ctx.db.user.findOne({ where: { id: userId } })
            if (createdBy?.role === 'DEFAULT') {
              throw new Error('Not Authorized user add this data!')
            }
            
            return await ctx.db.category.create({
              data: {
                ...createBookInput,
                categories,
                createdBy: { connect: { id: userId } }
              },
              
            })
          },
        }),
    
      },
      // ------
    })
    Thank You!!!!!
    b
    • 2
    • 4
  • a

    Andre Gustavo

    07/08/2020, 8:24 PM
    Hello, please, how can I fix this? On "newBook" Mutation I've got this error:
    Copy code
    {
      "error": {
        "errors": [
          {
            "message": "\nInvalid `prisma.category.create()` invocation in\n/home/castro/Cursos/Nexus/librarydash-nexus/api/graphql/Book.ts:86:46\n\n   82 data: {\n   83   ...createBookInput,\n   84   categories,\n   85   createdBy: { connect: { id: userId } },\n→  86   // userId\n\n{\n        data: {\n          title: 'The book title sample',\n          ~~~~~\n          author: [\n          ~~~~~~\n            'John Doe',\n            'Jane Doe'\n          ],\n          publishedYear: 1870,\n          ~~~~~~~~~~~~~\n          publishingCompany: 'PublisherBooks',\n          ~~~~~~~~~~~~~~~~~\n          copies: 1800,\n          ~~~~~~\n          availability: true,\n          ~~~~~~~~~~~~\n          status: 'ENABLED',\n          ~~~~~~\n          coverImage: [\n          ~~~~~~~~~~\n            'cover1.jpg',\n            'cover2.jpg'\n          ],\n          categories: {\n          ~~~~~~~~~~\n            id: 24,\n            name: 'Tech'\n          },\n          createdBy: {\n          ~~~~~~~~~\n            connect: {\n              id: 1\n            }\n          },\n      +   name: String,\n      ?   books?: {\n      ?     create?: BookCreateWithoutCategoriesInput,\n      ?     connect?: BookWhereUniqueInput\n      ?   }\n        }\n      })\n\nUnknown arg `title` in data.title for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `author` in data.author for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `publishedYear` in data.publishedYear for type CategoryCreateInput. Did you mean `select`?\nUnknown arg `publishingCompany` in data.publishingCompany for type CategoryCreateInput.\nUnknown arg `copies` in data.copies for type CategoryCreateInput. Did you mean `books`?\nUnknown arg `availability` in data.availability for type CategoryCreateInput. Did you mean `select`?\nUnknown arg `status` in data.status for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `coverImage` in data.coverImage for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `categories` in data.categories for type CategoryCreateInput. Did you mean `name`?\nUnknown arg `createdBy` in data.createdBy for type CategoryCreateInput. Did you mean `name`?\nArgument name for data.name is missing.\n\nNote: Lines with + are required, lines with ? are optional.\n",
            "locations": [
              {
                "line": 2,
                "column": 3
              }
            ],
            "path": [
              "newBook"
            ]
          }
        ],
        "data": {
          "newBook": null
        }
      }
    }
    schema.prisma
    Copy code
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }
    
    generator prisma_client {
      provider = "prisma-client-js"
    }
         
    
    model User {
      id          Int @id @default(autoincrement())
      createdAt   DateTime @default(now())
      updatedAt   DateTime @updatedAt
      role        RoleUser @default(DEFAULT)
      firstName   String
      lastName    String?
      email       String @unique
      password    String
      books       Book[]
    }
    
    model Book {
      id                  Int @id @default(autoincrement())
      createdAt           DateTime @default(now())
      updatedAt           DateTime @updatedAt
      title               String @unique
      userId              Int
      author              String[]
      publishedYear       Int
      publishingCompany   String
      copies              Int
      availability        Boolean
      status              RoleBookStatus @default(ENABLED)
      coverImage          String[]
      categories          Category[] @relation(references: [id])
      createdBy           User @relation(fields: [userId], references: [id])
      
    }
    
    model Category {
      id      Int @id @default(autoincrement())
      name    String  @unique
      books   Book[]  @relation(references: [id])
    }
    
    enum RoleUser {
      ADMIN
      DEFAULT
      MANAGER
    }
    
    enum RoleBookStatus {
      BLOCKED
      BORROWED
      DAMAGED
      ENABLED
      UNENABLED
    }
    Book.ts
  • a

    Alex Vilchis

    07/09/2020, 1:23 AM
    Hello. Setting
    NODE_ENV
    to
    production
    causes the server to not listen to any requests (502). Does anyone know why?
    r
    • 2
    • 3
  • m

    Matt

    07/09/2020, 1:30 AM
    I have an app that was previously working that after upgrading is giving me this error:
    Copy code
    const GQLDateTime = asNexusMethod(GraphQLDateTime, "datetime");
                        ^
    
    TypeError: asNexusMethod is not a function
    I still have
    Copy code
    const { asNexusMethod } = require("nexus");
    in the code above the line where I'm using it. Any idea what's causing the issue?
    r
    • 2
    • 4
  • a

    Andrew Leung

    07/09/2020, 9:24 PM
    When using Nexus Framework, is there any kind of escape hatch that returns the actual
    GraphQLSchema
    produced by the framework? An example would be when trying to implement
    Subscriptions
    and using
    subscriptions-transport-ws
    web sockets. The excerpt from the README:
    Copy code
    import { createServer } from 'http';
    import { SubscriptionServer } from 'subscriptions-transport-ws';
    import { execute, subscribe } from 'graphql';
    import { schema } from './my-schema';
    
    const WS_PORT = 5000;
    
    // Create WebSocket listener server
    const websocketServer = createServer((request, response) => {
      response.writeHead(404);
      response.end();
    });
    
    // Bind it to port and start listening
    websocketServer.listen(WS_PORT, () => console.log(
      `Websocket Server is now running on <http://localhost>:${WS_PORT}`
    ));
    
    const subscriptionServer = SubscriptionServer.create(
      {
        schema,
        execute,
        subscribe,
      },
      {
        server: websocketServer,
        path: '/graphql',
      },
    );
    In order to get
    SubscriptionServer
    working, it requires the
    GraphQLSchema
    to be passed through.
    r
    j
    • 3
    • 5
  • h

    Henry

    07/14/2020, 3:00 PM
    Is there a way currently in nexus to have the capabilities of the nexus/schema plugins? I really want to migrate to nexus but all my current resolvers use the authorize and connectionField plugins
    r
    • 2
    • 1
  • p

    Pani Avula

    07/15/2020, 6:38 AM
    any plans to support deno?
    r
    • 2
    • 2
  • p

    Peter

    07/15/2020, 6:11 PM
    Hello In https://github.com/graphql-nexus/examples/blob/master/plugins-prisma-and-jwt-auth-and-shield/package.json is no version so yarn and npm throw error
    Copy code
    Package.json version field is not a string
    I also can’t report an issue on github 😢
    r
    • 2
    • 2
  • m

    Martin Nirtl

    07/17/2020, 12:26 PM
    hey!! can anyone tell me if nexus offers access to generated types? specified the type via schema.objectType and would like to use the generated type also from within the code
    r
    • 2
    • 7
  • m

    Michael

    07/18/2020, 6:45 AM
    After setting up a nexus template with paljs, running the dev server works fine. when trying to make a production build I'm getting 
    Error: node_modules/@types/typegen-nexus-context/index.d.ts:5:10 - error TS2459: Module '"../../../src/app"' declares 'Prisma' locally, but it is not exported.
     (+ another typescript error) though.
    a
    • 2
    • 22
  • m

    Michael

    07/19/2020, 9:45 AM
    does paljs work with yarn workspaces? I'v a workspace 'backend' when I run
    pal g
    inside the folder, I do get
    ✕ Error: @prisma/client is not found
    . Sounds like it's assumed in the local
    node_modules
    folder and not the monorepo's one.
    a
    • 2
    • 1
  • p

    Peter

    07/20/2020, 1:08 PM
    Hi What is the best way to split mutation or query (to seperated files) from. schema.mutationType?
    r
    r
    • 3
    • 10
  • r

    ryan

    07/20/2020, 3:31 PM
    Hi everyone! 👋 I recently started up at Prisma in developer relations and I'm hoping to get to know the wider Prisma/Nexus community a bit better 🙂 At Prisma, we're looking to better understand how Nexus users are currently making use of the framework and/or @nexus/schema. Some of the things we're interested in are: • which parts of Nexus are you using? • what (if any) pain/friction points are you encountering? • what does your wider GraphQL stack look like? If anyone would be interested in sharing their experience with Nexus, it would be awesome to chat with you. Please send me a DM and we can set something up 🙂 Thanks!
    🚀 2
    👍 4
    💯 2
  • m

    Michael

    07/20/2020, 4:00 PM
    hi! first of all thanks already for the many suggestions and help I received within the last couple of days here in the channels. I'm still struggling with setting up a graphql server that can be used with react-admin. Naturally I want to avoid as much boilerplate as possible, so the database schema should ideally be defined only once. Even though I consider
    paljs
    to be a very promising project, I think the CRUD that it generates does not fit to react-admin. Things get complicated because of a newer version of nexus-prisma (now nexus-plugin-prisma). so that the examples in react-admin are not up to date enough anymore. Does anyone have a up to date template for this architecture? I'm a bit irritated, why it's so hard to find something like this. It makes me wonder if my choices are to exotic. But from what I read prisma is widely used plus react-admin is maybe the admin framework with the most traction currently. I may be wrong, any hints welcome.
  • j

    jasonkuhrt

    07/20/2020, 4:52 PM
    <!here> Just to bring some attention to this 🙂 https://prisma.slack.com/archives/CM2LEN7JL/p1595259075364000
    👍 5
  • m

    Michael

    07/21/2020, 10:05 AM
    Regrding my post above. I'm making progress. I was able now to setup the server as I planned. And it works with react-admin. The only pain point is that I still have to manually define the nexus types according to my prisma schema. Mapping techniques explained in https://github.com/graphql-nexus/nexus-plugin-prisma/issues/299 did not work for me yet and seem to be kind of hacky. In any way, while doing this manually now (just the 'types', crud gets generated by react-admin). I'm having an issue with a 'DateTime' field. I'm getting this error:
    - Missing type DateTime, did you forget to import a type to the root query?
    Will post the whole file in a thread to the right.
    r
    a
    • 3
    • 23
  • m

    Michael

    07/21/2020, 11:31 AM
    suddenly I'm seeing
    - Missing type ActorWhereInput, did you forget to import a type to the root query?
    (only when
    addCrudResolvers("Actor"),
    is added) the server does not start, that wasn't the case before. does anyone have a hint what could be the issue here?
  • m

    Michael

    07/21/2020, 11:38 AM
    oh, had to run prisms2 generate again. ok. solved 🦆
  • p

    Peter

    07/21/2020, 1:15 PM
    I have some problem with generating type by prisma
    Copy code
    model EventCost {
      id          String    @id @default(uuid())
      amount      Int
      cost        Int
      eventTypes  EventType @relation(fields: [eventTypeId], references: [id])
      eventTypeId String
    }
    
    model EventType {
      id         String      @id @default(uuid())
      name       String
      visible    Boolean
      duration   Int
      eventCosts EventCost[]
    }
    I also try to create type by nexus
    Copy code
    schema.objectType({
      name: 'EventType',
      definition(t) {
        t.model.id()
        t.model.name()
        t.model.visible()
        t.model.duration()
        t.field('eventCosts', { type: 'EventCost' })
      },
    })
    but I got error that
    Copy code
    Type '"EventCost"' is not assignable to type ....
    When I’m checking generated schema I getting something like this
    Copy code
    type EventType {
      duration: Int!
      eventCosts: NEXUS__UNKNOWN__TYPE
      id: String!
      name: String!
      visible: Boolean!
    }
    
    scalar NEXUS__UNKNOWN__TYPE
    I run migration and rerun the nexus server but still missing the EventCost :|
    a
    w
    • 3
    • 8
  • a

    Awey

    07/21/2020, 7:09 PM
    Going through the testing section on the nexus tutorial, I came across an issue.
    Property 'query' does not exist on type 'NexusTestContextApp'.ts(2339)
    Not sure if I'm doing something wrong or if the tutorial is outdated/wrong. I pretty much copy pasted all the code it gave and there is still an error.
    a
    • 2
    • 16
  • p

    Peter

    07/21/2020, 7:27 PM
    How is the better way to create a input type in type list? I want to pass to input argument an array with objects.
  • a

    Awey

    07/21/2020, 7:56 PM
    Looking at this https://nexusjs.org/adoption-guides/nexus-schema-users it has an
    x
    beside JS support. Does that mean everything needs to be written in TS?
    r
    • 2
    • 1
  • a

    Awey

    07/21/2020, 10:43 PM
    Is graphql-nexus production ready?
    r
    • 2
    • 1
  • a

    Awey

    07/21/2020, 10:50 PM
    Also it seems like to use any package you have to do the following
    import * as
    or else it will not work. If anyone can explain to me why that is, I'd really appreciate it.
    r
    • 2
    • 4
  • a

    Awey

    07/21/2020, 11:02 PM
    Also, how do we get access to the request/response objects?
    a
    w
    • 3
    • 7
1...678...25Latest