graphile / crystal

🔮 Graphile's Crystal Monorepo; home to Grafast, PostGraphile, pg-introspection, pg-sql2 and much more!
https://graphile.org/
Other
12.62k stars 571 forks source link

Schema only usage without configuration #565

Closed ansarizafar closed 1 year ago

ansarizafar commented 7 years ago

Thanks for amazing work. I am using Postgraphile as a library and I also want to execute a query on the server without having to go through HTTP. My question is why it is to provide a pool and other configuration, why not Postgraphile just expose excuteQuery/excuteMutation functions as all other configurations are already set.

benjie commented 7 years ago

We provide the tooling (such as withPostGraphQLContext and createPostGraphQLSchema) so that you may execute queries using "graphql" itself. By doing this we allow you to make optimisations, should you so desire, e.g. Skipping the verification phase and jumping straight to execute. And of course running queries on your schema with "graphql" function is the standard way throughout the GraphQL ecosystem.

Further reading that may interest you: https://github.com/postgraphql/postgraphql/pull/209

ansarizafar commented 7 years ago

Thanks for the info but this means graphql schema / connection pool will be created twice. It would be great If Postgraphile can at least expose schema/connection pool if not higher order query execute function.

benjie commented 7 years ago

You can pass in a shared pool to both so the pool needn't be created twice, I don't think the schema being generated twice is a huge deal - it's only done at server startup and it doesn't consume much memory but I'm open to a PR that would allow passing the schema in to the postgraphql middleware function if it's simple enough.

ansarizafar commented 7 years ago

Postgrapgile has made a developer's life very easy. Ideally, I would still request a query execute function exported from Postgraphile.

benjie commented 6 years ago

The current status on this is that you can copy the performQuery function from the docs and use that: https://www.graphile.org/postgraphile/usage-schema/

I'm going to leave this open though, because we can still do better.