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

Authorization PR #39

Open
wants to merge 75 commits into
base: authorization-implem
Choose a base branch
from
Open

Conversation

tobkle
Copy link
Contributor

@tobkle tobkle commented Aug 3, 2017

No description provided.

tobkle and others added 30 commits May 21, 2017 10:01
Thoughts here:

1. We only need one authorized loader (for the `readOne` case).
2. We can determine the `authQuery` at initialization time, assuming that a single user will be used for all queries (this is the case).
3. We can have the user at initialization time, although this will require refactoring the way the context is initialized here: https://github.com/tobkle/create-graphql-server/blob/master/skel/server/index.js

  i. We need to add the models to the context *after* the authentication, i.e. here: https://github.com/tobkle/create-graphql-server/blob/master/skel/server/index.js#L44

 ii. This will mean that we need a different reference to the mongo collection in the `passport.authenticate` call. But we can make that work I think, it doesn't really need the proper user collection.
Simplify authorized loader.
@tobkle
Copy link
Contributor Author

tobkle commented Aug 23, 2017

Did the change. First prototype of the adjusted generator is running. Tests are passing. Except for the yarn.lock on CircleCI. Had it run with npm instead of yarn the last time, as yarn was causing problems in my local environment. Yarn hadn't got any network connect. Haven't had the time yet to solve that. Can you give me some comments about the way the generator is implemented? Reading the AST is not so well done yet. Also the code replacement in the model file, but it was the easiest first approach. I should find some time to continue on the weekend.

Copy link
Owner

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

Just a few drive by comments, sorry really busy at the moment but, wow, you've been pushing hard on this :)

roleArgument.name &&
roleArgument.name.kind === NAME &&
roleArgument.name.value &&
roleArgument.name.value !== ''){
Copy link
Owner

Choose a reason for hiding this comment

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

In general do we need to be this defensive with this AST reading code? Aren't there certain guarantees about what comes out of graphql?

Copy link
Owner

Choose a reason for hiding this comment

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

It makes this code quite hard to read having all these null checks.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed it

const that = this;
try {
generateAuthCodeModeReadOne
} catch (err) { log.error(err.message); }
Copy link
Owner

Choose a reason for hiding this comment

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

I thought we were going to get rid of these try/catch blocks?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed them

const LIST_VALUE = 'ListValue';
const DIRECTIVE = 'Directive';
const ARGUMENT = 'Argument';
const NAME = 'Name';
Copy link
Owner

Choose a reason for hiding this comment

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

I'm pretty sure you can get these constants out of the graphql package.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I do now.

that.authorizedLoader = new DataLoader(ids => findByIds(this.collection, ids, authQuery));`;
} else {
// User has to come from this.context.User
generatedCode = `const { me, User } = context;
Copy link
Owner

Choose a reason for hiding this comment

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

Did you try embedding the code in some templates?

I know it's a bit clunky but it seems like it's easier to modify later if it's not buried inside a big file like this.

Also, it's a bit inconsistent to do it differently here.

I'd be cool with a different way of doing templating (maybe with proper string interpolation, or using handlebars or something?) if you wanted though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added handlebars templating for models and resolvers, allows also to treat the user type differently then the other types. so the additional coding with bcrypt and password don't have to be entered manually any more.

@tobkle
Copy link
Contributor Author

tobkle commented Sep 7, 2017

Have now two active branches master (this) and another one, where I've integrated both, Authorizations and Query Arguments.

@tmeasday
Copy link
Owner

tmeasday commented Sep 8, 2017

Sorry I am lagging so much on this, crunch time for me right now.

@tobkle
Copy link
Contributor Author

tobkle commented Sep 8, 2017

Don't mind. Whenever you have the time. Have learnt a lot on this project so far. Thanks for your work.

@tmeasday
Copy link
Owner

Wow, this is looking really amazing

Copy link
Owner

@tmeasday tmeasday left a comment

Choose a reason for hiding this comment

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

Just a couple of smaller things (well the onAuthRegisterLoader thing might be annoying, not sure).

The code generation stuff is unsurprisingly pretty complex now but I think it's an improvement on what came before.

I think you still need to run prettier/linting over the code, but it's almost ready!

['authorId', 'coauthorsIds'],
{ User },
onAuthRegisterLoader('tweet findOneById', 'readOne', me, this)
);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand this part -- why does it need to be async (or callback-based)?

Is it because onAuthRegisterLoader "doesn't throw exception in error case"? What is the error case? Why is it legitimate?

return this.loader.load(id);
async findOneById(id, me, resolver) {
const log = authlog(resolver, 'readOne', me);
if (!this.authorizedLoader) {
Copy link
Owner

Choose a reason for hiding this comment

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

I don't understand why it would ever be allowed that you do not have an authorizedLoader.

inputField = field;
// take field as it was entered
CreateInputField = field;
// on updates, on NonNullable entered fields, the user should be able to decide, if he wants to update
Copy link
Owner

Choose a reason for hiding this comment

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

Best not to use gender specific language--make it eg. "the user should be able to decide, if they want to update"

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.

None yet

2 participants