-
Notifications
You must be signed in to change notification settings - Fork 240
feat: migrate graphs from apollo #17
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
Merged
JivusAyrus
merged 11 commits into
main
from
suvij/eng-3816-migrate-from-apollo-to-cosmo
Aug 31, 2023
Merged
Changes from 5 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
3215d0b
feat: migrate graphs from apollo
JivusAyrus 12e1754
fix: ci
JivusAyrus 38cc616
fix: ci
JivusAyrus 842bf5a
feat: add confetti
JivusAyrus 98714f3
Merge branch 'main' into suvij/eng-3816-migrate-from-apollo-to-cosmo
JivusAyrus 56f564b
feat: improve the ui of migration button
JivusAyrus c0718db
fix: pr suggestions
JivusAyrus a3fff1d
Merge branch 'main' into suvij/eng-3816-migrate-from-apollo-to-cosmo
JivusAyrus 4bf337b
fix: ci
JivusAyrus 33836bc
Merge branch 'suvij/eng-3816-migrate-from-apollo-to-cosmo' of github.…
JivusAyrus 1845e27
fix: ci
JivusAyrus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| import { MigrationSubgraph } from 'src/types/index.js'; | ||
|
|
||
| export default class MigrateFromApollo { | ||
|
StarpTech marked this conversation as resolved.
Outdated
|
||
| apiKey = ''; | ||
| organizationSlug = ''; | ||
| constructor({ apiKey, organizationSlug }: { apiKey: string; organizationSlug: string }) { | ||
| this.apiKey = apiKey; | ||
| this.organizationSlug = organizationSlug; | ||
| } | ||
|
|
||
| public async fetchGraphID(): Promise<{ id: string; name: string }> { | ||
| const headers = new Headers(); | ||
| headers.append('X-API-KEY', this.apiKey); | ||
| headers.append('apollographql-client-name', this.organizationSlug); | ||
| headers.append('apollographql-client-version', '1.0.0'); | ||
| headers.append('Content-Type', 'application/json'); | ||
|
|
||
| const graphql = JSON.stringify({ | ||
| operationName: 'ListVisibleGraphs', | ||
| query: ` | ||
| query ListVisibleGraphs { | ||
| me { | ||
| id | ||
| name | ||
| } | ||
| } | ||
| `, | ||
| variables: {}, | ||
| }); | ||
|
|
||
| const response = await fetch('https://graphql.api.apollographql.com/api/graphql', { | ||
| method: 'POST', | ||
| headers, | ||
| body: graphql, | ||
| }); | ||
| if (response.status !== 200) { | ||
| throw new Error('Could not fetch the graph from apollo.'); | ||
| } | ||
| const body = await response.json(); | ||
| const data = body.data; | ||
| return { | ||
| id: data.me.id, | ||
| name: data.me.name, | ||
| }; | ||
| } | ||
|
|
||
| // fetches the schemas of the subgraphs and the routing url of the federated graph | ||
| public async fetchGraphDetails({ graphID, variantName }: { graphID: string; variantName: string }): Promise<{ | ||
| fedGraphRoutingURL: string; | ||
| subgraphs: MigrationSubgraph[]; | ||
| }> { | ||
| const headers = new Headers(); | ||
| headers.append('X-API-KEY', this.apiKey); | ||
| headers.append('apollographql-client-name', this.organizationSlug); | ||
| headers.append('apollographql-client-version', '1.0.0'); | ||
| headers.append('Content-Type', 'application/json'); | ||
|
|
||
| const graphql = JSON.stringify({ | ||
| query: ` | ||
| query GetGraph($graphId: ID!) { | ||
| graph(id: $graphId) { | ||
| id | ||
| title | ||
| variants { | ||
| id | ||
| url | ||
| name | ||
| subgraphs { | ||
| name | ||
| url | ||
| activePartialSchema { | ||
| sdl | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `, | ||
| variables: { | ||
| graphId: graphID, | ||
| }, | ||
| }); | ||
|
|
||
| const response = await fetch('https://graphql.api.apollographql.com/api/graphql', { | ||
| method: 'POST', | ||
| headers, | ||
| body: graphql, | ||
| }); | ||
| if (response.status !== 200) { | ||
| throw new Error('Could not fetch the subgraphs from apollo.'); | ||
| } | ||
| const body = await response.json(); | ||
| const data = body.data; | ||
| const variants: any[] = data.graph.variants; | ||
|
|
||
| const variant = variants.find((v: { name: string }) => v.name === variantName); | ||
|
|
||
| if (!variant) { | ||
| throw new Error('Could not find the requested variant of the graph.'); | ||
| } | ||
| const subgraphs: any[] = variant.subgraphs; | ||
|
|
||
| return { | ||
| fedGraphRoutingURL: variant.url, | ||
| subgraphs: subgraphs.map((subgraph) => { | ||
| return { | ||
| name: subgraph.name, | ||
| routingURL: subgraph.url, | ||
| schema: subgraph.activePartialSchema.sdl, | ||
| } as MigrationSubgraph; | ||
| }), | ||
| }; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.