I want to generate something like this but I do not know which side to call the graphql scheme that generates postgraphile
app.use(postgraphile(pgConnectionString, pgSchemas, pgOptions));
app.get("/foo", (req, res) => {
// get a pg query / pg client from the postgraphile middleware
// make some query
const result = await pgQuery.query(
"SELECT ...."
);
// do something with result
});
Hi Carl,
I'm a little confused by your question, so there's two answers:
const pg = require('pg');
const postgraphile = require('postgraphile');
const pool = new pg.Pool({connectionString});
app.use(postgraphile(pool, pgSchemas, pgOptions));
app.get("/foo", (req, res) => {
const result = await pool.query(
"SELECT ...."
);
});
const pool = new pg.Pool({connectionString});
// ref: https://www.graphile.org/postgraphile/usage-schema/
export async function performQuery(
schema,
query,
variables,
jwtToken,
operationName
) {
return await withPostGraphileContext(
{
pgPool: pool,
jwtToken: jwtToken,
jwtSecret: "...",
pgDefaultRole: "..."
},
async context => {
// Execute your GraphQL query in this function with the provided
// `context` object, which should NOT be used outside of this
// function.
return await graphql(
schema, // The schema from `createPostGraphileSchema`
query,
null,
{ ...context }, // You can add more to context if you like
variables,
operationName
);
}
);
}
const middleware = postgraphile(pool, pgSchemas, pgOptions);
app.use(middleware);
app.get("/foo", (req, res) => {
const schema = await middleware.getGqlSchema();
const result = await performQuery(schema, '{__typename}');
});
[semi-automated message] Thanks for your question; hopefully we're well on the way to helping you solve your issue. This doesn't currently seem to be a bug in the library so I'm going to close the issue, but please feel free to keep requesting help below and if it does turn out to be a bug we can definitely re-open it š
@benjie what is "operationName"? It is not defined anywhere in the docs.
Hereās a couple places you can read about it:
Thank you, it has helped me a lot
Most helpful comment
Hereās a couple places you can read about it: