prisma-labs / graphql-framework-experiment

Code-First Type-Safe GraphQL Framework
https://nexusjs.org
MIT License
673 stars 66 forks source link

No TypeScript types for connectionField #952

Closed dantman closed 4 years ago

dantman commented 4 years ago

Screenshot

Screen Shot 2020-05-30 at 2 55 30 PM

Description

The connectionPlugin says this is how to use the plugin.

export const User = objectType({
  name: "User",
  definition(t) {
    t.connectionField(...);
  },
});

However this code gives the error Property 'connectionField' does not exist on type 'ObjectDefinitionBlock<"User">'. because there are no type definitions for connectionField. There doesn't even appear to be an extra plugin file to import to add types in.

Akxe commented 4 years ago

Share your tsconfig.json that might be the error...

dantman commented 4 years ago

I don't see how the tsconfig can be the error. I checked the source code and don't see any definition for connectionField. tsconfig can't make a type definition exist when none exist.

{
  "compilerOptions": {
    "target": "es2016",
    "downlevelIteration": true,
    "lib": [
      "dom",
      "dom.iterable",
      "es2015.collection",
      "es2015.iterable",
      "esnext"
    ],
    "declaration": false,
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "CommonJS",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react"
  }
}
Akxe commented 4 years ago

@dantman I was missing types when I used compilerOptions.types as some types sis not get loaded. This seemed really similar, so I tried it. Doesn't seems like the case though... I wish you good luck finding a solution.

jasonkuhrt commented 4 years ago

@dantman did you install the plugin? Guessing you did but not clear.

dantman commented 4 years ago

Adding the connectionPlugin to the schema, of course. But adding a line of code like that does not change the TypeScript types exported by @nexus/schema.

const schema = makeSchema({
  // ... types, etc,
  plugins: [
    // ... other plugins
    connectionPlugin(),
  ],
});
marceloverdijk commented 4 years ago

I'm noticing the same. Also with a custom plugin providing a t.pageField method.

jasonkuhrt commented 4 years ago

But adding a line of code like that does not change the TypeScript types exported by @nexus/schema.

It is not about what's exported. It is about the typegen that takes place during reflection. And in that, the plugin does affect the typegen. Anyways, you registered the plugin.

dantman commented 4 years ago

It is not about what's exported. It is about the typegen that takes place during reflection. And in that, the plugin does affect the typegen. Anyways, you registered the plugin.

Oh, the TypeScript types are part of the generated output.

It was not clear in the documentation that the types for the connection plugin's API were part of generated code and they need to be in a place where the tsconfig's includes fill find them.

marceloverdijk commented 4 years ago

What did you do to get error away?

marceloverdijk commented 4 years ago

Never mind, I'm switching to nexus framework.

dantman commented 4 years ago

There's actually a further issue here. vscode and tsc will pick up on the types.d.ts file. However ts-node users will still encounter this error when they try to run their server.

https://github.com/TypeStrong/ts-node#help-my-types-are-missing

jacktan165 commented 4 years ago

I have the same issue too. Did you removed the errors? How do you generate the types.d.ts file?

alchemyjamie commented 2 years ago

@dantman were you able to resolve this when running w/ ts-node? I'm experiencing the same as above

longlhh90 commented 2 years ago

@alchemyjamie you can add --files option into the command of ts-node or in tsconfig.json like this:

{
  "ts-node": {
    "files": true
  },
  "compilerOptions": {
    // ....
  }
}

original answer I found here https://stackoverflow.com/questions/60782231/ts-node-cant-find-my-type-definition-files