0no-co / gql.tada

🪄 Magical GraphQL query engine for TypeScript
https://gql-tada.0no.co
MIT License
2.44k stars 34 forks source link

gql.tada losed Smart tips while writing `gql` fields #314

Closed tianyingchun closed 1 month ago

tianyingchun commented 1 month ago

Describe the bug

import { initGraphQLTada } from 'gql.tada';
import type { introspection } from './graphql-env.d.ts';

export const graphql = initGraphQLTada<{
  introspection: introspection;
}>();

const ACTIVE_CUSTOMER = graphql(`
  query ActiveCustomer {
    activeCustomer {
      id
      firstName
      lastName
      phoneNumber
      emailAddress
    }
  }
`);

in vscode it can not auto intelligent give us tips for fields

 firstName
      lastName
      phoneNumber
      emailAddress
image

Reproduction

No response

{
  "typescript.tsdk": "node_modules/typescript/lib",
  "typescript.enablePromptUseWorkspaceTsdk": true,
  "editor.formatOnSave": true,
  "editor.defaultFormatter": "dbaeumer.vscode-eslint",
  "eslint.experimental.useFlatConfig": true,
  "editor.codeActionsOnSave": {
    "source.fixAll": "explicit",
    "source.organizeImports": "never"
    // "source.removeUnused": "always"
  },
  "files.associations": {
    "*.css": "tailwindcss"
  },
  "tailwindCSS.experimental.classRegex": [
    ["cva\\(([^)]*)\\)", "[\"'`]([^\"'`]*).*?[\"'`]"],
    ["cx\\(([^)]*)\\)", "(?:'|\"|`)([^']*)(?:'|\"|`)"]
  ],
  "[javascript]": {
    "editor.formatOnSave": false
  },
  "i18n-ally.localesPaths": ["i18n"],
  "i18n-ally.keystyle": "nested"
}

gql.tada version

"vscode": Version: 1.91.0-insider,
"gql.tada": "1.7.5"

Validations

tianyingchun commented 1 month ago

i found the cause of this issue

 "plugins": [
      {
        "name": "next"
      },
      {
        "name": "@0no-co/graphqlsp",
        "schemas": [
          {
// if i setup `name` to `shop-api` it can not works, the `name` setup to  "@0no-co/graphqlsp", it works
            "name": "shop-api",
            "schema": "http://localhost:7001/shop-api",
            "tadaOutputLocation": "./src/common/graphql-env.d.ts"
          }
        ]
      }

// if i setup name to shop-api it can not works, the name setup to "@0no-co/graphqlsp", it works

kitten commented 1 month ago

Just to point this out, did you run gql.tada doctor by any chance? It should catch these kinds of issues, but we haven't really made the warnings on running it when you change these files more obvious

tianyingchun commented 1 month ago

yes i have tried gql.tada doctor it works fine, i found sometimes

image

sometimes it works, it caused by "typescript.enablePromptUseWorkspaceTsdk": true,?

tianyingchun commented 1 month ago

Is it possible that vscode configuration does not work sometimes?

tianyingchun commented 1 month ago

i think i found the root cause, please see my tsconfig.json

   {
            "name": "admin-api",
            "schema": "http://localhost:7001/shop-api",
            "tadaOutputLocation": "./src/graphql-env1.d.ts"
          }

i have configd "schema" to online http http://localhost:7001/shop-api, if i have generated ./src/graphql-env1.d.ts and stop graphql server http://localhost:7001/shop-api

for now reload vscode IDE the auto intelligent can not works correct, the intelligent feature disappeared

and when i restart graphql server to make sure http://localhost:7001/shop-api can be access ok, then relunch vscode IDE, it works


but i think because i have generated a correct graphql-env1.d.ts file, it should works correct even if i have closed graphql server http://localhost:7001/shop-api?

tianyingchun commented 1 month ago

because in the most time we may don't need to keep our graphql server online, because of we have generated an latest correct version graphql-env1.d.ts, the graphql(....) should works correctly for auto intelligent feature what do you think?

kitten commented 1 month ago

That's working as intended.

If you shut down your API the type inference will still work as long as that typings file is generated but the GraphQLSP plugin (i.e. the editor support) will stop being able to retrieve the schema.

There's more details about this in the docs. Specifically, you may want to look into either saving an SDL schema file or making your server output an SDL schema file if you don't want to keep the server running

If you don't have an easy way to let your API output a local .graphql file, you can use the CLI to generate one: https://gql-tada.0no.co/get-started/workflows

tianyingchun commented 1 month ago

Thank you so much for clarifying the confusion