-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GraphQL Codegen for generating gql types (#2485)
* Add generate types cli function | Automatically trigger in dev * Setup watcher for generate types * Add commented out code for makeMergeSchema Remove unused imports * Forgot to add codegen deps * Add types to tsconfig * Remove prebuild tasks All type generation now under rw g types Move watcher one level up, so it can be reused more easily for other actions * Progress: query operation and mutation operation results are globals * Generify graphqlHooksProvider * Fix createCell types to avoid hacking OperationResult * Allow passing through of apollo error * Update cell generator and template to have types * Transform to js, when not a typescript project * Bit of cleanup * Update cell generator snapshots * Merge template changes * Update cell list template * Get tests working | add compute for readablity * Update formatting on cell template * PR Comments * Lint * Sometimes vscode just needs a refresh 🤷
- Loading branch information
Showing
24 changed files
with
1,465 additions
and
242 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
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
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
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
17 changes: 0 additions & 17 deletions
17
packages/cli/src/commands/generate/cell/templates/cell.js.template
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
packages/cli/src/commands/generate/cell/templates/cell.tsx.template
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,22 @@ | ||
import type { ${operationName} } from 'types/gql-types' | ||
import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web' | ||
|
||
export const QUERY = gql` | ||
query ${operationName}($id: ${idType}!) { | ||
${camelName}: ${camelName}(id: $id) { | ||
id | ||
} | ||
} | ||
` | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Empty = () => <div>Empty</div> | ||
|
||
export const Failure = ({ error }: CellFailureProps) => ( | ||
<div style={{ color: 'red' }}>Error: {error.message}</div> | ||
) | ||
|
||
export const Success = ({ ${camelName} }: CellSuccessProps<${operationName}>) => { | ||
return <div>{JSON.stringify(${camelName})}</div> | ||
} |
27 changes: 0 additions & 27 deletions
27
packages/cli/src/commands/generate/cell/templates/cellList.js.template
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
packages/cli/src/commands/generate/cell/templates/cellList.tsx.template
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,29 @@ | ||
import type { ${operationName} } from 'types/gql-types' | ||
import type { CellSuccessProps, CellFailureProps } from '@redwoodjs/web' | ||
|
||
|
||
export const QUERY = gql` | ||
query ${operationName} { | ||
${camelName} { | ||
id | ||
} | ||
} | ||
` | ||
|
||
export const Loading = () => <div>Loading...</div> | ||
|
||
export const Empty = () => <div>Empty</div> | ||
|
||
export const Failure = ({ error }: CellFailureProps) => ( | ||
<div style={{ color: 'red' }}>Error: {error.message}</div> | ||
) | ||
|
||
export const Success = ({ ${camelName} }: CellSuccessProps<${operationName}>) => { | ||
return ( | ||
<ul> | ||
{${camelName}.map((item) => { | ||
return <li key={item.id}>{JSON.stringify(item)}</li> | ||
})} | ||
</ul> | ||
) | ||
} |
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
Oops, something went wrong.