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

Using Knex Adapter with KeystoneJS 5 and Postgresql: AdminUI keeps showing “GraphQL error: Cannot read property 'refListKey' of undefined ” #2610

Closed
ra-external opened this issue Mar 30, 2020 · 4 comments

Comments

@ra-external
Copy link

ra-external commented Mar 30, 2020

We have a KeystoneJS app which up until now has used MongoDB. Our DevOps want use to move to Postgresql, which KeystoneJS 5 supports through the Knex adapter.

I don't know much about Postgresql (I've used Mongo), but I followed the instructions at the above link and the DB is set up and running. I removed the authentication for Keystone as instructed and created a new User. However when I add the authentication back and login to the AdminUI I get the following error, not only on the user page, where it's repeated twice, but on other pages as well.

imagen

The relevant portion of code, where I connect the Knex adapter, is


const keystone = new Keystone({
    name: PROJECT_NAME,
    adapter: new KnexAdapter()
});

const createAuth = () => {
    authStrategy = keystone.createAuthStrategy({
        type: PasswordAuthStrategy,
        list: 'User',
        config: {
            identityField: 'username', // default: 'email'
            secretField: 'password' // default: 'password'
        }
    });
};

To get the DB set up the first time I had to use

 const keystone = new Keystone({
        name: PROJECT_NAME,
        adapter: new KnexAdapter({dropDatabase:true})
    });

I get these errors in the browser console

imagen

The application was running fine with Mongo and I have hardly changed anything. I have no references to refListKey in my code -- the only ones I could find were in the Keystone libraries.

This is my User list


import { Checkbox, Password, Text } from '@keystonejs/fields';

export default keystone => {
	keystone.createList('User', {
		labelField: 'username',

		access: {
			// 1. Only admins can read deactivated user accounts
			read: ({ authentication: { item } }) => {
				if (item.isAdmin) {
					return {}; // Don't filter any items for admins
				}
				// Approximately; users.filter(user => user.state !== 'deactivated');
				return {
					state_not: 'deactivated'
				};
			}
		},
		fields: {
			username: { type: Text },
			password: {
				type: Password,
				access: {
					// 3. Only admins can see if a password is set. No-one can read their own or other user's passwords.
					read: ({ authentication }) => {
						return authentication.item.isAdmin;
					},
					// 4. Only authenticated users can update their own password. Admins can update anyone's password.
					update: ({ existingItem, authentication }) => {

						return authentication.item.isAdmin || existingItem.id === authentication.item.id;
					}
				}
			},
			isAdmin: {
				type: Checkbox
			}
		}
	});
};

I am not using the just-released versions of the Keystone libraries, as there were problems with them that need to be resolved (this was another issue) -- but instead these

 "@keystonejs/adapter-mongoose": "^5.2.0",
    "@keystonejs/app-admin-ui": "^5.8.0",
    "@keystonejs/app-graphql": "^5.1.0",
    "@keystonejs/app-next": "^5.1.0",
    "@keystonejs/app-static": "^5.1.0",
    "@keystonejs/auth-password": "^5.1.0",
    "@keystonejs/field-content": "^5.4.0",
    "@keystonejs/fields": "^6.3.0",
    "@keystonejs/fields-markdown": "^5.1.0",
    "@keystonejs/fields-wysiwyg-tinymce": "^5.2.0",
    "@keystonejs/file-adapters": "^5.5.0",
    "@keystonejs/keystone": "^5.5.0",
    "@keystonejs/oembed-adapters": "^5.1.0",

Any clues on how to move forward would be much appreciated. Do I need to do something the Postgresql DB, and if so, what/how?

@molomby
Copy link
Member

molomby commented Apr 1, 2020

Hey @ra-external, looks like you maybe found a fix here. What was the resolution?

@ra-external
Copy link
Author

@molomby -- I don't think I did in the end. I think moving forward to newer versions of the packages did solve this error but introduced new ones. Sorry to be so vague -- trying to upgrade the packages together with using Postgresql has been a hassle and I've spent many hours trying many different combinations and getting many different errors, so I can't remember what worked and when. But I wasn't able to move forward, so for the moment I'm using Mongo and waiting for the latest version of the packages to appear soon. I'll upgrade and see if it fixes 'everything'.

@molomby
Copy link
Member

molomby commented Apr 3, 2020

Oh jeez, yeah.. just read your other issues. Sounds like you've hit a lot of snags :( Sorry about that

This iteration of Keystone's still pretty young so there will be occasional breaking changes. We use semver pretty conservatively, so the dependancies specified by a package should be fine, but if you have an old-ish @keystonejs/keystone and you're separately installing the latest @keystonejs/knex-adapter I'm not surprised there are issues.

You probably want to either install package version that were released around the same time (they will have all been tested against each other at release) or wait until all the latest packages work for you then upgrade them all at once. For this specific case I'd actually advise the latter -- there's been some really important work done on relationships in the knex adapter recently; probably worth holding out for the new stuff.

@ra-external
Copy link
Author

ra-external commented Apr 3, 2020

@molomby -- Thanks. I was told that there was a large PR that was going to be merged very shortly, so I'm hoping that that will solve many of my issues.

When you say "You probably want to either install package version that were released around the same time (they will have all been tested against each other at release": is there any way to get a package.json of each stable 'version'? That is, it could be that in rolling up and back I've gotten things out of whack. I'd be keen to find the latest working-together-well version of all the packages, but I'm not sure how to do that (which betrays my NPM ignorance, of course). For instance, if soon there will be a new stable version, in which all the parts work well together, how, apart from looking through all the libraries, would I know the last time that all the parts worked well together, and what the package numbers were?

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