Coder Social home page Coder Social logo

Connections on interface about pothos HOT 7 CLOSED

hayes avatar hayes commented on August 15, 2024
Connections on interface

from pothos.

Comments (7)

hayes avatar hayes commented on August 15, 2024 1

I'll try to add this some time this weekend.

from pothos.

hayes avatar hayes commented on August 15, 2024 1

published a pre-release with the above API. Version info is in the PR description. Docs are in the first file in the chage-set if you want to try it out

from pothos.

hayes avatar hayes commented on August 15, 2024

Are defining the field on both the interface and the UserNode? I think of you omit the field on UserNode it would work, but I suspect you want a different resolver. I think for now you would need to manually define your connection object and implement the field like any other field. In general there isn't a way to re-use the connection types for multiple fields which is effectively what you need. I'll have to think about a solution for this that isn't just manually implementing everything.

from pothos.

NICHTJ3 avatar NICHTJ3 commented on August 15, 2024

Yes I'm defining the field on 3 things the Feed, the Profile and the Page.

My problem is effectively that I have a Feed and a Profile both of which have posts.

On the client I have a PostList component that uses a fragment to get the posts and I wanted to be able to reuse it between the Feed and Profile pages.

But to solve my problem for now what do you mean by manually defining my connection object?

from pothos.

NICHTJ3 avatar NICHTJ3 commented on August 15, 2024

If I can't find a nice solution to this I might just create two separate components for my post lists which might be the more correct thing to do

from pothos.

hayes avatar hayes commented on August 15, 2024

I am thinking about adding an API like:

const SharedConnection = builder.connectionObject(NumberThing);

builder.queryField('sharedConnection', (t) =>
  t.field({
    type: SharedConnection,
    nullable: true,
    args: {
      ...t.arg.connectionArgs(),
    },
    resolve: (root, args) =>
      resolveOffsetConnection({ args }, ({ limit, offset }) => {
        const items = [];

        for (let i = offset; i < Math.min(offset + limit, 200); i += 1) {
          items.push(new NumberThing(i));
        }

        return items;
      }),
  }),
);

Basically this would allow you to define a connection object type that is re-usable in multiple field definitions, adding an API to create connection args. This would let you define a PostsConnection object type, and then use that to define a field on your Page interface, as well as your Profile and Feed objects. The issue is that currently there is no way to use the same Connection type on multiple fields (a requirement for fields defined on interfaces)

from pothos.

NICHTJ3 avatar NICHTJ3 commented on August 15, 2024

That would be great. This is pretty much the solution I was hoping for 💯

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.