Git Product home page Git Product logo

Comments (5)

hayes avatar hayes commented on September 2, 2024

Interesting... I should probably add a note to the docs about this specific case. The root of this is in the circular reference. Even though logically we know that the options passed to implement won't affect the type of Author, typescript can't resolve the shape of Author until it has resolved the shape of the options object. The options objects for author and post circularly reference each other, so typescript can't properly resolve the types. I don't see an obvious way around this at the moment, but I can add a note to the docs to make this more explicit. Seems like for circular references you'll just have to split at least one of the types into 2 statements as you did above.

from pothos.

hayes avatar hayes commented on September 2, 2024

added a note to the docs

from pothos.

homoky avatar homoky commented on September 2, 2024

Is there a workaround for dataloader as well?

import { builder } from '../schema';
import Piece from './Piece';
import Arrangement from './Arrangement';

export default builder.loadableObject('Composer', {
  load: (ids: string[], ctx) => ctx.prisma.composer.findMany({ where: { id: { in: ids } } }),
  sort: (composer) => value.id,
  fields: (t) => ({
    id: t.exposeID('id', {}),
    firstName: t.exposeString('firstName'),
    lastName: t.exposeString('lastName'),
    fullName: t.string({ resolve: (parent, _args, _ctx) => parent.firstName + ' ' + parent.lastName }),
    slug: t.exposeString('slug'),
    bio: t.string({ resolve: async (parent, _args, ctx) => ctx.prismaTranslation(parent.bio) }),
    pieces: t.field({
      type: [Piece],
      resolve: async (parent, _args, ctx) => ctx.prisma.piece.findMany({ where: { composerId: parent.id }, orderBy: { createdAt: 'desc' } }),
    }),
    arrangements: t.field({
      type: [Arrangement],
      resolve: async (parent, _args, ctx) => {
        return ctx.prisma.arrangement.findMany({ where: { publishedAt: { not: null }, piece: { composerId: parent.id } }, orderBy: { publishedAt: 'desc' } });
      },
    }),
  }),
});
import { builder } from '../schema';
import { Context } from '../context';
import Composer from './Composer';
import Arrangement from './Arrangement';

export default builder.loadableObject('Piece', {
  load: (ids: string[], ctx: Context) => ctx.prisma.piece.findMany({ where: { id: { in: ids } } }),
  sort: (piece) => piece.id,
  fields: (t) => ({
    id: t.exposeID('id'),
    name: t.string({ resolve: async (parent, _args, ctx) => ctx.prismaTranslation(parent.name) }),
    slug: t.exposeString('slug'),
    description: t.string({ resolve: async (parent, _args, ctx) => ctx.prismaTranslation(parent.description) }),
    composer: t.field({
      type: Composer,
      resolve: async (parent, _args, ctx) => ctx.prisma.piece.findUnique({ where: { id: parent.id }, select: { composer: true }, rejectOnNotFound: true }).then((piece) => piece.composer),
    }),
    arrangements: t.field({
      type: [Arrangement],
      resolve: async (parent, _args, ctx) => {
        return ctx.prisma.arrangement.findMany({ where: { pieceId: parent.id, publishedAt: { not: null } } });
      },
    }),
  }),
});

from pothos.

hayes avatar hayes commented on September 2, 2024

I'm away from my computer right now, so can't give a complete answer or test right now, but, you can pass a ref instead of a name to loadable object.

Basically export const Composer = builder.objectRef<ComposerType>('Composer')

And then just do builder.loadableObject(Composer, {...})

Let me know if works, if not I can take a look on Monday

from pothos.

homoky avatar homoky commented on September 2, 2024

No rush @hayes, enjoy weekend. :D I opened #358 to keep this in one place separate of this issue.

from pothos.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.