nexus: Unused interfaces cause a compilation error
Hi,
I’m currently in the process of migrating my codebase to Nexus. I can successfully run the following code snippet using ts-node-dev --no-notify --transpileOnly --respawn src/server.ts:
import { asNexusMethod, interfaceType, queryField } from 'nexus';
import { GraphQLDate } from 'graphql-iso-date';
const DateScalar = asNexusMethod(GraphQLDate, 'date');
const DisplayableError = interfaceType({
name: 'DisplayableError',
definition(t) {
t.list.string('field', { nullable: true });
t.string('logCode', { nullable: true });
t.string('message');
t.resolveType(() => undefined);
},
});
const Node = interfaceType({
name: 'Node',
definition(t) {
t.id('id');
t.resolveType(() => undefined);
},
});
const currentDateQueryField = queryField('currentDate', {
type: DateScalar,
resolve() {
return new Date();
},
});
export { DateScalar, DisplayableError, Node, currentDateQueryField };
However, when trying to compile it using tsc I get the following 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 >,
~~~
src/common/commonSchema2.ts:11:5 - error TS2345: Argument of type '[]' is not assignable to parameter of type '[OutputScalarConfig<"DisplayableError", "message"> & { resolve: FieldResolver<"DisplayableError", "message">; }] | [FieldResolver<"DisplayableError", "message">]'.
Type '[]' is not assignable to type '[FieldResolver<"DisplayableError", "message">]'.
Property '0' is missing in type '[]'.
11 t.string('message');
~~~~~~~~~~~~~~~~~~~
src/common/commonSchema2.ts:19:5 - error TS2345: Argument of type '[]' is not assignable to parameter of type '[OutputScalarConfig<"Node", "id"> & { resolve: FieldResolver<"Node", "id">; }] | [FieldResolver<"Node", "id">]'.
Type '[]' is not assignable to type '[FieldResolver<"Node", "id">]'.
Property '0' is missing in type '[]'.
19 t.id('id');
~~~~~~~~~~
src/common/commonSchema2.ts:24:57 - error TS2345: Argument of type '{ type: GraphQLScalarType; resolve(): Date; }' is not assignable to parameter of type 'NexusOutputFieldConfig<"Query", "currentDate"> | (() => NexusOutputFieldConfig<"Query", "currentDate">)'.
Type '{ type: GraphQLScalarType; resolve(): Date; }' is not assignable to type '() => NexusOutputFieldConfig<"Query", "currentDate">'.
Type '{ type: GraphQLScalarType; resolve(): Date; }' provides no match for the signature '(): NexusOutputFieldConfig<"Query", "currentDate">'.
24 const currentDateQueryField = queryField('currentDate', {
~
25 type: DateScalar,
~~~~~~~~~~~~~~~~~~~
...
28 },
~~~~
29 });
I’m using Node v10.5.0 and my package deps look 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.1.1",
"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.6",
"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",
"prettier": "1.16.4",
"rimraf": "^2.6.3",
"ts-node-dev": "^1.0.0-pre.32",
"tslint": "^5.12.1",
"typescript": "^3.1.3"
}
I’d appreciate if someone could provide some pointers as to what what might be the issue here.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 5
- Comments: 15 (2 by maintainers)
graphql downgrade to 14.6. It solved my problem.