Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@ruslantalpa
ruslantalpa / thoughts.md
Last active October 16, 2015 14:32
Thoughts on SQL backend/resolver for GraphQL server

We want to get back this result

{
	project: {
		id: 1,
		name: "First Project",
		description: "Create a cool website",
		client: {
			id: 1,
			name: "First Client"
[
{ "firstName" : "Daniel"
, "lastName" : "Díaz"
, "age" : 24
, "likesPizza" : true
}
,
{ "firstName" : "Rose"
, "lastName" : "Red"
, "age" : 39

Scenario 1, this i think models a real life scenario of how an api would evolve over time and we can test it it's actually possible to model versioning using shcemas

Start with 3 schemas that hold the versions of the api 1,2,3

  • v1 just holds a few tables with relations (let's go with companies/users/clients/projects/tasks (+the intermediat tables for many/many relations), i know the domain so i can spot the problems and provide scenarios) the relations are companies>clients>projects>tasks, companies>users, projects<>users the fields are basically id,name,name_id (this is the fk)
  • v2 needs to do this
  • change the name of the foreign keys from client_id to client_fk (new CTO that likes it that way :)) )
  • add a new BOOL field for the project table called "archived"
  • change the type of a field from the client table ("archived" change from int to bool)
#------------------------------------------------------------------------------
# ERROR REPORTING AND LOGGING
#------------------------------------------------------------------------------
# - Where to Log -
log_destination = 'csvlog' # Valid values are combinations of
# stderr, csvlog, syslog, and eventlog,
# depending on platform. csvlog
# requires logging_collector to be on.
---- this query si meant to return something similar to information_schema.view_column_usage
---- but only the columns that are actually in the SELECT part of the result
---- and the name of the column as used in the view definition
-- list only the columns from views
WITH view_columns AS (
SELECT
c.oid AS view_oid,
a.attname::information_schema.sql_identifier AS column_name