Apollo GraphQL Server - Generating TypeScript types from schema with apollo codegen

Hi all,

I am currently setting an a new Apollo Project (FE: React / BE: plain apollo-server)

I followed this tutorial to generate the type information from server on the React Application

This worked fine.

How can I generate the typescript definitions on the server? On the server I don’t want the server to connect with itself via npx apollo service:download --endpoint=http://localhost:4000/ graphql-schema.json to generate the local schema file.

Is it possible to directly generate the typescript defintions via

npx apollo codegen:generate --localSchemaFile=THIS_SHOULD_BE_FROM_MY_LOCAL_GQL_SCHEMA_DEFINITIONS --target=typescript --tagName=gql

from the ts file with the gql definitions (export const typeDefs = gql...)
As an alternative I could also think of that there is a posibility to have a separate gql file which is used for TS Type code generation

I use apollo codegen for client-side codegen and graphql-code-generator for server-side.