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

Roadmap: additional CRUD methods on mapping tables #2

Open
marshall007 opened this issue Feb 7, 2019 · 2 comments
Open

Roadmap: additional CRUD methods on mapping tables #2

marshall007 opened this issue Feb 7, 2019 · 2 comments

Comments

@marshall007
Copy link
Collaborator

In the special case of mapping tables (i.e. where all columns of the table definition can be represented as nodeIds), it would be nice if additional default CRUD methods were exposed for operating on them as a set of nodeIds. For example:

create table public.users_to_organizations (
  contract_id         text NOT NULL,
  organization_code   text NOT NULL,
  user_id             text NOT NULL REFERENCES public.users(auid),

  FOREIGN KEY (contract_id, organization_code) REFERENCES public.organizations(contract_id, code),
  PRIMARY KEY (auid, contract_id, organization_code)
)
mutation {
  # delete specified (or all, by default) existing mappings
  deleteAllUserToOrganizations(userNodeId: "...", organizationNodeIds: [ "..." ]) {
    user {
      # ...
    }
    organizations {
      # ...
    }
  }

  # create specified (or all, by default) existing mappings
  createAllUserToOrganizations(userNodeId: "...", organizationNodeIds: [ "..." ]) {
    user {
      # ...
    }
    organizations {
      # ...
    }
  }

  # delete all existing mappings from the table and insert specified new ones
  setAllUserToOrganizations(userNodeId: "...", organizationNodeIds: [ "..." ]) {
    user {
      # ...
    }
    organizations {
      # ...
    }
  }
}
@marshall007
Copy link
Collaborator Author

Support for NodeID in custom functions would also be an acceptable solution here (see graphile/crystal#979). You could imagine these mutations being implemented with a signature like:

public.set_all_user_to_organizations(u public.users, o public.organizations[])

@benjie
Copy link
Member

benjie commented Feb 8, 2019

I certainly prefer the function approach 👍

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