{"id":20525792,"url":"https://github.com/drewwiens/postgraphile-node","last_synced_at":"2026-04-07T22:31:50.047Z","repository":{"id":57328730,"uuid":"318344794","full_name":"drewwiens/postgraphile-node","owner":"drewwiens","description":"Query Postgraphile from the same Node app","archived":false,"fork":false,"pushed_at":"2021-02-25T20:07:59.000Z","size":5,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-02T15:41:02.403Z","etag":null,"topics":["apollo-server","database","graphile","graphql","graphql-request","javascript-library","node","node-js","nodejs","postgraphile","postgres","postgres-database","postgres-db","postgresql","postgresql-database","typescript","typescript-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drewwiens.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-12-03T23:14:55.000Z","updated_at":"2021-02-25T20:08:01.000Z","dependencies_parsed_at":"2022-09-08T14:52:29.906Z","dependency_job_id":null,"html_url":"https://github.com/drewwiens/postgraphile-node","commit_stats":null,"previous_names":["adwiens/postgraphile-node"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/drewwiens/postgraphile-node","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewwiens%2Fpostgraphile-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewwiens%2Fpostgraphile-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewwiens%2Fpostgraphile-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewwiens%2Fpostgraphile-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drewwiens","download_url":"https://codeload.github.com/drewwiens/postgraphile-node/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drewwiens%2Fpostgraphile-node/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31532217,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-07T16:28:08.000Z","status":"ssl_error","status_checked_at":"2026-04-07T16:28:06.951Z","response_time":105,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["apollo-server","database","graphile","graphql","graphql-request","javascript-library","node","node-js","nodejs","postgraphile","postgres","postgres-database","postgres-db","postgresql","postgresql-database","typescript","typescript-library"],"created_at":"2024-11-15T23:09:33.655Z","updated_at":"2026-04-07T22:31:50.024Z","avatar_url":"https://github.com/drewwiens.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# postgraphile-node\n\nQuery Postgraphile from the same Node app.\n\n## Usage\n\n```js\nimport { PostgraphileClient } from 'postgraphile-node';\nimport postgraphile from 'postgraphile';\nimport { gql } from 'graphql-request'\n\nconst middleware = postgraphile('postgres://user:pass@your-host/db-name');\nconst client = new PostgraphileClient(middleware);\n\nconst query = gql`\n  {\n    Movie(title: \"Inception\") {\n      releaseDate\n      actors {\n        name\n      }\n    }\n  }\n`;\n\nclient.request(query).then((data) =\u003e console.log(data));\n```\n\n## What it does\n\nThis library provides `PostgraphileClient`. It's a drop-in replacement for the GraphQLClient class in [graphql-request](https://www.npmjs.com/package/graphql-request) that allows you to send GQL queries directly to Postgraphile without any network requests.\n\n## Why would anyone want to do this\n\nPostgraphile is great for auto-generating a public GraphQL API, but there isn't a good way to access the database internally from the same Node server. You need to do this often when customizing the API, for example with custom plugins.\n\nPostgraphile provides its internal Postgres client to custom plugins, but accessing the database this way requires writing and maintaining blocks of SQL, which is best avoided.\n\nYou could make HTTP requests to Postgraphile's `/graphql` endpoint, but that would have the app make HTTP requests to itself. It can work, but it's a bit hacky.\n\nAnother option is to add another database connector like TypeORM, Sequelize, or Prisma to access the database, but then you are having to adopt yet another technology in addition to Postgraphile, which isn't DRY.\n\n## Detecting whether a query came from PostgraphileClient\n\n`PostgraphileClient` adds a boolean property `isInternalQuery` to the mocked `req` object that can be used to detect whether the query came from this library.\n\nThe following example shows how to use `isInternalQuery` with `graphql-shield` to break the infinite loop caused by querying Postgraphile from its own schema:\n\n```js\nimport postgraphile from 'postgraphile';\nimport { rule } from 'graphql-shield';\n\nconst middleware = postgraphile('postgres://user:pass@your-host/db-name', {\n  async additionalGraphQLContextFromRequest(req: any) {\n    return {\n      isInternalQuery: req.isInternalQuery || false\n    };\n  }\n});\n\nconst yourRule = rule({ cache: 'no_cache' })(\n  async (parent, args, ctx, info) =\u003e {\n    // ctx.isInternalQuery is true here if the query was from PostgraphileClient.\n  }\n);\n```\n\nThis approach can be used anywhere the GraphQL context object is available, such as in Postgraphile plugins.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewwiens%2Fpostgraphile-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrewwiens%2Fpostgraphile-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrewwiens%2Fpostgraphile-node/lists"}