-
Notifications
You must be signed in to change notification settings - Fork 993
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gql): Codemod existing projects to get newest gql config (#9959)
- Loading branch information
Showing
8 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
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
8 changes: 8 additions & 0 deletions
8
packages/codemods/src/codemods/v7.x.x/updateGraphQLConfig/README.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# Update graphql.config.js | ||
|
||
Replaces the root `graphql.config.js` file with one that includes types and gql | ||
documents support. | ||
|
||
Fetches the file from the create-redwood-app template files on GitHub | ||
|
||
No jscodeshift is involved. |
5 changes: 5 additions & 0 deletions
5
...codemods/src/codemods/v7.x.x/updateGraphQLConfig/__testfixtures__/input/graphql.config.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const { getPaths } = require('@redwoodjs/internal') | ||
|
||
module.exports = { | ||
schema: getPaths().generated.schema, | ||
} |
11 changes: 11 additions & 0 deletions
11
...odemods/src/codemods/v7.x.x/updateGraphQLConfig/__testfixtures__/output/graphql.config.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// This file is used by the VSCode GraphQL extension | ||
|
||
const { getPaths } = require('@redwoodjs/project-config') | ||
|
||
/** @type {import('graphql-config').IGraphQLConfig} */ | ||
const config = { | ||
schema: getPaths().generated.schema, | ||
documents: './web/src/**/!(*.d).{ts,tsx,js,jsx}', | ||
} | ||
|
||
module.exports = config |
7 changes: 7 additions & 0 deletions
7
...es/codemods/src/codemods/v7.x.x/updateGraphQLConfig/__tests__/updateGraphqlConfig.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { updateGraphqlConfig } from '../updateGraphqlConfig' | ||
|
||
describe('updateGraphQLConfig', () => { | ||
it('Replaces graphql.config.js with a new version downloaded from GH', async () => { | ||
await matchFolderTransform(updateGraphqlConfig) | ||
}) | ||
}) |
17 changes: 17 additions & 0 deletions
17
packages/codemods/src/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
import { fetch } from '@whatwg-node/fetch' | ||
|
||
import { getPaths } from '@redwoodjs/project-config' | ||
|
||
export const updateGraphqlConfig = async () => { | ||
const res = await fetch( | ||
// TODO: Have to come back here to update the URL when we have a more | ||
// stable location than main | ||
// 'https://raw.githubusercontent.com/redwoodjs/redwood/release/major/v7.0.0/packages/create-redwood-app/templates/ts/graphql.config.js' | ||
'https://raw.githubusercontent.com/redwoodjs/redwood/main/packages/create-redwood-app/templates/ts/graphql.config.js' | ||
) | ||
const text = await res.text() | ||
fs.writeFileSync(path.join(getPaths().base, 'graphql.config.js'), text) | ||
} |
13 changes: 13 additions & 0 deletions
13
packages/codemods/src/codemods/v7.x.x/updateGraphQLConfig/updateGraphqlConfig.yargs.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import task from 'tasuku' | ||
|
||
import { updateGraphqlConfig } from './updateGraphqlConfig' | ||
|
||
export const command = 'update-graphql-config' | ||
export const description = | ||
'(v6.x->v7.x) Update graphql.config.js from the create-redwood-app template' | ||
|
||
export const handler = () => { | ||
task('Update root graphql.config.js file', async () => { | ||
await updateGraphqlConfig() | ||
}) | ||
} |
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