graphile / global-ids

[EXPERIMENTAL] Allows you to use Relay global object identifiers in more places.
MIT License
9 stars 1 forks source link

Roadmap: additional CRUD methods on mapping tables #2

Open marshall007 opened 5 years ago

marshall007 commented 5 years ago

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 commented 5 years ago

Support for NodeID in custom functions would also be an acceptable solution here (see https://github.com/graphile/postgraphile/issues/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 commented 5 years ago

I certainly prefer the function approach 👍