Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edge ordering #53

Closed
moret opened this issue Nov 5, 2015 · 7 comments
Closed

Edge ordering #53

moret opened this issue Nov 5, 2015 · 7 comments

Comments

@moret
Copy link

moret commented Nov 5, 2015

Hi.

I was looking for a way to order edges based on the parent document array, but couldn't find a way. For example, given a model with Person and Destinations and a database:

const destinations = [
  new Destination({name: 'London'},
  new Destination({name: 'Paris'},
  new Destination({name: 'Berlin'}
];

const people = [
  new Person({name: 'John', trips: [destinations[2], destinations[0]]}),
  new Person({name: 'Jane', trips: [destinations[1]]}),
  new Person({name: 'Jill', trips: [destinations[1], destinations[0]]})
];

and a query:

{
  people {
    name
    trips {
      edges {
        node {
          name
        }
      }
    }
  }
}

I would expect the result:

{
  "data": {
    "people": [
      {
        "name": "John",
        "trips": {
          "edges": [
            {
              "node": {
                "name": "Berlin"
              }
            },
            {
              "node": {
                "name": "London"
              }
            }
          ]
        }
      },
      {
        "name": "Jane",
        "trips": {
          "edges": [
            {
              "node": {
                "name": "Paris"
              }
            }
          ]
        }
      },
      {
        "name": "Jill",
        "trips": {
          "edges": [
            {
              "node": {
                "name": "Paris"
              }
            },
            {
              "node": {
                "name": "London"
              }
            }
          ]
        }
      },
    ]
  }
}

Is that currently possible with graffiti? I couldn't find a way to do it, nor to order in other collections. Thank you in advance for the attention!

@tothandras
Copy link
Contributor

@moret It's not currently possible to specify an order. It could be implemented by adding an orderBy enum type to arguments based on the fields of the type. We can add this feature request to our list, or you can send in a PR ;). Also, you can always do the ordering on the client side.

@moret
Copy link
Author

moret commented Nov 9, 2015

@tothandras I see. I would love to dive in and help with a PR, I'm just not sure if I will be able to right now. But I will keep an eye around. Thank you for your reply!

@tothandras
Copy link
Contributor

@moret Please take a loot at #61!

@moret
Copy link
Author

moret commented Nov 20, 2015

@tothandras looks great! In my use case I still need to use the association array own ordering which got solved in memory on the client as you suggested, but the orderBy solved all other sorting cases. Thanks a lot for the attention to that! 8)

@tothandras
Copy link
Contributor

@moret Is it okay if I merge it as it is? :)

@moret
Copy link
Author

moret commented Nov 20, 2015

@tothandras sure!

@tothandras
Copy link
Contributor

@moret #61 is merged and released under 4.3.0. ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants