-
Couldn't load subscription status.
- Fork 1
Example: feat: document node #1
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
base: main
Are you sure you want to change the base?
Conversation
| documents: ["src/**/*.tsx"], | ||
| ignoreNoDocuments: true, // for better experience with the watcher | ||
| documents: ["src/**/*.gql"], | ||
| // ignoreNoDocuments: true, // for better experience with the watcher |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I prefer to split gql into another file, but it's up to you
| "./src/gql/": { | ||
| preset: "client", | ||
| "./src/gql/generated.ts": { | ||
| plugins: ["typescript", "typescript-operations", "typed-document-node"], | ||
| // preset: "client", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading some plugins
| import { graphql } from "../src/gql"; | ||
|
|
||
| const allFilmsWithVariablesQueryDocument = graphql(/* GraphQL */ ` | ||
| query allFilmsWithVariablesQuery($first: Int!) { | ||
| allFilms(first: $first) { | ||
| edges { | ||
| node { | ||
| ...FilmItem | ||
| } | ||
| } | ||
| } | ||
| } | ||
| `); | ||
| import { | ||
| AllFilmsWithVariablesQueryDocument, | ||
| AllFilmsWithVariablesQueryQueryVariables, | ||
| } from "./gql/generated"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of writing query in tsx, you can import the types like this
| import { Film as GqlFilm } from "./gql/generated"; | ||
|
|
||
| const Film = (props: { | ||
| /* `film` property has the correct type 🎉 */ | ||
| film: FragmentType<typeof FilmFragment>; | ||
| film: GqlFilm; | ||
| }) => { | ||
| const film = useFragment(FilmFragment, props.film); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of useFragment, there are a type Film which is auto generated.
In this case conflicting to the component name though
| query allFilmsWithVariablesQuery($first: Int!) { | ||
| allFilms(first: $first) { | ||
| edges { | ||
| node { | ||
| ...FilmItem | ||
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put out the gql
NOTE: This PR shows the document node feature, how it looks like. It's ok to merge if you want, but not expected as of now.
Added some plugins
Preset has document node, however does not load
.gqlfile, just.ts/.tsxcolocation is supported.It's up to you which you prefer to use
dotansimha/graphql-code-generator#8296 (comment)