Apollo-tooling: Typescript Modern Root Directory

Created on 24 Dec 2018  ยท  5Comments  ยท  Source: apollographql/apollo-tooling

I'm using the following project structure:

.
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ node_modules
โ”‚  โ””โ”€โ”€ @forte-music/schema
โ”‚      โ””โ”€โ”€ schema.graphql
โ””โ”€โ”€ src
   โ”œโ”€โ”€ __generated__
   โ””โ”€โ”€ query.ts

In package json

  "apollo": {
    "client": {
      "service": {
        "name": "forte",
        "localSchemaFile": "./node_modules/@forte-music/schema/schema.graphql"
      }
    }
  },

When using

apollo codegen:generate --queries 'src/**/*.{graphql,ts,tsx}' --target typescript

A __generated__ folder is added in the project root.

โ””โ”€โ”€ globalTypes.ts

Is there a way to specify an output root? I would like the __generated__ folder to be in the src folder and nothing outside src to be affected.

Most helpful comment

No, --outputFlat puts all the output into a single directory. This is not the desired behavior. I want to put the globalTypes.ts under src/__generated__/globalTypes.ts instead of ./__generated__/globalTypes.ts.

All 5 comments

Hey @0xcaff, sorry for the delayed response here. It looks like you may have found a way to achieve what you needed, but we also have the --outputFlat flag which is what I think you wanted. The README at the root of this project enumerates all the possible flags. You can get the same printout by running npx apollo client:codegen --help. Hope this is helpful - feel free to reopen a separate issue if you're still having any problems ๐Ÿ‘

No, --outputFlat puts all the output into a single directory. This is not the desired behavior. I want to put the globalTypes.ts under src/__generated__/globalTypes.ts instead of ./__generated__/globalTypes.ts.

I am also having the same issue...trying to generate the globalTypes.ts under the src/__generated__ folder and it does, but it also creates an empty __generated__ folder at my project root (where package.json is located).

This is what my command looks like
sh apollo client:codegen --target=typescript --globalTypesFile=src/__generated__/globalTypes.ts __generated__

I am also having this issue too.

I added this to the script to resolve the issue. The only thing is that it still creates an empty __generated__ folder at root :|

--globalTypesFile="src/__generated__/globalTypes.d.ts"

@masashiswingle any luck on not automatically creating the generated folder?
I got it working with
apollo client:codegen --target=typescript --outputFlat './src/__generated__'
It's just that you have to make sure that the __generated__ folder exists

Was this page helpful?
0 / 5 - 0 ratings