maticzav / graphql-middleware

Split up your GraphQL resolvers in middleware functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

3.0.2 throws TypeError: definitions.trim is not a function

gihrig opened this issue · comments

In prisma/photon TS example graphql-auth a comment references non-working graphql-shield in issue #361

The problem appears when graphql-middleware 3.0.2 is installed as a dependency of graphql-yoga.

Resolving graphql-middleware to 3.0.1 eliminates the error and graphql-shield works as expected.
Only works with yarn, npm install does not process resolutions

"resolutions": {
  "graphql-middleware": "3.0.1"
}
$ ts-node-dev --no-notify --respawn --transpileOnly ./src
Using ts-node version 8.3.0, typescript version 3.5.3
TypeError: definitions.trim is not a function
    at parseFragmentToInlineFragment (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/fragments.ts:85:21)
    at /Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/fragments.ts:41:24
    at Array.map (<anonymous>)
    at Object.extractFragmentReplacements (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/fragments.ts:40:6)
    at addMiddlewareToSchema (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/middleware.ts:40:32)
    at normalisedMiddlewares.reduceRight.schema (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/middleware.ts:86:13)
    at Array.reduceRight (<anonymous>)
    at applyMiddlewareWithOptions (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/middleware.ts:78:77)
    at applyMiddleware (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-middleware/src/middleware.ts:129:36)
    at new GraphQLServer (/Users/glen/Documents/JavaScript/Research/hello-photon-graphql-auth/node_modules/graphql-yoga/src/index.ts:137:13)
[ERROR] 18:09:25 TypeError: definitions.trim is not a function

@maticzav please merge 6e1b5c7 into master so the fix can propagate to graphql-yoga.

Then this issue can be closed as well as graphql-shield #361

@maticzav I have confirmed that 4.0.0 resolves the issue.

Thank you! :-)

getting this on 4.0.1