Skip to content

Conversation

@brad-decker
Copy link
Contributor

Updates

  1. Removed the base64 encoding of order attribute from the cursor. Replaced with the index of the item itself.
  2. Updated all the logic based on this to provide true pagination regardless of the order by statement.
  3. Added a test case in integration/connections for custom queries and made sure all tests pass there.

Caveats

  1. Need more test cases to make sure nothing can break the pagination.
  2. A unit test for $parent failed on simplifyAST but i haven't touched that.
    Signed-off-by: brad-decker bhdecker84@gmail.com

@aweary
Copy link
Contributor

aweary commented Feb 22, 2016

👏

@mickhansen
Copy link
Owner

Travis isn't currently running the integration tests since a unit test fails (looks like it might be related to a graphql update, not sure).

return result;
}

module.exports = exports['default']; No newline at end of file
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lib/ should be in gitignore, either way please remove from PR

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the lib folder to this so i could use it straight from github for our application. I can remove it directly before its ready for merge. If you have an alternative suggestion to make this able to be installed from github so we can install versions that aren't ready for NPM for testing etc i'd love to implement that feature.

We use automated build processes on heroku so we are limited to what can be automatically installed.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm alright, please do remove before we merge.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

@mickhansen
Copy link
Owner

I've fixed the unit test, please rebase.

@mickhansen
Copy link
Owner

I generally like the approach of encoding the index in the cursor and then using that index.
The only issue i see is that it does not take into account the connection edges changing (i.e. more being added)

@brad-decker
Copy link
Contributor Author

I'm not familiar with that part of it. Could I alter the mutation test to account for this and add some tests in their for resulting order? Though I do believe that some of that would need to be handled on the client side in the relay mutation configuration using the fields config? Give me some guidance and i can work towards a test case that fails and then work on a resolution.

@mickhansen
Copy link
Owner

I was thinking more of changes to rows from outside graphql-relay.
But i'm not sure that the existing solution solved that any better actually.

ELSE "updatedAt" End ASC`);
}
return options;
},
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can simply add the literal to the value of the ENUM i believe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Didn't work for me because literal returns an object with {val : }

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, i believe i have that in one of my projects. Having an object shouldn't matter, the value in ENUM can be anything AFAIR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

      let orderBy = args.orderBy;
      let orderAttribute = orderByAttribute(orderBy);
      let orderDirection = args.orderBy[0][1];```

specifically this part of the connections configuration prevents that case because its looking directly for an array value. I tried setting it up directly in the order configuration first and it failed. 

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah alright, was sure i tried that out, but maybe i used a hook too.

@mickhansen
Copy link
Owner

@brad-decker Any update?

@mickhansen
Copy link
Owner

Do we even need to care about id in the cursor with this update? We could possible just move to the cursor generators provided by graphql-relay

@chrisbolin
Copy link

hey guys, what's the current status of this?

@mickhansen
Copy link
Owner

@brad-decker has been unavailable for a bit, waiting for him to be back. Do you have a usecase not solved by the current method @chrisbolin?

@chrisbolin
Copy link

I hit #170, which led me here :)

@mickhansen
Copy link
Owner

Ah, i didn't actually envision seeing a lot of MSSQL users i must admit :)

@chrisbolin
Copy link

Oh, I'm on Postgres. pageInfo.hasPrevious is always false though, due to the way the where query is created

@chrisbolin
Copy link

e.g. the where query looks like this

        "id": {
          "$gt": "71"
        }

if you have an after that evaluates to 71. Therefore full_count will not include anything less than 71.

@chrisbolin
Copy link

@chrisbolin
Copy link

actually, looking at the code closely, it looks like hasPreviousPage will always be false no matter what if you are running a first query

@brad-decker
Copy link
Contributor Author

@chrisbolin @mickhansen sorry for the delay... No promises but i should be able to work on this this week.

@chrisbolin
Copy link

no worries, @brad-decker! Thanks for taking a stab at this.

@chrisbolin
Copy link

I think this is probably related to the full_count issue: The last arg seems to generate funky queries. e.g.

"where": {
    "$or": [
      {
        "id": {
          "$lt": "103"
        }
      },
      {
        "id": {
          "$gt": "103"
        }
      }
    ]
  },

For example (last:3, before: "YXJyYXljb25uZWN0aW9uJDEwMyQxMDM=") (where that cursor is decoded to arrayconnection$103$103)

@mickhansen
Copy link
Owner

@chrisbolin Hmm yeah, full count is affected by where, odd i haven't encountered this since we do filter by id/order value.

@mickhansen
Copy link
Owner

All in all @brad-decker's update should work better. Not sure why i ruled out index in cursor as a proper fix in the beginning.

@brad-decker
Copy link
Contributor Author

@mickhansen can you do a final review of this and then i'll put our project that is using our fork on pause and remove the lib folder from the repository so you can merge. sorry for such a long delay on this.

@mickhansen
Copy link
Owner

@brad-decker IIRC i was quite happy with most of it, however the diff is near impossible at the moment.
If you could rebase and remove lib to clean it up i'll review asap.

@brad-decker
Copy link
Contributor Author

@mickhansen rebased and removed lib. I've got a failing test that was added in the relay test file regarding model connections that i have to figure out but i'll get on it shortly.

@mickhansen
Copy link
Owner

Still like 30-40 commits in the PR including merge commits.

@brad-decker
Copy link
Contributor Author

Hmm

@brad-decker
Copy link
Contributor Author

Ok successfully rebased, need to do some cleanup tho and fix that test still. Sorry about the false alarm there

@brad-decker
Copy link
Contributor Author

Cleanup done, test passing.

src/relay.js Outdated
/**
* Creates a cursor given a item returned from the Database
* @param {Object} item sequelize model instance
* @param {Integer} index the index of this item within the results, 1 indexed
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 indexed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@brad-decker
Copy link
Contributor Author

@mickhansen most of your points have been addressed now. Thanks for the feedback


it('should support nested aliased fields', async function () {
let result = await graphql(this.schema, `
it('should support in-query slicing with user provided args/where', async function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this test was changed although i don't think it was intentional.

Signed-off-by: brad-decker <bhdecker84@gmail.com>

removed defaultOrderBy for lint

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Weird conflict issue, fixing.

Signed-off-by: brad-decker <bhdecker84@gmail.com>

add one to startIndex if its not 0 to account for 0 indexed cursor

Signed-off-by: brad-decker <bhdecker84@gmail.com>

update tests to match results

Signed-off-by: brad-decker <bhdecker84@gmail.com>

fixing test

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

removed defaultOrderBy for lint

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

removed defaultOrderBy for lint

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cursor Reconfigure For Order

Signed-off-by: brad-decker <bhdecker84@gmail.com>

removed defaultOrderBy for lint

Signed-off-by: brad-decker <bhdecker84@gmail.com>

make graphql-sequelize useable from github

Signed-off-by: brad-decker <bhdecker84@gmail.com>

build should use internal version of babel

Signed-off-by: brad-decker <bhdecker84@gmail.com>

use internal node_modules version take 2

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Remove postinstall, add lib folder temporarily

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Weird conflict issue, fixing.

Signed-off-by: brad-decker <bhdecker84@gmail.com>

add one to startIndex if its not 0 to account for 0 indexed cursor

Signed-off-by: brad-decker <bhdecker84@gmail.com>

update tests to match results

Signed-off-by: brad-decker <bhdecker84@gmail.com>

removed lib

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Cleanup, fixed tests

Signed-off-by: brad-decker <bhdecker84@gmail.com>

Making requested Changes

Signed-off-by: brad-decker <bhdecker84@gmail.com>

renaming cursor to queriedCursor

Signed-off-by: brad-decker <bhdecker84@gmail.com>

rebase messed up some tests. replacing them

Signed-off-by: brad-decker <bhdecker84@gmail.com>

fixing one more test.

Signed-off-by: brad-decker <bhdecker84@gmail.com>
@brad-decker
Copy link
Contributor Author

Thanks @KATT @chrisbolin @mickhansen and everyone else for your patience here. 👏

@mickhansen mickhansen merged commit 4641eb6 into mickhansen:master Apr 19, 2016
@KATT
Copy link
Contributor

KATT commented Apr 19, 2016

Amazing!! Thank you so much for all the the time & effort you both put into this @mickhansen + @brad-decker! Can't wait to try it out.

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

Successfully merging this pull request may close these issues.

5 participants