Skip to content
This repository has been archived by the owner on Dec 8, 2021. It is now read-only.

Unable to use typeorm model files #342

Open
vibhanshu909 opened this issue Dec 13, 2018 · 1 comment
Open

Unable to use typeorm model files #342

vibhanshu909 opened this issue Dec 13, 2018 · 1 comment

Comments

@vibhanshu909
Copy link

vibhanshu909 commented Dec 13, 2018

Description

I'm using TypeORM and trying to use graphqlgen to generate resolver types.

Steps to reproduce

Create a project with TypeORM and graphql-yoga, created a TypeORM Entity (model/table).
Installed graphqlgen globally.
created graphqlgen.yml file with following content:-

language: typescript

schema: ./src/schema.graphql
context: ./src/types.ts:Context
models:
  files:
    - ./src/entity/User.ts

output: ./src/generated/graphqlgen.ts

resolver-scaffolding:
  output: ./src/generated/tmp-resolvers/
  layout: file-per-type

Actual results

(node:283) UnhandledPromiseRejectionWarning: SyntaxError: This experimental syntax requires enabling one of the following parser plugin(s): 'decorators-legacy, decorators' (4:0) at _class.raise (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:4028:15) at _class.expectOnePlugin (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:5378:18) at _class.parseDecorator (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:7645:10) at _class.parseDecorators (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:7627:28) at _class.parseStatement (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:7475:12) at _class.parseBlockOrModuleBlockBody (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:8046:23) at _class.parseBlockBody (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:8033:10) at _class.parseTopLevel (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:7443:10) at _class.parse (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:8876:17) at Object.parse (/usr/local/lib/node_modules/graphqlgen/node_modules/@babel/parser/lib/index.js:10907:38) (node:283) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:283) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Versions

  • graphqlgen: 0.4.0
  • OS name and version: ubuntu 18.04
@vinsidious
Copy link

I know this issue is over a month old, but I ran into the same issue today and figured I might as well share my workaround.

I ended up using the patch-package module to add the decorators-legacy plugin to the array of plugins used by the ts parser. Here's the patch:

--- a/node_modules/graphqlgen/dist/introspection/ts-ast.js
+++ b/node_modules/graphqlgen/dist/introspection/ts-ast.js
@@ -144,7 +144,7 @@ function isFieldOptional(node) {
 }
 function buildTSTypesMap(fileContent, filePath) {
     var ast = parser_1.parse(fileContent, {
-        plugins: ['typescript'],
+        plugins: ['typescript', 'decorators-legacy'],
         sourceType: 'module',
     });
     var typesMap = findTypescriptTypes(ast).reduce(function (acc, type) {

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants