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

    Matt

    09/22/2020, 4:07 PM
    I have a mutation that's an update of an existing db entry. I allow the mutation to update only the fields that the user needs so every arg is set to
    nullable: true
    (except id). What I'm concerned with is what if the user includes an arg of
    some_required_field:  null
    . Is there anything to prevent them doing this? Or do I need to write custom code to look through the args for any fields that are set to null that shouldn't be?
    r
    • 2
    • 1
  • p

    Pieter

    09/23/2020, 1:41 PM
    I am using
    @typescript-eslint/no-unused-vars
    rule and we are not ignoring the generated types from
    @nexus/schema
    due to needing the file in git for our tsc builds and we had an issue with massive git diffs when some team members linted from outside the root and eslint didn't ignore the changes, so we enforce it to be linted now. The problem is that after upgrading fron
    nexus 0.12
    to
    @nexus/schema
    we end up with this code at the bottom of the generated types:
    Copy code
    declare global {
      interface NexusGenPluginTypeConfig<TypeName extends string> {
      }
      interface NexusGenPluginFieldConfig<TypeName extends string, FieldName extends string> {
      }
      interface NexusGenPluginSchemaConfig {
      }
    }
    Eslint then throws this error:
    Copy code
    3238:38  error  'TypeName' is defined but never used   @typescript-eslint/no-unused-vars
      3240:39  error  'TypeName' is defined but never used   @typescript-eslint/no-unused-vars
      3240:64  error  'FieldName' is defined but never used  @typescript-eslint/no-unused-vars
    I can't add a
    // eslint-disable
    comment as the file gets regenerated the whole time. How do I fix this? CC @Ryan
    r
    • 2
    • 13
  • p

    Pieter

    09/23/2020, 5:08 PM
    Express Middleware vs Nexus Context I've setup context with
    schema.addToContext()
    but that seem to run each time a new resolver is triggered (so multiple times per request depending on the size of the gql query and the list count) I've thus removed the async data fetching from the
    addToContext
    method and added
    server.express.use
    middleware right above it in the same file. This seems to work great in dev mode with
    ts-node-dev --transpile-only api/graphql.ts
    which is my entrypoint that imports all the relevant files in order (context is at the top) and calls
    app.assemble()
    as I need this for vercel deployments. The problem is that in production (after running
    nexus build --entrypoint api/graphql.ts
    the express middleware do not seem to be running at all, despite running in dev.
    • 1
    • 2
  • s

    Swapnull

    09/23/2020, 5:54 PM
    Hey, I have a function which is like this. It gets the distance in meters between two lat/lngs
    Copy code
    schema.extendType({
      type: 'Query',
      definition: (t) => {
        t.int('getDistance', {
          args: {
            location1: schema.stringArg(),
            location2: schema.stringArg(),
          },
          resolve: async (_root, args, ctx) => {
             /* does maths and returns int */
          },
        })
      },
    })
    I then have 2 objects like
    Copy code
    schema.objectType({
      name: 'events',
      definition(t) {
        t.model.uuid()
        t.model.location()
      }
    })
    
    schema.objectType({
      name: 'suppliers',
      definition(t) {
        t.model.uuid()
        t.model.location()
      }
    })
    I basically want to say “For 1 supplier, find all events within a distance”. In JS you would do it like
    Copy code
    const getEvents = (supplier, events, distance = 1000) => 
      events.filter(e => getDistance(e.location, supplier.location) < distance);
    I want to do this while also having other where clauses
    Copy code
    query test($supplierId: String, $supplierLocation: String, $distance, $order: [eventsOrderByInput!], $startDate: DateTime,  $endDate: DateTime) {
      events(first: 5, orderBy: $order, where: {
        date: {gte: $startDate, lte: $endDate}
        /* something here that says only include it when getDistance($supplierLocation, event.location) < distance */
      }) {
        uuid
      }
    }
    Is it possible to use this type of thing? If not, how would people suggest achieving it? Maybe filter by distance on an initial query and then use that query as the base for any other queries or something? Is that even possible?
    r
    • 2
    • 6
  • m

    Michael Gardner

    09/24/2020, 5:36 PM
    (probably more of a pure prisma2 question but) do we have the ability through
    schema.prisma
    to tell the database a precision of float to prevent weird round-off errors? I’m thinking about values of latitude and longitude in a geolocation value.
    Copy code
    model Point {
      id        String    @id @default(cuid())
      createdAt DateTime? @default(now())
      updatedAt DateTime? @updatedAt
      Polygon   Polygon?  @relation(fields: [polygonId], references: [id])
      polygonId String?
      latitude  Float
      longitude Float
      altitude  Float?
    }
    would be my example for that. If not, I guess the one could adjust the
    createOnePoint
    and
    createManyPoints
    to shave off a few decimals, but it still doesn’t prevent possible data corruption from the storage in the database possibly. Currently im debating just making them strings and doing a migration later if this becomes a thing.
    r
    • 2
    • 3
  • a

    Adam

    09/25/2020, 9:38 PM
    is there any guidance for how to implement a mutlitenant app with prisma 2 and the nexus/graphql plugin? By multi-tenant I am having a shared table for all the data, and use selectors to differentiate the different environments
    a
    • 2
    • 3
  • d

    Dave

    09/26/2020, 1:33 PM
    I'm using Nexus and nexus-plugin-prisma, this allows me to add endpoints to express using
    server.express.get('/endpoint', async (req, res, ctx) => {}
    I can't however figure out how to access the prisma client from within the call, could anyone point me in the right direction please?
    m
    p
    • 3
    • 6
  • w

    windkomo

    09/28/2020, 9:38 PM
    Hi, is there a way to execute another mutation from a mutation resolver?
  • p

    Pierre Ortega

    09/28/2020, 9:58 PM
    @windkomo abstract the mutation logic into a function that you can call
    💯 1
  • m

    Matheus Assis

    09/29/2020, 7:35 PM
    Hello everyone 👋 I have a nexus setup using graphql-shield. And due to my business logic. I have some methods that require the user id for example:
    Copy code
    query GetContacts($userId: Int!) {
      userContactLists(where: { userId: { equals: $userId } }) {
        id
        name
      }
    }
    (This is just an example of a query, but there's also mutations that I want to apply that too) And it only works when there's a token and everything. But the userId property could be any userId, not the logged in user. What are the recommendations in those situations? I only want to allow if the provided userId is from the current logged in user.
    r
    • 2
    • 7
  • a

    Ahmed

    09/30/2020, 3:04 PM
    When the nexus framework stopped? and is there any plans to back it?
  • d

    Daniel Mahon

    09/30/2020, 3:21 PM
    @jasonkuhrt FYI the link to the framework halt announcement is broken on the DOCS site and the 0.3.0 release
  • j

    James Homer

    09/30/2020, 3:53 PM
    The framework is being abandoned??! Oh man I switched out my existing custom setup recently 🙁
  • d

    Daniel Mahon

    09/30/2020, 4:04 PM
    @James Homer looks that way, there are migration docs, framework back to nexus/schema, on the site but looks like they might stil be working on the official announcement…. I just recently finished migrating 2 projects to the framework so I feel for ya…, the good thing is at least with nexus schema there shouldnt be too many changes to go back to using apollo (which im guessing is one reason they are dropping it) but well just have to wait for the announcement
  • j

    James Homer

    09/30/2020, 4:06 PM
    Thanks @Daniel Mahon me too, I’d just got everything working nicely on Vercel!
  • s

    sven

    09/30/2020, 4:12 PM
    is this for real? I am working for 3 months on a project that is based on it -.-
  • a

    Ahmed

    09/30/2020, 4:13 PM
    Yes I just saw this and I have generated CRUD tool for two versions framework and schema so I ask if they dropped it I will remove it from my tools
  • a

    Ahmed

    09/30/2020, 4:15 PM
    Also, all my current projects were in nexus/schema with apollo. I didn't like the nexus framework at all
  • a

    Adam

    09/30/2020, 4:24 PM
    What was the official "nexus framework" vs just "nexus", I have a project that uses
    @nexus/schema
    and
    nexus-plugin-prisma
    , does anyone have a link to this announcement?
  • a

    Ahmed

    09/30/2020, 4:29 PM
    @Adam your project with @nexus/schema has no change. Just projects working with nexus need to move to @nexus/schema
  • a

    Adam

    09/30/2020, 4:29 PM
    gotcha
  • p

    Petr Homoky

    09/30/2020, 4:30 PM
    It was just the matter of the time when you regularly check the commits. It looks the same as with yoga 2.
  • p

    Petr Homoky

    09/30/2020, 4:31 PM
    I was in decision with new project and I had a feeling that this could come so I went only with the schema that has not too many updates recently but it is stable at least.
  • a

    Adam

    09/30/2020, 4:33 PM
    where is the announcement at? I dont see anything on
    <http://nexusjs.org|nexusjs.org>
  • a

    Adam

    09/30/2020, 4:33 PM
    the whole transition of things with nexus and prisma has been confusing, especially when I'm looking at
    <http://nexus.js.org|nexus.js.org>
    accidentally instead of
    <http://nexusjs.org|nexusjs.org>
    👍 1
    j
    • 2
    • 1
  • a

    Adam

    09/30/2020, 4:45 PM
    I also attempted to update
    nexus-plugin-prisma
    today from
    .19
    to
    .20
    and it errors on trying to find
    prisma.yml
    d
    • 2
    • 1
  • j

    jasonkuhrt

    09/30/2020, 5:22 PM
    <!here> Hey everyone, there is an important announcement regarding Nexus Framework here: https://nxs.li/unframework/about. If you are a Nexus Framework user, or considering it, please read this!
    💯 5
    😭 7
    😫 2
    👍 4
    ✔️ 19
    😌 1
  • s

    Sytten

    09/30/2020, 5:23 PM
    I think this is the right decision
    👌 2
    💯 15
  • s

    Sytten

    09/30/2020, 5:24 PM
    Schema integrates very well with apollo and other servers, we have been running on it for a few months now
  • s

    Sytten

    09/30/2020, 5:26 PM
    There is still a need for a better server than apollo IMO, but not a framwork
1...101112...25Latest