Giter Club home page Giter Club logo

Comments (8)

ntucker avatar ntucker commented on May 25, 2024

Thanks for the report!

Is this mainly about discoverability? I.e., you couldn't figure out how to write code to create - or is it also about readability - i.e., Resource.getList.push doesn't make sense.

from data-client.

th3fallen avatar th3fallen commented on May 25, 2024

the latter mostly

from data-client.

ntucker avatar ntucker commented on May 25, 2024

Hmm, curious about the use case: Do you want to create a new item and not add it to a list? Do you have a list endpoint at all?

from data-client.

ntucker avatar ntucker commented on May 25, 2024

For context, the API was modeled after Backbone collections

from data-client.

ntucker avatar ntucker commented on May 25, 2024

Hmm, push is the standard terminology I've found:

Do you have a suggestion for a better way to distinguish adding to end, beginning, or inserted in sorted order?

from data-client.

jacobcossman avatar jacobcossman commented on May 25, 2024

I am having a slightly different but related issue, which I can open a new issue for if necessary. I cannot determine how to extend getList.push in order to specify a new body type for the POST request. The following does not work:

const InternalUserBaseResource = createResource({
    urlPrefix,
    path: 'internal/users/:userId',
    schema: InternalUser,
    Endpoint: AuthdEndpoint
})

export const InternalUserResource = InternalUserBaseResource.extend({
    ...InternalUserBaseResource,
    getList: {
        ...InternalUserBaseResource.getList,
        push: {
            ...InternalUserBaseResource.getList.push,
            body: {} as InternalUser & { password: string }
        }
    }
})

I get the following error:

TypeError: Cannot set property push of [object Object] which has only a getter

I may have missed it but I don't see anywhere in the docs or migration guide how we're supposed to extend this new getList.push method of creating entities. Do I have to extend create instead and ignore the deprecation warnings?

from data-client.

ntucker avatar ntucker commented on May 25, 2024

@jacobcossman Thanks for the report.

A few things of note:

  • Resource.extend() cannot be used with spread.
  • RestEndpoint.push inherits the body type from its parent. Since 'GET' RestEndpoints don't use the body, you can simply set the getList body and it will only be used with unshift and push.

This means you can achieve what you desire by using the override version of Resource.extend

export const InternalUserResource = createResource({
    urlPrefix,
    path: 'internal/users/:userId',
    schema: InternalUser,
    Endpoint: AuthdEndpoint
}).extend({
    getList: {
        body: {} as InternalUser & { password: string }
    }
});

In an effort to help others avoid this confusion - was this the upgrade guide you were looking at? If not, could you link to what you were looking at?

PS) To help others more easily find issues, I would prefer new issue opened and simply include a reference to related issues when mentioning. It can be difficult to navigate in a block of comments for things, but including links ensures people can still find slightly related things easily.

from data-client.

jacobcossman avatar jacobcossman commented on May 25, 2024

@ntucker thanks so much! Yes, the upgrade guide you linked is what I was looking at. I think a note under the Resource.extend() section for this specific use case would be very helpful.

Also noted about opening new issues 👍

from data-client.

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.