Skip to content

Commit

Permalink
feat(graphql): added support for auto-exporting the schema (#347)
Browse files Browse the repository at this point in the history
* Added support for auto-exporting the schema

Supports .json and .graphql formats.
Tests are WIP.

* Made the requested changes

Also fixed the tests by manually defining the mocked method.

* Fixed CI errors, added a change I forgot to commit

* Update postgraphql.ts

* Update postgraphql.ts

* Rename pathgraphqlIntegrationSchemaExport-test.js to postgraphqlIntegrationSchemaExport-test.js

* Rename pathgraphqlIntegrationSchemaExport-test.js.snap to postgraphqlIntegrationSchemaExport-test.js.snap

* Update postgraphql.ts
  • Loading branch information
Michon van Dooren authored and calebmer committed Feb 11, 2017
1 parent 2f25ce8 commit f71bb7a
Show file tree
Hide file tree
Showing 8 changed files with 3,223 additions and 6 deletions.
2 changes: 2 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ The usage of the `postgraphql` binary is as follows. To pull up this documentati
-a, --classic-ids use classic global id field name. required to support Relay 1
-j, --dynamic-json enable dynamic JSON in GraphQL inputs and outputs. uses stringified JSON by default
-M, --disable-default-mutations disable default mutations, mutation will only be possible through Postgres functions
--export-schema-json [path] enables exporting the detected schema, in JSON format, to the given location. The directories must exist already, if the file exists it will be overwritten
--export-schema-graphql [path] enables exporting the detected schema, in GraphQL schema format, to the given location. The directories must exist already, if the file exists it will be overwritten
--show-error-stack [setting] show JavaScript error stacks in the GraphQL result errors
Get Started:
Expand Down
2 changes: 2 additions & 0 deletions docs/library.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ Arguments include:
- `watchPg`: When true, PostGraphQL will watch your database schemas and re-create the GraphQL API whenever your schema changes, notifying you as it does. This feature requires an event trigger to be added to the database by a superuser. When enabled PostGraphQL will try to add this trigger, if you did not connect as a superuser you will get a warning and the trigger won’t be added.
- `disableQueryLog`: Turns off GraphQL query logging. By default PostGraphQL will log every GraphQL query it processes along with some other information. Set this to `true` to disable that feature.
- `enableCors`: Enables some generous CORS settings for the GraphQL endpoint. There are some costs associated when enabling this, if at all possible try to put your API behind a reverse proxy.
- `exportJsonSchemaPath`: Enables saving the detected schema, in JSON format, to the given location. The directories must exist already, if the file exists it will be overwritten.
- `exportGqlSchemaPath`: Enables saving the detected schema, in GraphQL schema format, to the given location. The directories must exist already, if the file exists it will be overwritten.

[connect]: https://www.npmjs.com/connect
[express]: https://www.npmjs.com/express
Expand Down
11 changes: 11 additions & 0 deletions src/postgraphql/__tests__/__mocks__/fs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
const fs = require.requireActual('fs')

// Mock the writeFile for the export tests
const writeFile = jest.fn((path, contents, callback) => {
callback()
})

module.exports = {
...fs,
writeFile,
}
Loading

0 comments on commit f71bb7a

Please sign in to comment.