Skip to content

Exercise to create a simple Media library with PostGraphile

Notifications You must be signed in to change notification settings

artetecha/hedgehog

Repository files navigation

This is Hedgehog 🦔, a GraphQL server developed using PostGraphile, thus PostgreSQL, too.

Features

  • Leverages the power of PostgreSQL. PostgreSQL is a powerful, open source object-relational database system that uses and extends the SQL language combined with many features that safely store and scale the most complicated data workloads. See an overview as well as the feature matrix.
  • Instant GraphQL CRUD API generated via PostgreSQL reflection API
  • Very fast performance (see here and here)
  • Hot reload that refreshes the API if the underlying database schema changes
  • Best practices:
    • GraphQL connections (see Original FB specs, and Explaining GraphQL Connections)
    • Globally unique identifier for caching (nodeId)
    • Only expose what you need to (--no-ignore-rbac, namespaces, @omit smart comments)
    • Only expose what the server can execute efficiently (--no-ignore-indexes)
    • Make schema flexible to allow non-breaking changes (mutation payloads rather than returning new records directly)
    • Proper mutation design (see, for example, Designing GraphQL Mutations)
    • Documentation (autogenerated from PostgreSQL comments)
    • Serve over HTTP accepting application/json and application/graphql ({"query": "...", "variables": {...}})
    • Avoid versioning (make non-breaking changes by adding deprecated computed fields/etc to replace the old fields)
    • Sensible nullability
    • Efficient execution (no N+1 issues, advanced query planner, even better than the recommended DataLoader approach)
    • Server-side Batching & Caching (Experimental)
    • Customisation of the GraphQL schema via plugins and PostgreSQL comments.

Routes

The application accepts POST requests on /, and (on non-production environments) exposes GraphiQL on /graphiql.

Package scripts

"scripts": {
    "start": "postgraphile",
    "command:seed": "node commands/seed.js",
    "command:schema": "node commands/schema.js"
  },

start

There is no dev or other "startup" script, since they would all be the same, simply executing postgraphile. The postgraphile executable will read its settings from .postgraphilerc.js. Please refer to PostGraphile documentation for more information about those settings.

command:schema

This is a utility implemented to load the schema and its updates on deployment. The main schema file, schema/main.sql must be kept up to date at all times. However, it will only be loaded on the first deployment of the application, when the database is found to be empty. Subsequent deployments will ignore that file, and look to find update files, schema/update.([0-9]+).sql. If these are found, their numbering is compared with the runtime configuration file located at run/schema-config.json, to determine what the latest update had been at the previous deployment, and run only the updates that came after it.

command:seed

This utility uses a GraphQL binding approach to implement a seeding script for the application. Please refer to the script itself for more information about it.

About

Exercise to create a simple Media library with PostGraphile

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published