hasura / graphql-engine

Blazing fast, instant realtime GraphQL APIs on your DB with fine grained access control, also trigger webhooks on database events.
https://hasura.io
Apache License 2.0
31.17k stars 2.77k forks source link

Support GraphQL mutation for CLI migrations #3899

Open tbenst opened 4 years ago

tbenst commented 4 years ago

Hi, thanks for this awesome server! I’m currently using SQL in migrations to seed the database. I’d love if I could use a GraphQL mutation instead. Let me know if I missed this in the documentation?

If not, I’d like to request this feature. Thank you!

marionschleifer commented 4 years ago

@tbenst could you elaborate a bit on the use case you would like to have this feature for? Is there a specific reason why you prefer GraphQL mutations over SQL in migrations?

tbenst commented 4 years ago

@marionschleifer, well, I’d like to use it for the same reason why someone might want to use hasura or GraphQL in the first place: it’s easy for me to write a single GraphQL mutation, and much harder to write the 6 separate insertion SQL command for each logical datapoint

tbenst commented 4 years ago

For example, insertions with UUIDs are painful. This would be trivial with GraphQL.

CREATE EXTENSION IF NOT EXISTS "uuid-ossp";

DO $$
DECLARE
  firstUuid uuid = uuid_generate_v4();
  secondUuid uuid = uuid_generate_v4();
BEGIN
  INSERT INTO Entities (id, "type", str) VALUES
    (firstUuid, 'fish', 'Tg(HuC:GCaMP6f)');
  INSERT INTO Entities (id, type, date) VALUES
    (secondUuid, 'date',
      '2020-01-28 10:00:00-08');
  INSERT INTO Relations (fromEntity, relation, toEntity) VALUES
    (firstUuid, 'hasDOB', secondUuid);
END $$;