Last active
July 23, 2019 19:45
-
-
Save JakeDawkins/bcf5ecf08ea9a11520dfe5d644136f5f to your computer and use it in GitHub Desktop.
Apollo config 3.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TO VIEW THE WORK DONE ON LOADING EN EXPERIMENTAL CONFIG, SEE THIS BRANCH: | |
// https://github.com/apollographql/apollo-tooling/compare/jake/experimental-config | |
/** | |
* Goal: rebuild apollo config to allow for easier configuration | |
* | |
* Ideas: | |
* - More top-level options with fewer nested keys | |
* - I don't think field nesting is strictly necessary, since a _lot_ | |
* of things are duplicated between client/service projects (like includes) | |
* - No inference around project type | |
* - Multiple projects in a single config | |
* | |
* Gotcha's: | |
* - Should it be possible to run a cli command from the root? | |
* - apollo client:codegen --project=web | |
* - equivalent to `cd projects/web && apollo client:codegen` | |
* - apollo client:check --config=./myProj/my.config.js --project=web | |
* - equivalent to `cd myProj/projects/web && apollo client:codegen` | |
* - what to do if multiple projects overlap paths? | |
* - We should probably error for this | |
*/ | |
type ClientOptions = { | |
name?: string; | |
referenceID?: string; | |
version?: string; | |
// client schemas | |
clientOnlyDirectives?: string[]; | |
clientSchemaDirectives?: string[]; | |
addTypename?: boolean; | |
// stats window config | |
statsWindow?: { to: number; from: number }; | |
}; | |
type SchemaSource = { | |
registry?: boolean; | |
files?: string[]; | |
url?: string; | |
headers?: Record<string, string>; | |
skipSSLValidation?: boolean; | |
}; | |
type BaseProjectConfig = { | |
includes?: string[]; | |
excludes?: string[]; | |
apolloGraphId?: string; | |
apolloGraphVariant?: string; | |
schema?: SchemaSource; | |
}; | |
type ClientConfig = BaseProjectConfig & { | |
type: 'client'; | |
clientOptions?: ClientOptions; | |
}; | |
type ServiceConfig = BaseProjectConfig & { | |
type: 'service'; | |
}; | |
type ProjectConfig = ClientConfig | ServiceConfig; | |
type ApolloConfig = | |
| ProjectConfig | |
| { | |
projects: Record<string, ProjectConfig>; | |
}; | |
module.exports = { | |
projects: { | |
// >>>>>>>>>> CLIENT EXAMPLES <<<<<<<<<<<<< | |
clientWithEngineService: { | |
type: 'client', | |
includes: ['src/**/*.{ts,tsx,js,jsx,graphql}'], | |
apolloGraphId: 'github', | |
apolloGraphVariant: 'prod', | |
schema: { | |
// signifies the schema is coming from the apollo registry, not anywhere else. | |
// if `apolloGraphId` is present, this is the default option, and could be left off. | |
registry: true, | |
}, | |
}, | |
clientWithMultipleSchemaFiles: { | |
type: 'client', | |
includes: ['src/**/*.{ts,tsx,js,jsx,graphql}'], | |
schema: { | |
files: ['./schema/a.graphql', './schema/b.graphql'], | |
}, | |
}, | |
clientWithSimpleIntrospectedSchema: { | |
type: 'client', | |
schema: { | |
url: 'https://api.github.com/graphql', | |
}, | |
}, | |
clientWithComplexIntrospectedSchema: { | |
type: 'client', | |
schema: { | |
url: 'https://api.github.com/graphql', | |
headers: { | |
Authorization: 'Bearer ${env:YOUR_APP_TOKEN}', | |
}, | |
skipSSLValidation: true, | |
}, | |
}, | |
// >>>>>>>>>> SERVICE EXAMPLES <<<<<<<<<<<<< | |
serviceWithSimpleIntrospectedSchema: { | |
type: 'service', | |
includes: ['src/**/*.{ts,tsx,js,jsx,graphql}'], | |
apolloGraphId: 'my-service', | |
apolloGraphVariant: 'prod', | |
// this is the endpoint for a local scheme. All checks and pushes will still go to the registry. | |
schema: { | |
url: 'http://localhost:4000/graphql', | |
}, | |
}, | |
serviceWithSchemaFiles: { | |
type: 'service', | |
includes: ['src/**/*.{ts,tsx,js,jsx,graphql}'], | |
apolloGraphId: 'my-service', | |
apolloGraphVariant: 'prod', | |
schema: { | |
files: ['./schema/a.graphql', './schema/b.graphql'], | |
}, | |
}, | |
}, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment