Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PostGraphile plugins #586

Merged
merged 2 commits into from
Jun 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/check-configuration.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Check Configurationn
name: Check Configuration
on:
pull_request:
branches:
Expand Down
1 change: 1 addition & 0 deletions examples/grpc-example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"@graphql-mesh/cli": "0.2.10",
"@graphql-mesh/grpc": "0.2.10",
"@graphql-mesh/transform-naming-convention": "0.2.10",
"@grpc/proto-loader": "0.5.4",
"google-protobuf": "3.12.2",
"graphql": "15.1.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/handlers/postgraphile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
},
"dependencies": {
"@graphql-mesh/types": "0.2.10",
"@graphql-mesh/utils": "0.2.10",
"fs-extra": "9.0.1",
"postgraphile-core": "4.7.0",
"postgraphile": "4.7.0",
"@graphile/federation": "0.0.3",
"pg": "8.2.1"
},
"publishConfig": {
Expand Down
7 changes: 1 addition & 6 deletions packages/handlers/postgraphile/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { Pool } from 'pg';
import { join } from 'path';
import { tmpdir } from 'os';
import { readJSON, unlink } from 'fs-extra';
import FederationPlugin from '@graphile/federation';

const handler: MeshHandlerLibrary<YamlConfig.PostGraphileHandler> = {
async getMeshSource({ name, cache, config, hooks }) {
Expand All @@ -28,11 +27,7 @@ const handler: MeshHandlerLibrary<YamlConfig.PostGraphileHandler> = {

let writeCache: () => Promise<void>;

const appendPlugins: Plugin[] = [];

if (config.federation) {
appendPlugins.push(FederationPlugin);
}
const appendPlugins = await Promise.all<Plugin>(config.plugins?.map(pluginName => import(pluginName)));

const builder = await getPostGraphileBuilder(pgPool, config.schemaName || 'public', {
dynamicJson: true,
Expand Down
4 changes: 2 additions & 2 deletions packages/handlers/postgraphile/yaml-config.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ type PostGraphileHandler @md {
"""
cacheIntrospection: Boolean
"""
Enable Apollo Federation support (enable only if your merger is set as `federation`)
Extra Postgraphile Plugins
"""
federation: Boolean
plugins: [String]
}

type PostGraphilePool {
Expand Down
12 changes: 8 additions & 4 deletions packages/types/src/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -894,9 +894,13 @@
"type": "boolean",
"description": "Cache Introspection"
},
"federation": {
"type": "boolean",
"description": "Enable Apollo Federation support (enable only if your merger is set as `federation`)"
"plugins": {
"type": "array",
"items": {
"type": "string"
},
"additionalItems": false,
"description": "Extra Postgraphile Plugins"
}
},
"required": [
Expand Down Expand Up @@ -1197,7 +1201,7 @@
},
"cacheKey": {
"type": "string",
"description": "Cache key to use to store your resolvers responses.\nThe defualt is: {typeName}-{fieldName}-{argsHash}\n\nAvailable variables:\n- {args.argName} - use resolver argument\n- {typeName} - use name of the type\n- {fieldName} - use name of the field\n- {argsHash} - a hash based on the 'args' object\n- {info} - the GraphQLResolveInfo of the resolver\n\nAvailable interpolations:\n- {format|date} - returns the current date with a specific format"
"description": "Cache key to use to store your resolvers responses.\nThe defualt is: {typeName}-{fieldName}-{argsHash}-{fieldNamesHash}\n\nAvailable variables:\n- {args.argName} - use resolver argument\n- {typeName} - use name of the type\n- {fieldName} - use name of the field\n- {argsHash} - a hash based on the 'args' object\n- {fieldNamesHash} - a hash based on the field names selected by the client\n- {info} - the GraphQLResolveInfo of the resolver\n\nAvailable interpolations:\n- {format|date} - returns the current date with a specific format"
},
"invalidate": {
"$ref": "#/definitions/CacheInvalidateConfig",
Expand Down
4 changes: 2 additions & 2 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,8 @@ type PostGraphileHandler @md {
pool: PostGraphilePool
"""Cache Introspection"""
cacheIntrospection: Boolean
"""Enable Apollo Federation support (enable only if your merger is set as `federation`)"""
federation: Boolean
"""Extra Postgraphile Plugins"""
plugins: [String]
}
type PostGraphilePool {
user: String
Expand Down
22 changes: 22 additions & 0 deletions website/docs/handlers/postgraphile.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ sources:
> You can check out our example that uses schema stitching with a PostgreSQL datasource.
[Click here to open the example on GitHub](https://github.com/Urigo/graphql-mesh/tree/master/examples/postgres-geodb)

### External Plugins (e.g. Federation)
You can add PostGraphile plugins such as FederationPlugin and ConnectionFilterPlugin. You can install it using npm or yarn like below;
```sh
yarn add @graphile/federation
```

and add those in your configuration file;

```yml
sources:
- name: MyDb
handler:
postgraphile:
connectionString: postgres://postgres:password@localhost/postgres
plugins:
- "@graphile/federation"
```

> Use `FederationPlugin` only if you are using `federation` as merger as in [Federation Recipe](/recipes/federation)

[Learn more about PostGraphile plugins](https://www.graphile.org/postgraphile/extending/)

## Config API Reference

{@import ../generated-markdown/PostGraphileHandler.generated.md}
73 changes: 3 additions & 70 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
core-js "^3.4.0"
lodash.xorby "^4.7.0"

"@apollo/federation@^0.6.8":
version "0.6.10"
resolved "https://registry.yarnpkg.com/@apollo/federation/-/federation-0.6.10.tgz#e74a7f45adaa06410736d52b2e8a8a8b4fc40720"
integrity sha512-KdEg2N/T9OEV9wYtrhkNTxnoemap3gCKaJzxogf6a14cVHk9/HMrv8hDUcl3Uu3fzUq591JVBfBcLJntD+2FkQ==
dependencies:
apollo-env "^0.5.1"
apollo-graphql "^0.3.3"
apollo-server-env "2.4.0"

"@apollo/gateway@0.16.5":
version "0.16.5"
resolved "https://registry.yarnpkg.com/@apollo/gateway/-/gateway-0.16.5.tgz#ccd30fef677ed2edd1fe542f3d053393b2ad835d"
Expand Down Expand Up @@ -1458,16 +1449,6 @@
url "^0.11.0"
webpack-sources "^1.4.3"

"@graphile/federation@0.0.3":
version "0.0.3"
resolved "https://registry.yarnpkg.com/@graphile/federation/-/federation-0.0.3.tgz#c2b2b62fd1b7432dd5696068572f9a69ab9b6403"
integrity sha512-Xh2fU4T3aCLovoRy2LFlhr7p9ftH6x3mNswMuR33lvmfCT8UngYiaDKxFKp9Ovtm+RvExp4r3KIt6NPDvicptg==
dependencies:
"@apollo/federation" "^0.6.8"
"@types/graphql" "^14.0.0"
graphile-utils "^4.4.2"
graphql-tools "^4.0.5"

"@graphile/lru@4.5.0":
version "4.5.0"
resolved "https://registry.yarnpkg.com/@graphile/lru/-/lru-4.5.0.tgz#e8fe036d322dfe1715675aab171979981e28ac9e"
Expand All @@ -1483,22 +1464,6 @@
"@graphql-tools/utils" "^6.0.0"
tslib "~2.0.0"

"@graphql-codegen/plugin-helpers@1.15.2":
version "1.15.2"
resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-1.15.2.tgz#102d93094858f10537911bd3c788f730f0f74974"
integrity sha512-5bvgNrLEtXj0tmyGj0I2JfxbjL1wkOKcjTubGDFfmbOR4aGOCCJPCgTtoCyCX8qbazW4LOsVInWieKEoEGUzYg==
dependencies:
"@graphql-tools/utils" "^6.0.0"
camel-case "4.1.1"
common-tags "1.8.0"
constant-case "3.0.3"
import-from "3.0.0"
lower-case "2.0.1"
param-case "3.0.3"
pascal-case "3.1.1"
tslib "~2.0.0"
upper-case "2.0.1"

"@graphql-codegen/plugin-helpers@1.15.3":
version "1.15.3"
resolved "https://registry.yarnpkg.com/@graphql-codegen/plugin-helpers/-/plugin-helpers-1.15.3.tgz#0e2cf89b8aec3ee7a737157ac1b08fbfce626e07"
Expand Down Expand Up @@ -2552,13 +2517,6 @@
"@types/koa" "*"
graphql "^14.5.3"

"@types/graphql@^14.0.0":
version "14.5.0"
resolved "https://registry.yarnpkg.com/@types/graphql/-/graphql-14.5.0.tgz#a545fb3bc8013a3547cf2f07f5e13a33642b75d6"
integrity sha512-MOkzsEp1Jk5bXuAsHsUi6BVv0zCO+7/2PTiZMXWDSsMXvNU6w/PLMQT2vHn8hy2i0JqojPz1Sz6rsFjHtsU0lA==
dependencies:
graphql "*"

"@types/html-minifier-terser@^5.0.0":
version "5.1.0"
resolved "https://registry.yarnpkg.com/@types/html-minifier-terser/-/html-minifier-terser-5.1.0.tgz#551a4589b6ee2cc9c1dff08056128aec29b94880"
Expand Down Expand Up @@ -3532,15 +3490,6 @@ apollo-engine-reporting@^2.0.0:
async-retry "^1.2.1"
uuid "^8.0.0"

apollo-env@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/apollo-env/-/apollo-env-0.5.1.tgz#b9b0195c16feadf0fe9fd5563edb0b9b7d9e97d3"
integrity sha512-fndST2xojgSdH02k5hxk1cbqA9Ti8RX4YzzBoAB4oIe1Puhq7+YlhXGXfXB5Y4XN0al8dLg+5nAkyjNAR2qZTw==
dependencies:
core-js "^3.0.1"
node-fetch "^2.2.0"
sha.js "^2.4.11"

apollo-env@^0.6.1, apollo-env@^0.6.5:
version "0.6.5"
resolved "https://registry.yarnpkg.com/apollo-env/-/apollo-env-0.6.5.tgz#5a36e699d39e2356381f7203493187260fded9f3"
Expand All @@ -3559,14 +3508,6 @@ apollo-errors@^1.9.0:
assert "^1.4.1"
extendable-error "^0.1.5"

apollo-graphql@^0.3.3:
version "0.3.7"
resolved "https://registry.yarnpkg.com/apollo-graphql/-/apollo-graphql-0.3.7.tgz#533232ed48b0b6dbcf5635f65e66cf8677a5b768"
integrity sha512-ghW16xx9tRcyL38Pw6G5OidMnYn+CNUGZWmvqQgEO2nRy4T0ONPZZBOvGrIMtJQ70oEykNMKGm0zm6PdHdxd8Q==
dependencies:
apollo-env "^0.6.1"
lodash.sortby "^4.7.0"

apollo-graphql@^0.4.0:
version "0.4.4"
resolved "https://registry.yarnpkg.com/apollo-graphql/-/apollo-graphql-0.4.4.tgz#25f456b28a4419bb6a42071f8a56e19e15bb80be"
Expand Down Expand Up @@ -3657,14 +3598,6 @@ apollo-server-core@^2.14.3:
subscriptions-transport-ws "^0.9.11"
ws "^6.0.0"

apollo-server-env@2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/apollo-server-env/-/apollo-server-env-2.4.0.tgz#6611556c6b627a1636eed31317d4f7ea30705872"
integrity sha512-7ispR68lv92viFeu5zsRUVGP+oxsVI3WeeBNniM22Cx619maBUwcYTIC3+Y3LpXILhLZCzA1FASZwusgSlyN9w==
dependencies:
node-fetch "^2.1.2"
util.promisify "^1.0.0"

apollo-server-env@^2.4.4:
version "2.4.4"
resolved "https://registry.yarnpkg.com/apollo-server-env/-/apollo-server-env-2.4.4.tgz#12d2d0896dcb184478cba066c7a683ab18689ca1"
Expand Down Expand Up @@ -7946,7 +7879,7 @@ graphile-build@4.7.0:
pluralize "^7.0.0"
semver "^6.0.0"

graphile-utils@^4.4.2, graphile-utils@^4.7.0:
graphile-utils@^4.7.0:
version "4.7.0"
resolved "https://registry.yarnpkg.com/graphile-utils/-/graphile-utils-4.7.0.tgz#f1b4b77a84741bbcbb69c1f3d2c009bd9c7336f6"
integrity sha512-q147Dn4BV7AfujMCSoWf48dqUJUdr2ReLCY9aal7+m2ZthxMlnqhqrbGFvsDz+Vdx/KaZoDbNqEgAmfhE9R0mA==
Expand Down Expand Up @@ -8092,7 +8025,7 @@ graphql-tools-fork@9.0.1:
node-fetch "^2.6.0"
uuid "^7.0.2"

graphql-tools@^4.0.0, graphql-tools@^4.0.4, graphql-tools@^4.0.5:
graphql-tools@^4.0.0, graphql-tools@^4.0.4:
version "4.0.8"
resolved "https://registry.yarnpkg.com/graphql-tools/-/graphql-tools-4.0.8.tgz#e7fb9f0d43408fb0878ba66b522ce871bafe9d30"
integrity sha512-MW+ioleBrwhRjalKjYaLQbr+920pHBgy9vM/n47sswtns8+96sRn5M/G+J1eu7IMeKWiN/9p6tmwCHU7552VJg==
Expand Down Expand Up @@ -8134,7 +8067,7 @@ graphql-upload@^8.0.2:
http-errors "^1.7.3"
object-path "^0.11.4"

graphql@*, graphql@15.1.0, "graphql@>=0.9 <0.14 || ^14.0.2", "graphql@^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.2", graphql@^14.2.1, graphql@^14.5.3:
graphql@15.1.0, "graphql@>=0.9 <0.14 || ^14.0.2", "graphql@^0.6.0 || ^0.7.0 || ^0.8.0-b || ^0.9.0 || ^0.10.0 || ^0.11.0 || ^0.12.0 || ^0.13.0 || ^14.0.2", graphql@^14.2.1, graphql@^14.5.3:
version "15.1.0"
resolved "https://registry.yarnpkg.com/graphql/-/graphql-15.1.0.tgz#b93e28de805294ec08e1630d901db550cb8960a1"
integrity sha512-0TVyfOlCGhv/DBczQkJmwXOK6fjWkjzY3Pt7wY8i0gcYXq8aogG3weCsg48m72lywKSeOqedEHvVPOvZvSD51Q==
Expand Down