Open PeteSolid opened 3 years ago
Unfortunately there are not! It would be great to create such content - I'll leave this open as a Good First Issue.
I can leave a small description here right away, in a few steps:
fastify-postgres
:
const fastifyPostgres = require('fastify-postgres').default;
app.register(fastifyPostgres, { connectionString: process.env.DATABASE_URL });
2. Add `mercurius` and a schema:
```javascript
const schema = `
schema {
query: Query
}
type Query {
foo(id: ID!): String
}
`;
const mercurius = require('mercurius').default;
app.register(mercurius, {
schema,
resolvers: {
Query: {
foo: fooResolver
}
}
});
app
on the GraphQL context. And on the Fastify app instance you can then access fastify-postgres
as app.pg
and thus complete the above setup by eg. doing a app.pg.query()
:const fooResolver = async (parent, args, context, info) => {
const { app } = context;
const { id } = args;
const result = await app.pg.query('SELECT bar FROM foo WHERE foo.id = $1', [id]);
return result.rows[0] && result.rows[0].bar;
};
Would you be interested in me wrapping that up as a PR @mcollina?
Hi, I am a beginner and it is not quite clear to me how to combine it with a Database like PostgresQL to read and write? Are there docs for that? Many thanks!