[WIP] feat: Read all graphql configuration from postgres#9
[WIP] feat: Read all graphql configuration from postgres#9david-martin wants to merge 8 commits intoaerogear-attic:masterfrom david-martin:read-gql-config-from-db
Conversation
| }) | ||
|
|
||
| return DataSource | ||
| } |
There was a problem hiding this comment.
@pb82 fyi, here is the sequelize model for a Data Source, based on the schema being used for the UI
(i.e. https://github.com/aerogear/data-sync-ui/blob/master/gql/schema.js#L4-L16)
I omitted an 'id' field as that is automatically added (auto increment primary key) by sequelize.
README.md
Outdated
| ``` | ||
| docker run --rm --name=postgres -p 5432:5432 -e POSTGRES_PASSWORD=mysecretpassword -v `pwd`/examples:/tmp/examples -d postgres | ||
| docker exec postgres psql -U postgres -f /tmp/examples/create_tables.example.sql | ||
| docker exec postgres psql -U postgres -f /tmp/examples/create_example_datasource.sql |
There was a problem hiding this comment.
This fails because the table is not created before insert operation. @david-martin
There was a problem hiding this comment.
Good catch.
I'll update to start the server before creating the example datasource
There was a problem hiding this comment.
So, what I understand is, Sequlize should create the table. But it didn't do in my case. After I manually created the table and run the server, I saw log statements like "CREATE TABLE etc " in the logs.
Here are the log statements:
Executing (default): SELECT "id", "name", "type", "config", "createdAt", "updatedAt" FROM "DataSources" AS "DataSource";
Executing (default): SELECT t.typname enum_name, array_agg(e.enumlabel ORDER BY enumsortorder) enum_value FROM pg_type t JOIN pg_enum e ON t.oid = e.enumtypid JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace WHERE n.nspname = 'public' AND t.typname='enum_DataSources_type' GROUP BY 1
Executing (default): CREATE TYPE "public"."enum_DataSources_type" AS ENUM('InMemory', 'Postgres');
Executing (default): SELECT typname, typtype, oid, typarray FROM pg_type WHERE (typtype = 'b' AND typname IN ('hstore', 'geometry', 'geography')) OR (typtype = 'e')
Executing (default): CREATE TABLE IF NOT EXISTS "DataSources" ("id" SERIAL , "name" VARCHAR(255), "type" "public"."enum_DataSources_type", "config" JSON, "createdAt" TIMESTAMP WITH TIME ZONE NOT NULL, "updatedAt" TIMESTAMP WITH TIME ZONE NOT NULL, PRIMARY KEY ("id"));
Executing (default): SELECT i.relname AS name, ix.indisprimary AS primary, ix.indisunique AS unique, ix.indkey AS indkey, array_agg(a.attnum) as column_indexes, array_agg(a.attname) AS column_names, pg_get_indexdef(ix.indexrelid) AS definition FROM pg_class t, pg_class i, pg_index ix, pg_attribute a WHERE t.oid = ix.indrelid AND i.oid = ix.indexrelid AND a.attrelid = t.oid AND t.relkind = 'r' and t.relname = 'DataSources' GROUP BY i.relname, ix.indexrelid, ix.indisprimary, ix.indisunique, ix.indkey ORDER BY i.relname;
It first does a "SELECT" and in later stages it does "CREATE TABLE IF NOT EXISTS".
There was a problem hiding this comment.
Other than this, progress so far looks good.
|
@david-martin is this ready to go? |
|
@darahayes not quite. |
| @@ -0,0 +1,19 @@ | |||
| module.exports = (sequelize, DataTypes) => { | |||
There was a problem hiding this comment.
fyi @pb82 model for Resolver. See https://github.com/aerogear/data-sync-server/pull/9/files#diff-5709bb01e7a28a79644cde19374931d6R42 for example of what gets inserted
| @@ -0,0 +1,7 @@ | |||
| module.exports = (sequelize, DataTypes) => { | |||
There was a problem hiding this comment.
fyi @pb82 model for GraphQLSchema. See https://github.com/aerogear/data-sync-server/pull/9/files#diff-5709bb01e7a28a79644cde19374931d6R3 for example of what gets inserted
|
@darahayes @aliok I've rebased and pushed a significant update to this. |
The `sequelize` module is used for this.
A `DataSource`, `GraphQLSchema` & `Resolver` model is defined.
On startup, the first schema is retrieved from the database,
and all Resolvers & DataSources are read and passed into the schema parser
logic.
The local dev setup has changed due to the introduction of postgres.
See README for details.
The gist of it is:
```
npm run db:start
npm run db:seed # Creates sequelize model tables & seeds some example data
npm run dev
```
to stop:
```
npm run db:stop
```
The server is expected to fail starting at this time as the `InMemory`
data source is not implemented yet.
You should see an error like this on startup if the db is working OK.
```
Error: Unhandled data source type: InMemory
at _.forEach (/home/dmartin/work/data-sync-server/server/lib/dataSourceParser.js:16:13)
at arrayEach (/home/dmartin/work/data-sync-server/node_modules/lodash/lodash.js:516:11)
at Function.forEach (/home/dmartin/work/data-sync-server/node_modules/lodash/lodash.js:9342:14)
at module.exports (/home/dmartin/work/data-sync-server/server/lib/dataSourceParser.js:7:5)
at module.exports (/home/dmartin/work/data-sync-server/server/lib/schemaParser.js:7:23)
at module.exports (/home/dmartin/work/data-sync-server/server/server.js:32:14)
at <anonymous>
```
This error should not happen after the `InMemory` data source and
resolver mappings have been added to the server.
|
@darahayes I have rebased on top of your in-memory datasource branch. |
|
Closing this because changes were merged with #12 |
feat: Read Data Source, Schema & Resolver configuration from posgres
The
sequelizemodule is used for this.A
DataSource,GraphQLSchema&Resolvermodel is defined.On startup, the first schema is retrieved from the database,
and all Resolvers & DataSources are read and passed into the schema parser
logic.
The local dev setup has changed due to the introduction of postgres.
See README for details.
The gist of it is:
Access graphiql on http://localhost:8000/graphiql
to stop:
Other changes in this PR
field&namekey respectively on each item in the item array, rather than using the key of an objectTODO:
Separate follow up PR for: