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

    Akshay Kadam (A2K)

    04/01/2021, 6:33 AM
    What should the type be if I want to pass an object? Do I have to do
    JSON.stringify
    &
    JSON.parse
    here? Or do I need to separate those queries into
    totalSum
    &
    totalPaid
    ?
    Copy code
    export const Query = queryType({
      definition(t) {
        t.crud.blogs()
        <http://t.crud.blog|t.crud.blog>({
          alias: 'blog',
        })
        t.nonNull.field('totalSum', {
          type: 'Int', // ?? 
          resolve: async (_root, _args, ctx: Context) => {
            const totalSum = await ctx.prisma.blog.aggregate({
              sum: {
                price: true,
              },
            })
            const totalPaid = await ctx.prisma.blog.aggregate({
              sum: {
                price: true,
              },
              where: {
                paid: true,
              },
            })
            return {
    					totalSum: totalSum.sum.price,
    					totalPaid: totalPaid.sum.price,
    				}
          },
        })
      },
    })
    n
    • 2
    • 2
  • m

    Michael

    04/01/2021, 8:35 PM
    Anyone use graphql code generation with nexus?
    j
    d
    • 3
    • 16
  • m

    Michael

    04/01/2021, 8:35 PM
    If so do you have any guides or tutorials?
  • a

    Alex Vilchis

    04/06/2021, 6:44 PM
    Hello there 👋 What could be the reason I am not getting autocomplete suggestions when importing from the package
    nexus-typegen
    ?
    Copy code
    import { NexusGenEnums } from 'nexus-typegen';
    It seems that I always need to type the import manually 🤔
    r
    • 2
    • 1
  • n

    Nicolas Toulemont

    04/07/2021, 7:24 AM
    Hey folks, I’m trying to build a type guard function to facilitate the handling of union type query results but, while the runtime validation is no issue, I can’t get the types working. Here is the query union type
    Copy code
    export type CurrentUserQuery = (
      { __typename?: 'Query' }
      & { currentUser?: Maybe<(
        { __typename?: 'User' }
        & Pick<User, 'id'>
        & { profile?: Maybe<(
          { __typename?: 'Profile' }
          & Pick<Profile, 'id' | 'firstName'| 'lastName'>
        )> }
      ) | (
        { __typename?: 'UserAuthenticationError' }
        & Pick<UserAuthenticationError, 'code' | 'message'>
      ) | { __typename?: 'UserForbiddenError' } | { __typename?: 'InvalidArgumentsError' } | { __typename?: 'NotFoundError' } | { __typename?: 'UnableToProcessError' }> }
    );
    My goal is to have something like this, where both the typename and data must be generics types
    Copy code
    if(isType('User', data.currentUser)) {
    			// handle user with type safety
    } else {
    			// handle errors
    }
    I’ve given it a fair try but I think I’m missing something. Any ideas ?
  • j

    Julien Goux

    04/07/2021, 4:08 PM
    Interesting, I’m switching all over the place right now ^^
    👍 1
    n
    • 2
    • 4
  • j

    Julien Goux

    04/07/2021, 4:08 PM
    I think you could have more help on the Typescript discord server
    n
    • 2
    • 1
  • j

    Julien Goux

    04/07/2021, 4:08 PM
    I always have awesome feedbacks 🙂
  • j

    Julien Goux

    04/07/2021, 4:10 PM
    Also aren’t type guards supposed to map to only one type? I’m not sure you can automatically have data.currentUser to be all your error types in your else statement
  • m

    mikkelsl

    04/14/2021, 11:36 AM
    Any idea why I suddenly get this error, when trying to deploy?
    Copy code
    2021-04-14T11:07:09.800837812Z $ NODE_ENV=production node build
    2021-04-14T11:07:27.563867980Z /home/site/wwwroot/build/graphql/booking/area.js:47
    2021-04-14T11:07:27.563898783Z         t.crud.createOneArea({
    2021-04-14T11:07:27.563904383Z                ^
    2021-04-14T11:07:27.563908584Z 
    2021-04-14T11:07:27.563912784Z TypeError: t.crud.createOneArea is not a function
    I have used the t.crud's without any issues earlier, and it runs just fine when running the build locally. Wondering if it could be after upgrading
    "nexus-plugin-prisma": "^0.33.0"
    . Maybe someone has experienced the same?
    r
    • 2
    • 5
  • a

    Akshay Kadam (A2K)

    04/15/2021, 1:40 PM
    I'm using
    prisma@2.19.0
    &
    nexus@1.0.0
    with
    nexus-plugin-prisma@0.33.0
    & I'm getting the following error on `_t_.crud.acquisitions()`:
    Copy code
    property) acquisitions: <undefined>(opts: {
        type: "ERROR: No subset types are available. Please make sure that one of your GraphQL type is a subset of your t.model('<ModelName>')";
    } & {
        alias?: undefined;
        resolve?: CustomFieldResolver<...> | undefined;
        computedInputs?: LocalComputedInputs<...> | undefined;
    } & NexusGenPluginFieldConfig<...> & CommonFieldConfig & {
        ...;
    }) => NexusPrismaFields<...>
    Expected 1 arguments, but got 0.ts(2554)
    static.d.ts(144, 777): An argument for 'opts' was not provided.
    r
    m
    • 3
    • 5
  • a

    Akshay Kadam (A2K)

    04/15/2021, 1:41 PM
    Another error I get in
    Query
    field on `resolve`:
    Copy code
    t.nonNull.field('getAcquisitions', {
          type: 'Acquisition',
          resolve: async (_root, _args, ctx: Context) => {
            const acquisitions = await ctx.prisma.acquisitions.findMany()
            return acquisitions
          },
        })
    The error is:
  • a

    Akshay Kadam (A2K)

    04/15/2021, 1:41 PM
    Copy code
    type 'FieldResolver<"Query", "getAcquisitions">'.
      Type 'Promise<acquisitions[]>' is not assignable to type '{ acquired_at?: string | null | undefined; acquired_object_id?: string | null | undefined; acquiring_object_id?: string | null | undefined; acquisition_id?: string | null | undefined; ... 6 more ...; term_code?: string | ... 1 more ... | undefined; } | PromiseLike<...> | { ...; } | PromiseLike<...>'.
        Type 'Promise<acquisitions[]>' is not assignable to type 'PromiseLike<{ acquired_at?: string | null | undefined; acquired_object_id?: string | null | undefined; acquiring_object_id?: string | null | undefined; acquisition_id?: string | null | undefined; ... 6 more ...; term_code?: string | ... 1 more ... | undefined; } | { ...; }>'.
          Types of property 'then' are incompatible.
            Type '<TResult1 = acquisitions[], TResult2 = never>(onfulfilled?: ((value: acquisitions[]) => TResult1 | PromiseLike<TResult1>) | null | undefined, onrejected?: ((reason: any) => TResult2 | PromiseLike<...>) | ... 1 more ... | undefined) => Promise<...>' is not assignable to type '<TResult1 = { acquired_at?: string | null | undefined; acquired_object_id?: string | null | undefined; acquiring_object_id?: string | null | undefined; acquisition_id?: string | null | undefined; ... 6 more ...; term_code?: string | ... 1 more ... | undefined; } | { ...; }, TResult2 = never>(onfulfilled?: ((value: {...'.
              Types of parameters 'onfulfilled' and 'onfulfilled' are incompatible.
                Types of parameters 'value' and 'value' are incompatible.
                  Type 'acquisitions[]' is not assignable to type '{ acquired_at?: string | null | undefined; acquired_object_id?: string | null | undefined; acquiring_object_id?: string | null | undefined; acquisition_id?: string | null | undefined; ... 6 more ...; term_code?: string | ... 1 more ... | undefined; } | { ...; }'.
                    Type 'acquisitions[]' has no properties in common with type '{ acquired_at?: MaybePromise<string | null | undefined>; acquired_object_id?: MaybePromise<string | null | undefined>; acquiring_object_id?: MaybePromise<string | null | undefined>; ... 7 more ...; term_code?: MaybePromise<...>; }'.ts(2322)
    definitionBlocks.d.ts(160, 5): The expected type comes from property 'resolve' which is declared here on type 'NexusOutputFieldConfig<"Query", "getAcquisitions"> & { resolve: FieldResolver<"Query", "getAcquisitions">; }'
    r
    • 2
    • 2
  • j

    Julien Goux

    04/15/2021, 9:00 PM
    Hello all 👋 How crazy would it be to codegen Nexus code out of a TS function signature? 😅
  • j

    Julien Goux

    04/15/2021, 9:01 PM
    Am I the only one finding the task of wrapping domain use cases with GraphQL types boring as hell ?
  • d

    Dregond

    04/16/2021, 12:41 AM
    Hi All, im using Pal js to generate SDL first GQL service (I have a another service using Nexus). I have the below for Subscriptions:
    Copy code
    Subscription: {
        onCreateUser: {
          subscribe: () => pubSub.asyncIterator("SYNC"),
          resolve(payload: any) {
            return payload;
          },
        },
      },
    that's in resolver.ts. I need to add the resolver types into the resolverTypes.ts, Not sure whats the correct way (below is not working)
    Copy code
    export interface Subscription {
      [key: string]: Resolver<any, any, any>;
      onCreateUser?: Resolver<{}, any, Client.User>;
    }
    a
    • 2
    • 2
  • a

    Akshay Kadam (A2K)

    04/17/2021, 6:19 AM
    What is
    BigInt
    equivalent in Nexus? Should I use
    _t_.float('price_amount')
    ?
  • a

    Akshay Kadam (A2K)

    04/17/2021, 6:29 AM
    No worries, it was just like using
    DateTime
    . Had to use
    BigInt
    the same way:
    Copy code
    import { asNexusMethod } from 'nexus'
    import { GraphQLBigInt } from 'graphql-scalars'
    
    export const BigInt = asNexusMethod(GraphQLBigInt, 'bigint')
    I do think adding it to documentation would be much better
  • a

    Akshay Kadam (A2K)

    04/17/2021, 6:43 AM
    How do I use
    BigInt
    in an argument in
    minPrice
    &
    maxPrice
    :
    Copy code
    t.nonNull.list.field('getAcquisitionsByPrice', {
          type: 'Acquisition',
          args: {
            minPrice: nonNull(intArg()),
            maxPrice: nonNull(intArg()),
            undisclosed: nonNull(booleanArg()),
            skip: nonNull(intArg()),
            take: nonNull(intArg()),
          },
    It gives me an error right now:
    "Int cannot represent non 32-bit signed integer value: 10000000000"
    r
    • 2
    • 11
  • r

    Robert Witchell

    04/17/2021, 12:31 PM
    Question about
    connectOrCreate
    and
    computedInputs
    • 1
    • 2
  • k

    Kevin Kelly

    04/19/2021, 12:47 PM
    Hello everyone! I’m enjoying the nexus.js tutorial, but I’m running into an issue at the end of section 4. I wonder if anyone could help. The section I’ve completed is: https://nexusjs.org/docs/getting-started/tutorial/chapter-testing-your-api/ and when I try to run the tests, I get an error.
    a
    r
    • 3
    • 5
  • o

    Otrebu

    04/20/2021, 4:04 PM
    Hi All! I was just wondering, does anyone have issues with types in mutation resolvers? https://github.com/graphql-nexus/nexus/issues/892 On another note, does anyone worked out a good way to map input types that contain nullables straight into prisma client? They are not compatible as the typescript types on nexus has
    | null
    while prisma client doesn't. https://github.com/graphql-nexus/nexus/issues/819
    r
    • 2
    • 6
  • t

    Timo

    04/21/2021, 10:37 AM
    Is it possible to use variable parameters within fragments? If yes, how?
    Copy code
    t.field('comments', {
          type: 'Comments',
          nullable: true,
          args: {
            first: intArg({
              required: false,
            }),
            last: intArg({
              required: false,
            }),
            after: stringArg({
              required: false,
            }),
            before: stringArg({
              required: false,
            }),
          },
          resolve: async (parent, args, ctx) => {
            ...
          },
        })
    Copy code
    fragment Post on Post {
     id
     author
     content
     comments(first: 4 <-- this should be dynamic) {
      ...Comment
     }
    }
    o
    • 2
    • 4
  • j

    Joseph

    04/22/2021, 5:54 AM
    https://nexusjs.org/docs/plugins/prisma/overview#example I'm having a rough time finding where
    schema
    is exported from nexus
    ✅ 1
    r
    • 2
    • 6
  • p

    Piervincenzo Madeo

    04/22/2021, 9:39 AM
    Hello there! I'm trying to set up a project for my company using Next.js, Prisma 2, Nexus, Apollo, GraphQL and Passport for authentication. It's a content platform with subscriptions. I've seen some examples out there but I still have some doubts about getting started and scale up the project. Do you have any useful starter, example, or tutorial to suggest beyond the basics?
    d
    • 2
    • 4
  • p

    Piervincenzo Madeo

    04/22/2021, 9:40 AM
    thank you. Happy to meet you all guys
    👋 1
  • r

    Robert Witchell

    04/23/2021, 12:16 AM
    how to improve
    computedInputs
    code?
    a
    • 2
    • 3
  • p

    Philipp Humburg

    04/25/2021, 8:10 AM
    The Tutorial on nexusjs.org/docs/getting-started/tutorial/chapter-testing-with-prisma is still Broken as ist still does not correctly work with wiping the db after the tests
    r
    • 2
    • 3
  • b

    BRob

    04/28/2021, 10:17 PM
    While removing nexus-plugin-prisma, has anyone ran into the schema transpilation just “hanging”?
  • b

    BRob

    04/28/2021, 10:18 PM
    I use
    NODE_ENV=development ts-node --transpile-only schema
    on my schema but I think there must be something wrong in my types that causes it to hang
1...202122...25Latest