cozemble / monorepo

A data and process canvas
https://cozemble.com
Apache License 2.0
13 stars 1 forks source link

Create a real database #38

Closed mike-hogan closed 1 year ago

mike-hogan commented 1 year ago

Given that aurora is set up And the user has made some models (lets say Customer and Address) And those models are being stored local storage in the browser

When a customer clicks "Apply to database" for the first time:

Now the data editor has to use that database instead of local storage. What API will it use? Because we only have a Postgres database

Option 1

Given that all data changes in the data editors are made using events, send the events to https://api.cozemble.com/:teamId/:modelId/:recordId

That endpoint can load all the models for the team, and the record, and "re-play" the events into the record, save it, and return the new record

Option 2

Make our our GraphQL endpoint that reflects the "shape" of the model. i.e if we have a Customer with a has-one Address, we can make this GraphQL api:

const schema = buildSchema(`
  type Address {
    id: ID!
    street: String!
    city: String!
    state: String!
    zip: String!
    customerId: ID!
  }

  type Customer {
    id: ID!
    name: String!
    email: String!
    address: Address
  }

  input AddressInput {
    street: String!
    city: String!
    state: String!
    zip: String!
  }

  input CustomerInput {
    name: String!
    email: String!
    address: AddressInput!
  }

  type Query {
    customer(id: ID!): Customer
  }

  type Mutation {
    createCustomer(input: CustomerInput!): Customer
  }
`);

And this would be hosted at https://api.cozemble.com/:teamId/graphql/v1.

But this would be dynamic, based on the models, not based on code generation. So if I have two teams, teamA and teamB, and teamA has models for Customer and Address, and teamB has models for Invoice and Order, when I hit this URL:

https://api.cozemble.com/teamA/graphql/v1, that GraphQL api will dynamically be about Customer and Address

And if I hit the url

https://api.cozemble.com/teamB/graphql/v1, that api will be about Invoice and Order

To implement this: