graphql-compose / graphql-compose-mongoose

Mongoose model converter to GraphQL types with resolvers for graphql-compose https://github.com/nodkz/graphql-compose
MIT License
708 stars 94 forks source link

Second arg for Resolver xxx should be instance of ObjectTypeComposer #395

Open michaelwclark opened 2 years ago

michaelwclark commented 2 years ago

This one was obscure and hard to find.

Locally everything worked great, just like our prior existing products that had used this amazing library. Production in our new AWS environment threw the error in the title or similar depending on how we setup the schemas.

Finally after over a week of trying dozens of various alternative setups (all worked locally, failed in cloud environment - aws lambdas) I read the source code. I found the checks are done using

if (!tc \|\| tc.constructor.name !== 'ObjectTypeComposer') {

The problem is minified code without source-maps will change the constructor name. At least that's my working theory.

This method of checking the type of tc is prone to issues with minification. I think the source maps will fix it, but i'm not 100%. Worst case scenario I'll disable minification for now.

I hope this helps someone else struggling with this.

Once we get this project launched I may open a PR with a fix for this, but for now wanted to get it out there.

michaelwclark commented 2 years ago

Update. I managed to get this thing humming along in production. The issue was the uglification/minification that serverless-bundle does with serverless-webpack under the covers.

I attempted turning off minification, turning on source maps and various other combinations. None of them worked, so finally I moved several libraries to externals and it worked. Here is an excerpt from my serverless.yml in case anyone stumbles across this and is in the same pickle.

custom:
  bundle:
    linting: false
    externals:
      - graphql-compose-mongoose
      - mongoose
      - graphql-compose
      - graphql
  importApiGateway:
    name: xxx-service-${self:custom.stage}
  stage: ${opt:stage, 'alpha'}
  apiKeys:
    - name: ${self:service}-api-key
      value: ${env:API_KEY_${self:custom.stage}}