diff --git a/README.md b/README.md index ff42acc..43751d1 100644 --- a/README.md +++ b/README.md @@ -49,14 +49,13 @@ GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test; \q ``` -- create a database sources directory: `mkdir models` - ## Example [Vue](https://vuejs.org)/[PrimeVue](https://github.com/primefaces/primevue) front-end, using [Vite](https://github.com/vitejs/vite) and [Villus](https://github.com/logaretm/villus) - install Vue CLI: `yarn global add @vue/cli` - initialize: `yarn create @vitejs/app --template vue-ts vue-toh` - change to your project directory: `cd vue-toh` - you are advised to initialize version control to help track source code changes (e.g. `git init`) +- create a data sources directory: `mkdir models` - copy or merge the template's [package~.json](templates/primevue/package~.json) as your new ./package.json (or selectively copy/paste, especially the following scripts) - generate JSON schema files: `yarn gen-json` (alternatively, if not using PostGraphile, use apollo `yarn gen-json-a` or get-graphql-schema `yarn gen-json-g`) - generate GraphQL schema files: `yarn gen-gql` (alternatively, ditto the above) @@ -76,9 +75,10 @@ GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test; - install angular CLI globally (again, you may need elevated privileges) `yarn global add @angular/cli` - create your Angular project: `ng new ng-toh` - change to your project directory: `cd ng-toh` +- you are advised to initialize version control to help track source code changes (e.g. `git init`) +- create a data sources directory: `mkdir models` - if using yarn, configure: `ng config cli.packageManager yarn` -- You are advised to initialize version control to help track source code changes (e.g. `git init`) -- generate JSON and GraphQL schema files: `yarn postgraphile -c postgres://test:testpass@/toh -s public -X --export-schema-json ../models/schema.json --export-schema-graphql ../models/schema.gql` +- generate JSON and GraphQL schema files: `yarn postgraphile -c postgres://test:testpass@/toh -s public -X --export-schema-json models/schema.json --export-schema-graphql models/schema.gql` - run the GraphQL server (in the background): `yarn postgraphile -c postgres://test:testpass@/toh -s public -o &` - optionally you can click on the link to GraphiQL generated by the above, and explore the server by entering queries such as: `{allHeroes{nodes{nodeId,id,name}}}` - add Angular and Material dependencies: `yarn add rxjs rxjs-compat @angular/material @angular/cdk graphql graphql-tag apollo-client apollo-angular apollo-link apollo-angular-link-http apollo-cache-inmemory` @@ -100,7 +100,8 @@ GRANT ALL PRIVILEGES ON ALL SEQUENCES IN SCHEMA public TO test; - create your Vue project: `vue create vuetify-toh`, and select manual with babel, pwa, router eslint, (or select the equivalent using `vue ui`), but not with TypeScript currently, due to Vue 3 beta limitations - change to your project directory: `cd vuetify-toh` - You are advised to initialize version control to help track source code changes (e.g. `git init`) -- generate JSON and GraphQL schema files: `yarn postgraphile -c postgres://test:testpass@/toh -s public -X --export-schema-json ../models/schema.json --export-schema-graphql ../models/schema.gql` +- create a data sources directory: `mkdir models` +- generate JSON and GraphQL schema files: `yarn postgraphile -c postgres://test:testpass@/toh -s public -X --export-schema-json models/schema.json --export-schema-graphql models/schema.gql` - run the GraphQL server (in the background): `yarn postgraphile -c postgres://test:testpass@/toh -s public -o &` - optionally you can click on the link to GraphiQL generated by the above, and explore the server by entering queries such as: `{allHeroes{nodes{nodeId,id,name}}}` - install Vue v3 beta plugin: `vue add vue-next` @@ -121,9 +122,9 @@ The `opinionate meta` sub-command can be used in a number of ways to help manage ### Example usage of the opinionate meta command -You can generate an overlay file with default metadata using `opinionate meta --overlay-out ../models/overlayOut.json`, similarly you can generate a SQL script to create table and field comments containing metadata using `opinionate meta --comments-out ../models/comments.pgsql`. These assume there is a `../models/schema.json` file describing the GraphQL schema (as produced by PostGraphile), otherwise you should use the `--schema` option to specify an alternative location. +You can generate an overlay file with default metadata using `opinionate meta --overlay-out models/overlayOut.json`, similarly you can generate a SQL script to create table and field comments containing metadata using `opinionate meta --comments-out models/comments.pgsql`. These assume there is a `models/schema.json` file describing the GraphQL schema (as produced by PostGraphile), otherwise you should use the `--schema` option to specify an alternative location. -You can define your own metadata structure (e.g. to extend the metadata available to the code generating templates), and this can include code to specify default values. This can simplify the templates, and has the added benefit of allowing some of those settings to be further customized (e.g. in the overlay file) before the final code is generated. Remember though, to add the metadata parameter to both commands, e.g. `opinionate meta --default-meta ../models/customMeta` and `opinionate gen --default-meta ../models/customMeta`. Note that the metadata file is NOT in standard JSON format. +You can define your own metadata structure (e.g. to extend the metadata available to the code generating templates), and this can include code to specify default values. This can simplify the templates, and has the added benefit of allowing some of those settings to be further customized (e.g. in the overlay file) before the final code is generated. Remember though, to add the metadata parameter to both commands, e.g. `opinionate meta --default-meta models/customMeta` and `opinionate gen --default-meta models/customMeta`. Note that the metadata file is NOT in standard JSON format. Note that you can use `opinionate meta -h` for more help, especially on defaults and options for the locations of files to read and write. diff --git a/codegen.yml b/codegen.yml index 5d4bd35..7b541d3 100644 --- a/codegen.yml +++ b/codegen.yml @@ -1,6 +1,6 @@ overwrite: true -schema: "../models/schema.gql" +schema: "models/schema.gql" generates: - ../models/types.d.ts: + models/types.d.ts: plugins: - "typescript" diff --git a/dist/bin/opinionate-gen.js b/dist/bin/opinionate-gen.js index 251b238..e279d25 100644 --- a/dist/bin/opinionate-gen.js +++ b/dist/bin/opinionate-gen.js @@ -13,7 +13,7 @@ class AppGen { .version(this.package.version) .option("-t, --template