-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolver incompatibility with Postgraphile top-level Connections #369
Comments
Hello, having a same problem, but not sure if this a middleware issue or postgraphile |
Hi all! 👋 It would be great if you could compose a small reproduction CodeSandbox or something similar? I think this could be an inherent issue with how |
This was first CodeSandbox , spend almost two hours, looks like that I was able to recreate issue. |
I'm also having this issue. Has a workaround or any other insight been found? |
It seems that the problem may be in part coming from I created a simple plugin to test this: const {makeExtendSchemaPlugin, makePluginByCombiningPlugins, gql} = require('graphile-utils');
const {addResolversToSchema} = require('@graphql-tools/schema');
const testPlugin = (builder) => {
builder.hook('finalize', schema => addResolversToSchema({schema, resolvers: {Mutation: {test: () => true}}}));
};
module.exports = makePluginByCombiningPlugins(
makeExtendSchemaPlugin({typeDefs: gql`extend type Mutation { test: Boolean }`}),
testPlugin,
); And it results in the same error. |
I lost hope to get any attention to this, so instead using this library went to solution similar to this |
I found a workaround for this (somewhat by accident). If you add a step to first wrap the schema using @graphql-tools/wrap, you can apply the middleware as usual and graphql-shield works as expected. I've tested this with postgraphile running on both Apollo Server (schema only) and Express (as library) Example plugin: const { makeProcessSchemaPlugin } = require("graphile-utils");
const permissions = require('../auth/permissions')
const { wrapSchema } = require('@graphql-tools/wrap')
const { applyMiddleware } = require('graphql-middleware')
module.exports = makeProcessSchemaPlugin(schema => {
const wrappedSchema = wrapSchema({
schema: schema,
transforms: []
});
return applyMiddleware(wrappedSchema, permissions);
}); |
@pschmidtudig This actually works! |
Hi!
I am trying to use the awesome
graphql-shield
library withPostgraphile
. In order to do so, I must usegraphql-middleware
. After thoroughly narrowing in on the problem, I've arrived at the following base case:Let's say we have an
item
table in Postgres. Postgraphile generates aschema
automatically, withAllItems
anditemById
fields. We send the schema throughwhich is then returned to Postgraphile plugin system, which becomes the finalized schema.
I then execute a query like so:
The
itemByID
will execute properly and return the right data, butallItems
does not:It seems to be a problem with Connection type fields on the top level, which include
nodes
andedges
arrays of objects (you can see nodes being queried in the allItems field). I did some experimentation, and it can even handle relational nested Connections insideitemByID
if I declared them (let's sayrelatedItems
for example). But it appears to be improperly handling and traversing Connections specifically when they're at the top level of the query, likeallItems
.To simplify the Connections format, I even tried Postgraphile with the simple connections option instead of Relay-format connections. That gets rid of the
nodes
andedges
array fields on Connections and so just returns an array immediately fromallItems
. But the resolving/traversal still remained a problem: They were now actually properly returning an array of objects but there were values ofnull
for every object field in the object array, meaning the leaf scalar values didn't appear to be resolved properly. So exchanging one problem for another in resolution.After looking closely, the problem seems to lie somewhere in the
applicator
'sgenerateResolverFromSchemaAndMiddleware
properly traversing the resolvers or when running theaddResolversToSchema
that generates a new schema for output.It just seems like in the current state, that
graphql-middleware
is not compatible with Postgraphile's generated schemas as inputs.Any pointers, clues, or solutions you can think of? We are so excited to use the graphql-shield library, but this schema translation step seems to be broken.
The text was updated successfully, but these errors were encountered: