exAspArk / graphql-guard

Simple authorization gem for GraphQL :lock:
MIT License
471 stars 36 forks source link

Allow inline policies to be used with class-based API of graphql-ruby 1.8 #16

Closed kymmt90 closed 6 years ago

kymmt90 commented 6 years ago

Partially fixes the problem discussed in #15

This PR allows inline guard policies to be used with class-based API of graphql-ruby 1.8.

In class-based API of graphql-ruby 1.8, GraphQL::Schema::Object and GraphQL::Schema::Field are used as base classes for class-based schema. In order to use class-based API with graphql-guard and to keep interface compatibility, these classes need to accept metadata guard and mask. accepts_definition is available for these cases.

http://graphql-ruby.org/api-doc/1.8.2/GraphQL/Schema/Member/AcceptsDefinition

Also in order to keep GraphQL::Guard::Testing compatibility, GraphQL::Schema::Object needs to have the class method .field_with_guard where these methods are utilized:

When class-based API is used, the testing method GraphQL::Field#guard uses objects converted by to_graphql.

These changes are tested by graphql-ruby 1.8.2.

coveralls commented 6 years ago

Coverage Status

Coverage remained the same at 100.0% when pulling 6be622d21e91e20724ad0e739e66db4b60e1d3ea on kymmt90:inline-policy-for-class-based-api into 71dc649fc2d8d20bb118d4bdef8b263637676e95 on exAspArk:master.

kymmt90 commented 6 years ago

@exAspArk How about this PR?

haizop commented 6 years ago

@exAspArk - So is this repository abandoned?

exAspArk commented 6 years ago

Hey, sorry for the delay. I'll have time to review the changes tomorrow

exAspArk commented 6 years ago

Seems like the changes break compatibility with previous GraphQL Ruby versions (GraphQL::Schema::Object.accepts_definition). Going to check whether it's possible to keep the version compatible or not.

exAspArk commented 6 years ago

Hey @kymmt90!

I merged your PR. I added some more changes in https://github.com/exAspArk/graphql-guard/pull/17 to keep graphql-guard compatible with older graphql-ruby versions. I also added a build matrix in travis.yml to build tests with graphql-ruby version 1.7 and 1.8 at the same time.

Thanks a lot for the PR! Great job! 🙌

kymmt90 commented 6 years ago

@exAspArk

Thank you for your review! 😄