Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there a way to make this work with apollo generate:codegen? #9

Open
vjpr opened this issue Jul 19, 2018 · 5 comments
Open

Is there a way to make this work with apollo generate:codegen? #9

vjpr opened this issue Jul 19, 2018 · 5 comments

Comments

@vjpr
Copy link

vjpr commented Jul 19, 2018

import {RouteModelFragment} from 'fragments/foo.fragments'

const query = gql`
  query maintenanceRoutes {
    routes {
      ...RouteModelFragment
    }
    zones {
      id
      zoneName
    }
  }
  
  ${RouteModelFragment}
`

$ apollo codegen:generate --schema=schema.graphql --target=flow --outputFlat --queries='foo.js' $OUT_DIR/types

Unknown fragment "RouteModelFragment".

ToolError: Validation of GraphQL query document failed
    at Object.validateQueryDocument (~/nvm/versions/node/v8.9.0/pnpm-global/1/node_modules/.registry.npmjs.org/apollo/1.4.0/node_modules/apollo/lib/validation.js:17:15)
    at Object.generate [as default] (~/nvm/versions/node/v8.9.0/pnpm-global/1/node_modules/.registry.npmjs.org/apollo/1.4.0/node_modules/apollo/lib/generate.js:19:18)
    at Task.task (~/nvm/versions/node/v8.9.0/pnpm-global/1/node_modules/.registry.npmjs.org/apollo/1.4.0/node_modules/apollo/lib/commands/codegen/generate.js:152:60)
    at Promise.resolve.then.then.skipped (~/nvm/versions/node/v8.9.0/pnpm-global/1/node_modules/.registry.npmjs.org/listr/0.14.1/node_modules/listr/lib/task.js:167:30)
    at <anonymous>

I wonder if apollo codegen can reference fragments from its schema so we don't need the import?

This issue means having to choose between templated gql queries or query type generation.

graphql-cli-generate-fragments may still be useful for copy-pasting in the generated fragments instead of having to type them.

And maybe its better to keep gql queries static so IDE integrations can work properly. Although the Apollo docs suggest importing fragments into your queries here: https://www.apollographql.com/docs/react/advanced/fragments.html.

@vjpr
Copy link
Author

vjpr commented Jul 19, 2018

Maybe if codegen support graphql-import it would work. apollographql/rover#495

@develomark
Copy link
Owner

@vjpr I intend to re-write to work with graphql codegen - which I think wraps apollo generate:codegen.

@ovidb
Copy link

ovidb commented May 9, 2019

Any news on this?

@sascha1337
Copy link

up

@predaytor
Copy link

predaytor commented Mar 19, 2021

Check your includes path like:
apollo codegen:generate --localSchemaFile=schema.json --target=typescript --includes=src/gql/**/*.gql.ts --outputFlat=src/gql/types --tagName=gql --addTypename --globalTypesFile=@types/globalTypes.d.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants