1

Ok, for 2 years I have been developing a GraphQL Node.js Apollo API in typescript, and there is one thing our team never managed to get up and running: How do we get "Go to Definition" in our .ts files, containing the Grahpql Schema?

Our schema is defined in multiple .ts files, and it's very frustrating having to look through many files when needing to lookup a type definition, input, etc.

We are all using VS Code, and I hoped I could obtain this with the Apollo Graphql extension. However this only seems to work for client projects?

Example of code structure

// file 1, inputs.ts
export const inputs = gql`
  input: FancyInput {
     fancyName: String!
  }
`;

// file 2, mutations.ts
export const mutations = gql`
  // HOW do we get "Go to Definition" when right clicking the 'FancyInput'?
  fancyMutation(input: FancyInput): Boolean!
`;

// file 3, apollo-server-setup
const { inputs } = from './inputs';
const { mutations } = from './mutations';
const server = new ApolloServer({
  typeDefs: [
    inputs,
    mutations
  ]
})

In the beginning, this was not a big problem, but now it's super frustrating because the project is rather big today with 30+ schema files.

DauleDK
  • 3,313
  • 11
  • 55
  • 98
  • reason for using graphql in ts files ? https://marketplace.visualstudio.com/items?itemName=kumar-harsh.graphql-for-vscode – xadm Aug 27 '20 at 18:39
  • Hi xadm - we are just following the graphql apollo server guides, where they are using typescript? Is it possible to define the schema in .gql files? – DauleDK Aug 27 '20 at 18:46
  • sure, with webpack ... or w/o https://stackoverflow.com/a/55737614/6124657 ... google for `"schema.graphql" webpack` or generators/loaders – xadm Aug 27 '20 at 19:08

0 Answers0