menu

Apollo

A community of developers, designers and others who love Apollo and GraphQL. 🚀

Channels
Team

Tips / workflow for codegen and CI / CD?

May 11, 2020 at 6:37pm

Tips / workflow for codegen and CI / CD?

May 11, 2020 at 6:37pm (Edited 5 months ago)
Hi all,
I have codegen working nicely with my local Apollo instance. My question is if anyone has an example of their package.json configuration for use in their build pipeline?
I have something like this in my package.json:
"scripts": {
"codegen": "apollo client:codegen --target=typescript --outputFlat",
"develop": "gatsby develop",
"prebuild": "npm run codegen",
"build": "gatsby build",
"prestart": "npm run codegen"
},
and a .graphqlconfig like this:
{
"extensions": {
"endpoints": {
"dev": {
"url": "http://localhost:4000/graphql"
}
}
}
}
Where I'm struggling is, how do I communicate with my various Apollo Server instances in different environments?

May 11, 2020 at 6:42pm
If you use graph manager then all of your schema is linked to a single endpooint with different tags. Then codegen can register/pull from those environments. CI/CD can register to check your schema on deploy/upload as well.
  • reply
  • like
from a YML file to use with bitbucket pipelines.
- step: &ValidateGQL
name: Validate GQL
caches:
- node
script:
- yarn apollo client:check --variant=Development
- step: &ValidateGQL-UAT
name: Validate GQL
caches:
- node
script:
- yarn apollo client:check --variant=UAT
- step: &ValidateGQL-PROD
name: Validate GQL
caches:
- node
script:
- yarn apollo client:check --variant=Production
  • reply
  • like
graph manager: https://engine.apollographql.com/ once you set your APOLLO_KEY in .env you can swap around what envs you are working in.
Edited
  • reply
  • like
Okay cool, reading up on managing environments with variants now.
  • reply
  • like
So I eventually realized that i wasn't even using my .graphqlconfig file, so I deleted that and just manually handled which endpoint to use based on environmental variables.
  • reply
  • like
Now I just need to figure out CORS....
Edited
  • reply
  • like