Code Monkey home page Code Monkey logo

Comments (14)

tsteuwer avatar tsteuwer commented on May 28, 2024

According to the JSON API spec:

Fetching Includes

An endpoint MAY also support an include request parameter to allow the client to customize which related resources should be returned.
[...]

GET /articles/1?include=comments HTTP/1.1
Accept: application/vnd.api+json

So, in regards to your comment above, you're request would actually look like:

GET http://localhost:3000/api/posts/9?include=author

Now, technically, we could also filter with this, so that would be:

GET http://localhost:3000/api/posts/9?include=author&filter["firstName"]=John

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

@digitalsadhu I have started on this and will most likley need help with it. I've started the branch feature/request-includes. I have added:

  • ✅ Check if the query object contains includes.
  • ✅ Check if the current method supports the parameter (e.g. DELETE, POST) should not include this param.
  • ✅ Added new test for DELETE if it's included.
  • ✅ If the current method does not support the parameter, JSON API spec says we must respond with a 400 error

... more to come.

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

:+1 sure thing. Just Sing out.

On Sun, 22 Nov 2015 at 02:16, Troy [email protected] wrote:

@digitalsadhu https://github.com/digitalsadhu I have started on this
and will most likley need help with it. I've started the branch
feature/request-includes. I have added:

  • Check if the query object contains includes.
  • Check if the current method supports the parameter (e.g. DELETE,
    POST) should not include this param.
  • Added new test for DELETE if it's included.

... more to come.


Reply to this email directly or view it on GitHub
#38 (comment)
.

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

@digitalsadhu delete the branch feature/request-includes, do a fetch, then check out the branch. I've changed a number of things. Here's my concern right now:

While I'm deleting the relationship from the attributes property, I have to then add it back as either an array of id's (IF it's a hasMany relationship), or just as a single property for a hasOne relationship. How would I find out what the key is for the relationship?

For instance:
Has One Relationship

data: {
   type: 'post',
   id: 5,
   attributes: {
     content: 'blah',
     other: 'other stuff'
     authorId: 22 <-- HAS ONLY ONE
   }
},
included: [
   {
      type: 'author',
      authorId: 22
      attributes: {
        firstName: 'John',
        lastName: 'Doe'
      }
   }
]

And for a hasMany...

data: {
   type: 'reviewerGroup',
   id: 1,
   attributes: {
     title: 'Reviewer Group 1',
     authority: 'Bosses'
     authorId: [22, 53] <--- HAS MANY
   }
},
included: [
   {
      type: 'author',
      authorId: 22
      attributes: {
        firstName: 'John',
        lastName: 'Doe'
      }
   },
   {
      type: 'author',
      authorId: 53
      attributes: {
        firstName: 'Joe',
        lastName: 'Shmoe'
      }
   }
]

It wont always be "id" or "authorId" and I have no idea how to do that in Loopback lol

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

Ok I've figured it out. Have single relationship requests via include=author. Now I need to get multiple relationship requests going, a la include=author,posts

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

@digitalsadhu @BenjaminHorn can I get one of you to CR what I've done so far. Is this the right way to go about this?

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

Cheers man, will try to take a look today/tonight

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

@tsteuwer you can always figure out everything you need to about relationships via
Model.relations for each model.

So if you are dealing with model Contract then just grab the Contract.relations object and look through it. It has the relationship type (belongsTo, hasOne, hasMany etc), the name of the foreign key and the value for it. It also gives you the from model and the to model but its important to note that the order is reversed for belongsTo.

Pretty easy to handle though, you just check the relation.type === 'belongsto' and then switch modelTo and modelFrom as @BenjaminHorn has done in his PR. Have a look in there for inspiration if you need to.

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

@digitalsadhu I did it! wooo hoo 👯 However, I can not, for the life of me, get 2 spaces working with vim. Is there any way to run a fix on the linter to autho-indent 2 spaces for me?

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

Nice one!

Haha damn indentation! There is an eslint formatted I believe so it's possible we could auto format yes. I haven't tried it but if you want you could give it a go and if it works ok add it to the project.

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

For se reason the one that comes with the project doesn't work. I've used jscs and it just works. Have you or @BenjaminHorn had a chance to check out the cr?

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

@tsteuwer Ok its Saturday night and I'm ready for open source! Will look through your code now!

from loopback-component-jsonapi.

tsteuwer avatar tsteuwer commented on May 28, 2024

@digitalsadhu was there anything else we need? Did you look over the code review? I can't remember the last thing that was said about this ticket

from loopback-component-jsonapi.

digitalsadhu avatar digitalsadhu commented on May 28, 2024

Merged into master as v0.11.0
Yay!

from loopback-component-jsonapi.

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.