graphql-nexus / nexus

Code-First, Type-Safe, GraphQL Schema Construction
https://nexusjs.org
MIT License
3.4k stars 275 forks source link

Compilation errors in nexus versions >= 0.11.5 #112

Closed schuma7 closed 5 years ago

schuma7 commented 5 years ago

I'm using nexus together with apollo server and noticed that the following schema:

import path from 'path';
import { makeSchema, objectType } from 'nexus';

const Query = objectType({
  name: 'Query',
  definition(t) {
    t.string('_empty', {
      resolve: () => {
        return '';
      },
    });
  },
});

const schema = makeSchema({
  types: [Query],
  outputs: {
    schema: path.join(__dirname, '../schema.graphql'),
    typegen: path.join(__dirname, '../src/generated/typegen.ts'),
  },
});

export { schema };

produces these compilation errors:

node_modules/nexus/dist/builder.d.ts:203:6 - error TS2707: Generic type 'GraphQLObjectType<TSource, TContext>' requires between 0 and 2 type arguments.

203   ): GraphQLObjectType<
         ~~~~~~~~~~~~~~~~~~
204     any,
    ~~~~~~~~
...
208     }
    ~~~~~
209   >;
    ~~~

node_modules/nexus/dist/builder.d.ts:227:6 - error TS2707: Generic type 'GraphQLObjectType<TSource, TContext>' requires between 0 and 2 type arguments.

227   ): GraphQLObjectType<
         ~~~~~~~~~~~~~~~~~~
228     any,
    ~~~~~~~~
...
232     }
    ~~~~~
233   >[];
    ~~~

node_modules/nexus/dist/utils.d.ts:15:9 - error TS2707: Generic type 'GraphQLObjectType<TSource, TContext>' requires between 0 and 2 type arguments.

 15   type: GraphQLObjectType<
            ~~~~~~~~~~~~~~~~~~
 16     any,
    ~~~~~~~~
...
 20     }
    ~~~~~
 21   >,
    ~~~

I've noticed the following:

I'm using Node v10.5.0 and my package dependencies are as follows:

"dependencies": {
    "@okgrow/graphql-scalars": "^0.4.5",
    "apollo-datasource-rest": "^0.3.2",
    "apollo-server": "^2.3.1",
    "apollo-server-express": "^2.3.1",
    "config": "^3.0.1",
    "express": "^4.16.4",
    "graphql": "^14.0.2",
    "graphql-iso-date": "^3.6.1",
    "graphql-tools": "^4.0.4",
    "graphql-type-json": "^0.2.1",
    "jsonwebtoken": "^8.5.0",
    "moment": "^2.24.0",
    "nexus": "0.11.5",
    "uuid": "^3.3.2"
  },
  "devDependencies": {
    "@types/config": "0.0.34",
    "@types/graphql-iso-date": "^3.3.1",
    "@types/graphql-type-json": "^0.1.3",
    "@types/jsonwebtoken": "^8.3.2",
    "@types/uuid": "^3.4.4",
    "@typescript-eslint/eslint-plugin": "^1.2.0",
    "@typescript-eslint/eslint-plugin-tslint": "^1.3.0",
    "@typescript-eslint/parser": "^1.3.0",
    "cross-env": "^5.2.0",
    "eslint": "^5.13.0",
    "eslint-config-airbnb-base": "^13.1.0",
    "eslint-config-prettier": "^4.0.0",
    "eslint-import-resolver-typescript": "^1.1.1",
    "eslint-plugin-import": "^2.16.0",
    "eslint-plugin-prettier": "^3.0.1",
    "nodemon": "^1.18.9",
    "prettier": "1.16.4",
    "rimraf": "^2.6.3",
    "ts-node": "^8.0.1",
    "tslint": "^5.12.1",
    "ts-node-dev": "^1.0.0-pre.30",
    "typescript": "^3.1.6"
  }
tgriesser commented 5 years ago

Can you check your lockfile npm or yarn to see what version of @types/graphql is being pulled in - I'm guessing it's an older one than the one nexus was built with, as that's the only thing I see that might be causing the issue.

I believe the version you have does not specify GraphQLObjectType args as having a default, and the build .d.ts has:

export declare const isInterfaceField: (
  type: GraphQLObjectType<
    any,
    any,
    {
      [key: string]: any;
    }
  >,
  fieldName: string
) => boolean;

Anyway, adding "@types/graphql": "^14.0.7" to your devDependencies should fix it.

schuma7 commented 5 years ago

Changing to ^14.0.7 has indeed solved the issue, thank you very much for your swift response!