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

    Andrew Rhyne

    04/20/2020, 4:42 PM
    Is there some sort of reference freeing magic going on under the hood here?
  • a

    Andrew Rhyne

    04/20/2020, 4:43 PM
    With my apollo-resolvers package, I had to implement some hacky magic to avoid this problem: https://github.com/boltsource/apollo-resolvers/blob/master/src/context.ts#L14
  • t

    tgriesser

    04/20/2020, 4:44 PM
    the context is created once per-request, and so it should just be gc’ed naturally as long as it’s not referenced by anything long-lived
  • a

    Andrew Rhyne

    04/20/2020, 4:45 PM
    So that makes sense, but it appears that Context is referenced by the data source class instances and vice versa creating a circular reference
  • a

    Andrew Rhyne

    04/20/2020, 4:45 PM
    I could be fundamentally misunderstanding something, but my rather dated understanding of V8 and ECMA standards leads me to believe that circular references aren't automatically GC'd
  • a

    Andrew Rhyne

    04/20/2020, 4:45 PM
    Since the reference count on both objects is still greater than zero
  • t

    tgriesser

    04/20/2020, 4:45 PM
    They should be as long as there’s nothing retaining the root context
  • t

    tgriesser

    04/20/2020, 4:48 PM
    I’ve been using the pattern for awhile with 50-100 data sources off of the root context and seen any issues w/ memory leaks for it. It’s basically attempting to simulate a thread local state for JS
  • a

    Andrew Rhyne

    04/20/2020, 4:48 PM
    Yeah totally, it's a pattern i've used for a while as well. I just wanted to understand what best practices look like for an API built with Prisma, and wanted to make sure that I am not misunderstanding something
  • a

    Andrew Rhyne

    04/20/2020, 4:49 PM
    https://github.com/graphql-nexus/schema/blob/develop/examples/ghost/src/data-sources/UserSource.ts#L10 < so like right here
  • a

    Andrew Rhyne

    04/20/2020, 4:50 PM
    there is def a circular reference, was wondering if
    weakmap
    or something like it is being used but perhaps my GC knowledge is a bit rusty at this point haha
  • a

    Andrew Rhyne

    04/20/2020, 4:53 PM
    One last question: is there a way to share context outside of GraphQL easily with the normal nexus context "autoload" pattern? E.g. share between GraphQL resolvers and regular old express handlers (for use in webhook handlers, SSO, etc)
    t
    • 2
    • 6
  • b

    brandon

    04/21/2020, 11:18 PM
    So I am trying to deploy my application to heroku using docker, but I am getting key issues when it comes to transpiling nexus types… I have in my generate function
    GENERATE_ARTIFACTS=true ts-node --transpile-only src/index
    but it doesn’t close the connection. Is there a better way to transpile? I’m using apollo-server-express
    • 1
    • 1
  • b

    brandon

    04/22/2020, 4:03 AM
    Ok I finally got nexus working with Prisma2 and apollo on Heroku with docker. Do you guys think a tutorial would be helpful?
    💯 2
    n
    • 2
    • 2
  • d

    Darryl

    04/22/2020, 9:37 AM
    Can somebody please better explain to me the differences between the upcoming Nexus framework and the current Nexus Schema package. I see the message in my terminal but I’m not sure exactly which I need. For example, I’ve set up a fairly basic app using Prisma (2) and use nexus (how I did with Prisma 1) to expose certain CRUD operations. If that’s the extent of what I want to do, should I “continue using the Nexus Schema package please” by installing
    @nexus/schema
    or should I look into transitioning to the Nexus framework? I worry a little as I’ve had a few big refactors with Prisma over the past year with how things have changed and now I’m up-to-date with Prisma 2 (beta 3), I don’t want to settle on a nexus implementation I don’t fully understand and go live with something I’ll have to change down the line.
    n
    • 2
    • 3
  • m

    Matt

    04/24/2020, 2:36 PM
    @nikolasburk Are you considering serverless as an option for Nexus framework? Or is serverless something you rather wouldn’t recommend for prisma or graphql apis in general?
  • c

    Cameron

    04/24/2020, 6:26 PM
    For those struggling with the new
    nexus@next
    framework (not
    @nexus/schema
    ) and
    graphql-shield
    , I’m working on a plugin, that’ll help you. Link coming soon…
    a
    • 2
    • 1
  • b

    brandon

    04/24/2020, 7:39 PM
    I was struggling to figure out how to relate a particular nexus model. I have
    User
    and
    Cart
    Where it is a 1:1 relationship between the two. How do I do a query similar to
    t.crud.cart()
    if I want it to return the cart of the particular user? Do I have to create a custom resolver or does nexus provide a way to return cart of self within the arguments?
  • b

    brandon

    04/24/2020, 7:41 PM
    I thought it would make sense to do…
    t.crud.cart({ WhereUserIdIsInique: User });
    or something
  • b

    brandon

    04/24/2020, 7:50 PM
    ah nvm. I got it. It wasn’t working because I forgot to add Cart to types in MakeSchema. Also I can just use graphql Shield to do the authorization outside the querying logic of nexus.
  • c

    Cameron

    04/25/2020, 2:13 AM
    Checkout my plugin to get basic jwt authentication working with
    nexus
    . Please let me know your thoughts and how I can improve it 😄 https://github.com/Camji55/nexus-plugin-jwt-auth
    👍 4
  • l

    Luc

    04/26/2020, 9:54 AM
    And there is
    nexus-plugin-shield
    a port of
    graphql-shield
    for nexus! Rules and shield configuration are fully compatible. https://github.com/lvauvillier/nexus-plugin-shield
    👍 2
    🤩 1
  • p

    Paul

    04/26/2020, 12:04 PM
    Hi, did anyone run into
    Copy code
    Property 'prisma' does not exist on type 'NexusContext'.ts(2339)
    ?
    l
    • 2
    • 7
  • p

    Paul

    04/26/2020, 4:42 PM
    How do you handle errors? I want to add statusCode to a response. Something like this:
    Copy code
    "errors": [{
      "message": "..."
      "statusCode": "..."
      "locations: "..."
    }]
    is it possible with nexus? any ideas are appreciated
  • o

    Oliver Evans

    04/27/2020, 11:24 PM
    Does anyone have a few minutes to help me with a roadblock in prisma-nexus? I'm setting up a test repo based on https://github.com/prisma/prisma-examples/tree/master/typescript/graphql-apollo-server, but trying to upgrade from
    @nexus/schema
    to
    nexus
    framework
  • o

    Oliver Evans

    04/27/2020, 11:26 PM
    I think I almost have it working, until
    Copy code
    % yarn build
    yarn run v1.21.1
    $ nexus build
     877 ● nexus:build getting used plugins
     376 ● nexus:plugin:nexus-plugin-prisma Running Prisma generators ...
     411 ● nexus:build starting artifact generation
    4020 ● nexus:build building typescript program
    2822 ● nexus:build starting addToContext type extraction
       3 ● nexus:build Awaiting artifact generation & addToContext type extraction
       3 ● nexus:build Compiling a production build
    Error: node_modules/@types/typegen-nexus/index.d.ts:11:7 - error TS2503: Cannot find namespace 'Prisma'.
    
    11 'db': Prisma.PrismaClient
             ~~~~~~
    
        at Object.compile (/home/oliver/farmly/microservices/users/node_modules/nexus/dist/lib/tsc.js:63:15)
        at Object.buildNexusApp (/home/oliver/farmly/microservices/users/node_modules/nexus/dist/lib/build/build.js:63:11)
        at async Build.parse (/home/oliver/farmly/microservices/users/node_modules/nexus/dist/cli/commands/build.js:31:9)
    error Command failed with exit code 1.
    w
    • 2
    • 4
  • o

    Oliver Evans

    04/27/2020, 11:40 PM
    My current code can be found here: https://github.com/OliverEvans96/graphql-nexus-prisma-test
  • o

    Oliver Evans

    04/28/2020, 9:16 PM
    Is it possible to generate the resulting graphql schema from nexus framework without the server running?
    s
    • 2
    • 3
  • a

    Alex Vilchis

    04/29/2020, 5:43 PM
    Hello, I am trying to add a field that counts all of the entities of my database. I added the following field declaration in the query type:
    Copy code
    t.field('count', {
          type: 'CountPayload'
    });
    And then I declared my count payload type as this:
    Copy code
    const CountPayload = objectType({
      name: 'CountPayload',
      definition(t) {
        t.field('patient', {
          args: {
            where: arg({ type: 'PatientWhereInput' })
          },
          type: 'ModelCount',
          resolve: async (parent, args, ctx: Context) => {
            const { prisma } = ctx;
    
            return {
              count: await prisma.patient.count({ where: args.where })
            };
          }
        });
      }
    });
    
    const ModelCount = objectType({
      name: 'ModelCount',
      definition(t) {
        <http://t.int|t.int>('count');
      }
    });
    However this is not working ☹️. The
    count
    field in
    queryType
    is returning null. I want the resolve to come from the subfield. Is there a way to achieve this?
  • a

    Alex Vilchis

    04/29/2020, 7:36 PM
    I want the query field to execute the resolvers in the subfields, basically
12345...25Latest