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

feat(inflection): Pluggable inflector, smart-comment overridable #199

Merged
merged 76 commits into from
Apr 13, 2018
Merged

Conversation

benjie
Copy link
Member

@benjie benjie commented Mar 18, 2018

This replaces the old inflector interface with one that's pluggable. It also changes the inflector interface so that it's sent objects rather than strings; these objects contain more information so a) fewer params are required to be passed to inflectors, b) inflectors can use more information to make decisions - e.g. they can use smart comments!

  • Allow renaming tables comment on table post is E'@name message';
  • Allow renaming columns comment on column my_schema.my_table.my_column is E'@name alternativeColumnName';
  • Allow renaming relations comment on constraint thread_author_id_fkey on thread is E'@foreignFieldName threads\n@fieldName author';
  • Allow renaming unique-key record finder comment on constraint person_pkey on person is E'@fieldName findPersonById';
  • Allow renaming computed columns comment on function person_full_name(person) is E'@fieldName name';
  • Allow renaming custom queries comment on function search_posts(text) is E'@name returnPostsMatching';
  • Allow renaming custom mutations comment on function authenticate(text, text) is E'@name login';
  • Allow renaming custom mutation function result comment on function authenticate(text, text) is E'@name login\n@resultFieldName token';
  • Allow renaming types comment on type flibble is E'@name flamble';
  • Test all these things

E.g. the following SQL makes the changes shown in the

comment on column person.created_at is 'The time this person was created (required).';
comment on constraint thread_author_id_fkey on thread is E'@foreignFieldName threads\n@fieldName author';
comment on constraint post_author_id_fkey on post is E'@foreignFieldName messages\n@fieldName author';
comment on table post is E'@name message';

smart-comments-live


I should do this in a separate PR really, but oh well 🤷‍♂️

The following enables you to selectively omit things from the GraphQL API. This is not intended for implementing permissions (you should do that using GRANTs and RLS), it's for removing things from your API that you don't need - for example you most likely wouldn't want to expose a ts_vector column to GraphQL land even though you have read permissions to it for search. You can use this to turn off certain mutations for certain fields, however you should back these up with database permissions. Repeat: this is not intended for implementing permissions!

We currently support the following for table foo, column foo.bar and function qux:

Omit action Table Column Function
create no createFoo mutation column bar is not available on createFoo mutation -
read table not present column not present in any interface -
update no updateFoo or updateFooBy* mutations column bar is not available on updateFoo mutations -
delete no deleteFoo or deleteFooBy* mutations - -
filter no condition argument for allFoos / foosBy... cannot filter allFoos/etc by bar prevents filtering by computed column
order no orderBy argument for allFoos/etc cannot order by BAR_ASC or BAR_DESC cannot order by computed column
all no allFoos query - -
many no foosBy... fields - -
execute - - computed column / custom query / custom mutation is not exposed
  • Allow omitting allFoos query comment on table foo is E'@omit list';
  • Allow omitting createFoo* mutation comment on table foo is E'@omit create';
  • Allow omitting updateFoo* mutation comment on table foo is E'@omit update';
  • Allow omitting deleteFoo* mutation comment on table foo is E'@omit delete';
  • Allow omitting all 'Foo'-related interfaces comment on table foo is E'@omit';
  • Allow omitting from node interface
  • Allow omitting column from create
  • Allow omitting column from update
  • Allow omitting column from read
  • Allow omitting column from orderBy
  • Allow omitting column from condition (filter)
  • Allow omitting column from "by unique" finders/etc

omit2

Example of why this shouldn't be used for permissions: could use orderBy to derive the range of the value of a column.

@jemgillam
Copy link
Collaborator

Whoops sorry @omit I'll watch out for it in the future!

@benjie
Copy link
Member Author

benjie commented Apr 13, 2018

-- rebased on latest master --

@benjie
Copy link
Member Author

benjie commented Apr 13, 2018

One checkbox left unchecked; we can add support for that later.

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.

2 participants