TypeError: field.type.inspect is not a function
ITfromHell opened this issue · 9 comments
Hi guys,
I´m trying to test your pretty cool graphql2rest. In my environment I got always same error:
error: [gqlgenerator] Encountered error trying to generate GQL files for GraphQL operations. Aborting
error: TypeError: field.type.inspect is not a function
So I installed the example without any other code. I added the modules via
yarn add express body-parser
yarn add path graphql graphql2rest
which results in packages.conf:
{
"dependencies": {
"body-parser": "^1.19.0",
"express": "^4.17.1",
"graphql": "^16.0.1",
"graphql2rest": "^0.6.4",
"path": "^0.12.7"
}
}
Executing ends up in the error
myuser@MacBook-Pro graphql2rest % node index.js
info: GQLGenerator initializing...
info: GQLGenerator initialized with query depthLimit of 1000
info: [gqlgenerator] Creating folder /Users/myuser/graphql2rest/myGqlFiles/
error: [gqlgenerator] Encountered error trying to generate GQL files for GraphQL operations. Aborting
error: TypeError: field.type.inspect is not a function
at generateQuery (/Users/myuser/graphql2rest/node_modules/graphql2rest/src/gqlgenerator/schemaParser.js:70:33)
at /Users/myuser/graphql2rest/node_modules/graphql2rest/src/gqlgenerator/index.js:123:23
at Array.forEach (<anonymous>)
at generateFile (/Users/myuser/graphql2rest/node_modules/graphql2rest/src/gqlgenerator/index.js:122:19)
at generateQueries (/Users/myuser/graphql2rest/node_modules/graphql2rest/src/gqlgenerator/index.js:147:3)
at Object.generateGqlQueryFiles (/Users/myuser/graphql2rest/node_modules/graphql2rest/src/gqlgenerator/index.js:59:3)
at Object.<anonymous> (/Users/myuser/graphql2rest/index.js:77:14)
at Module._compile (internal/modules/cjs/loader.js:1068:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1097:10)
at Module.load (internal/modules/cjs/loader.js:933:32)
error: FATAL: Error while attempting to load index.js from gqlGeneratorOutputFolder /Users/myuser/graphql2rest/myGqlFiles. Absolute path: "/Users/myuser/graphql2rest/myGqlFiles/".
Function generateGqlQueryFiles() must be executed at least once before init() is invoked, to generate .gql query files and index from your schema. Did you run it?
If you did and you specified a custom folder name, make sure you provide the "options" parameter to init(), and that "options.gqlGeneratorOutputFolder" is set to the correct folder.
...
My environment is
- MacOS 10.15.7
- Node.js v14.17.0 also tested with new LTS v16.13.1
Which example did you try? (please provide link)
Can you share the GraphQL schema you've used that resulted in the error?
Thanks
This one: https://github.com/sisense/graphql2rest/tree/master/examples
So the schema is provided in the index.js
The project has just three files: two of the example directory and one package.json as see above.
It will be started via "node index.js" (in other projects via npm, but this doesnt matter).
@roy-mor: Do you need additional info or should I test something?
Same problem here :'(
Same problem. Also on Mac OS, Node v16.13.1.
Might be related to the version of Node. graphql/graphql-js#1599 it looks like inspect is a method that comes from the javascript language, and it has been deprecated.
Looking at the code, it looks like inspect methods are used as a quick and dirty way to get the name of a type. in src/gqlgenerator/schemaparser.js around line 70.
I got a bit further by replacing field.type.inspect.replace(/[[]!]/g, ''); with field.type.toString().replace(/[[]!]/g, ''); at around line 70 of src/gqlgenerator/schemaparser.js.
The issue definitely happens when updating graphql
to v16 and I would agree with Warren's assessment that the removal of Node's inspect function in graphql is the culprit.
@roy-mor could you confirm Warren's fix to replace inspect
with toString
?