maticzav/graphql-shield

Error: Unknown object type "promise"

Opened this issue ยท 4 comments

Bug report

  • I have checked other issues to make sure this is not a duplicate.

Describe the bug

File uploads don't work and produce the error above.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

I use typegraphql with graphql-upload. Basically, I send an array of files like this in a mutation:

[
  {
     file: File
  }
]

then the error occurs.

Expected behavior

File uploads should succeed as they used to.

Actual behaviour

Error: Unknown object type "promise"

Additional context

    const schemaWithPermissions = applyMiddleware(schema, permissions);
    const server = new ApolloServer({
        schema: schemaWithPermissions,
        debug: true,
        uploads: false,
    });

Deleting this line
const schemaWithPermissions = applyMiddleware(schema, permissions);
and using
schema
without
applyMiddleware
uploads would work fine. But how should I enable permissions then?

NOTE:

I have commented out any mutations that do file uploads from Shield, until this issue gets fixed.

Hey @omar-dulaimi ๐Ÿ‘‹,

Thank you for opening an issue. We will get back to you as soon as we can. Have you seen our Open Collective page? Please consider contributing financially to our project. This will help us involve more contributors and get to issues like yours faster.

https://opencollective.com/graphql-shield

We offer priority support for all financial contributors. Don't forget to add priority label once you become one! ๐Ÿ˜„

We have the same error unfortunately when using graphql upload with the ShieldCache turned on strict, as it goes through all the args. Has there been found any solution yet?

I hit this same issue, but figured out the fix for it. The issue is caused by object-hash (used in the default hash implementation) not being able to handle promises.

Install object-hash in your project, then update your shieldOptions (passed into the shield function) to include the following:

const shieldOptions = {
    hashFunction: (arg: {
        parent: any;
        args: any;
    }): string => {
        try {
            return objectHash(arg)
        } catch (error) {
            if (error.message === "Unknown object type \"promise\"") {
                // ObjectHash can't handle promises so return a unique string as the hash instead
                return ulid()
            } else {
                throw error
            }
        }
    }
}
stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.