# gatsby-source-pg

> PostgreSQL source for Gatsby, powered by PostGraphile

Latest version **1.0.0-rc.0** (published 2021-11-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-source-pg
pnpm add gatsby-source-pg
yarn add gatsby-source-pg
bun add gatsby-source-pg
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0-rc.0 |
| Published | 2021-11-24 |
| First published | 2018-11-01 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 4 |
| Unpacked size | 11.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Benjie Gillam |
| Maintainers | benjie |
| Keywords | gatsby, gatsby-plugin, gatsby-source-plugin, source, plugin, pg, postgres, postgresql, sql, psql, pgsql, postgraphile, graphile, postgraphql |

## Links

- npm: https://www.npmjs.com/package/gatsby-source-pg
- Repository: https://github.com/graphile/gatsby-source-pg
- Homepage: https://github.com/graphile/gatsby-source-pg#readme
- Issues: https://github.com/graphile/gatsby-source-pg/issues
- npm.io page: https://npm.io/package/gatsby-source-pg

## Dependencies (4)

- [pg](https://npm.io/package/pg.md) ^8.7.1
- [apollo-link](https://npm.io/package/apollo-link.md) ^1.2.3
- [postgraphile](https://npm.io/package/postgraphile.md) ^4.12.5
- [gatsby-source-graphql](https://npm.io/package/gatsby-source-graphql.md) ^4.2.0

## Alternatives

- [apollo-link-http-common](https://npm.io/package/apollo-link-http-common.md) — 879.0K weekly downloads
- [react-relay](https://npm.io/package/react-relay.md) — 336.8K weekly downloads
- [relay-test-utils](https://npm.io/package/relay-test-utils.md) — 181.6K weekly downloads
- [@vendure/core](https://npm.io/package/@vendure/core.md) — 14.8K weekly downloads
- [@pnpm/deps.graph-sequencer](https://npm.io/package/@pnpm/deps.graph-sequencer.md) — 13.4K weekly downloads

## Recent versions

- 1.0.0-rc.0 (latest) — 2021-11-24
- 0.2.1 — 2020-08-04
- 0.2.0 — 2020-07-15
- 0.1.4 — 2019-05-30
- 0.1.3 — 2019-05-30
- 0.1.2 — 2018-11-13
- 0.1.1 — 2018-11-01
- 0.1.0 — 2018-11-01

## README

<p align="center">
  <a href="https://www.graphile.org/postgraphile/">
    <img alt="PostGraphile" src="https://www.graphile.org/images/postgraphile.optimized.svg" width="60" />
  </a>
  <img alt="Graphile Heart" src="https://www.graphile.org/images/graphile.optimized.svg" width="60" />
  <a href="https://www.gatsbyjs.org">
    <img alt="Gatsby" src="https://www.gatsbyjs.com/Gatsby-Monogram.svg" width="60" />
  </a>
</p>

<h1 align="center">
  gatsby-source-pg
</h1>

This module helps you pull your PostgreSQL database into Gatsby with minimal
effort.

<!-- SPONSORS_BEGIN -->

## Crowd-funded open-source software

To help us develop this software sustainably under the MIT license, we ask all
individuals and businesses that use it to help support its ongoing maintenance
and development via sponsorship.

### [Click here to find out more about sponsors and sponsorship.](https://www.graphile.org/sponsor/)

And please give some love to our featured sponsors 🤩:

<table><tr>
<td align="center"><a href="https://storyscript.com/?utm_source=postgraphile"><img src="https://graphile.org/images/sponsors/storyscript.png" width="90" height="90" alt="Story.ai" /><br />Story.ai</a> *</td>
<td align="center"><a href="https://surge.io/"><img src="https://graphile.org/images/sponsors/surge.png" width="90" height="90" alt="Surge" /><br />Surge</a> *</td>
<td align="center"><a href="http://chads.website"><img src="https://graphile.org/images/sponsors/chadf.png" width="90" height="90" alt="Chad Furman" /><br />Chad Furman</a> *</td>
<td align="center"><a href="https://postlight.com/?utm_source=graphile"><img src="https://graphile.org/images/sponsors/postlight.jpg" width="90" height="90" alt="Postlight" /><br />Postlight</a> *</td>
<td align="center"><a href="https://openbase.com/"><img src="https://graphile.org/images/sponsors/openbase.png" width="90" height="90" alt="Openbase" /><br />Openbase</a> *</td>
</tr></table>

<em>\* Sponsors the entire Graphile suite</em>

<!-- SPONSORS_END -->

## Usage

To install:

```
yarn add gatsby-source-pg
```

(or `npm install --save gatsby-source-pg`)

Then add the config to your `gatsby-config.js`:

```js
module.exports = {
  /* ... */
  plugins: [
    /* ... */

    {
      resolve: "gatsby-source-pg",
      options: {
        connectionString: "postgres://user:pass@host/dbname",
        schema: "public",
        refetchInterval: 60, // Refetch data every 60 seconds
      },
    },
  ],
};
```

The `connectionString` can be any valid PostgreSQL connection string, a full
connection string might look like:
`postgres://pg_user:pg_pass@pg_host:pg_port/pg_db?ssl=1`

## How to query

```graphql
{
  postgres {
    allPostsList {
      id
      authorId
      userByAuthorId {
        id
        username
      }
      title
    }
  }
}
```

## Example

For a working example of `gatsby-source-pg`, see
[gatsby-source-pg-example](https://github.com/graphile/gatsby-source-pg-example).

## Thanks

This plugin uses
[`gatsby-source-graphql`](https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-graphql#readme)
to merge the PostGraphile GraphQL schema into Gatsby's.

## Customising

This plugin is powered by PostGraphile, which is built on the highly flexible
and customisable Graphile Engine.

You can add to `options` most of the
[PostGraphile schema-only options](https://www.graphile.org/postgraphile/usage-schema/#api-createpostgraphileschemapgconfig-schemaname-options)

In addition, we accept the `typeName` and `fieldName` options from
`gatsby-source-graphql` which affect how the schema is namespaced, and the
`refetchInterval` setting to trigger refetching data every X seconds.

A common thing you might want to do is to shorten the names that PostGraphile
uses by default, you can do this using a plugin such as
`@graphile-contrib/pg-simplify-inflector`:

```js
// gatsby-config.js
module.exports = {
  /* ... */
  plugins: [
    /* ... */
    {
      resolve: "gatsby-source-pg",
      options: {
        connectionString: "postgres:///mydb",
        schema: "public",

        /* 👇 */
        appendPlugins: [require("@graphile-contrib/pg-simplify-inflector")],
        /* 👆 */
      },
    },
  ],
};
```

## Getting help

Pop into the Graphile Discord:
[http://discord.gg/graphile](http://discord.gg/graphile)

## Helpful links

- [Gatsby documentation](https://www.gatsbyjs.org/)
- [gatsby-source-pg-example](https://github.com/graphile/gatsby-source-pg-example/)
- [PostGraphile documentation](https://www.graphile.org/postgraphile/)

---
_Source: https://npm.io/package/gatsby-source-pg · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
