Skip to content
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

Error: Unknown object type "promise" #1221

Open
1 task done
omar-dulaimi opened this issue Aug 1, 2021 · 4 comments
Open
1 task done

Error: Unknown object type "promise" #1221

omar-dulaimi opened this issue Aug 1, 2021 · 4 comments

Comments

@omar-dulaimi
Copy link

omar-dulaimi commented Aug 1, 2021

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.

@open-collective-bot
Copy link

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! 😄

@chrissisura
Copy link

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?

@BenDLH
Copy link

BenDLH commented Jan 28, 2022

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
Copy link

stale bot commented Apr 16, 2022

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.

@stale stale bot added the stale label Apr 16, 2022
@labelsync-manager labelsync-manager bot removed the stale label Apr 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants