-
Notifications
You must be signed in to change notification settings - Fork 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
Example: feat: document node #1
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,11 +2,12 @@ import { CodegenConfig } from "@graphql-codegen/cli"; | |
|
||
const config: CodegenConfig = { | ||
schema: "https://swapi-graphql.netlify.app/.netlify/functions/index", | ||
documents: ["src/**/*.tsx"], | ||
ignoreNoDocuments: true, // for better experience with the watcher | ||
documents: ["src/**/*.gql"], | ||
// ignoreNoDocuments: true, // for better experience with the watcher | ||
generates: { | ||
"./src/gql/": { | ||
preset: "client", | ||
"./src/gql/generated.ts": { | ||
plugins: ["typescript", "typescript-operations", "typed-document-node"], | ||
// preset: "client", | ||
Comment on lines
-8
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Loading some plugins |
||
}, | ||
}, | ||
}; | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,17 @@ | ||
import React from "react"; | ||
import { useQuery } from "@apollo/client"; | ||
|
||
import "./App.css"; | ||
import Film from "./Film"; | ||
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"; | ||
Comment on lines
-6
to
+8
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
||
function App() { | ||
// `data` is typed! | ||
const { data } = useQuery(allFilmsWithVariablesQueryDocument, { | ||
variables: { first: 10 }, | ||
// `data` and `variables` are typed! | ||
const variables: AllFilmsWithVariablesQueryQueryVariables = { first: 10 }; | ||
const { data } = useQuery(AllFilmsWithVariablesQueryDocument, { | ||
variables: variables, | ||
}); | ||
return ( | ||
<div className="App"> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
import { FragmentType, useFragment } from "./gql/fragment-masking"; | ||
import { graphql } from "../src/gql"; | ||
|
||
export const FilmFragment = graphql(/* GraphQL */ ` | ||
fragment FilmItem on Film { | ||
id | ||
title | ||
releaseDate | ||
producers | ||
} | ||
`); | ||
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); | ||
Comment on lines
+1
to
-17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of |
||
return ( | ||
<div> | ||
<h3>{film.title}</h3> | ||
<p>{film.releaseDate}</p> | ||
<h3>{props.film.title}</h3> | ||
<p>{props.film.releaseDate}</p> | ||
</div> | ||
); | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query allFilmsWithVariablesQuery($first: Int!) { | ||
allFilms(first: $first) { | ||
edges { | ||
node { | ||
...FilmItem | ||
} | ||
} | ||
} | ||
} | ||
Comment on lines
+1
to
+9
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put out the gql |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment FilmItem on Film { | ||
id | ||
title | ||
releaseDate | ||
producers | ||
} |
This file was deleted.
This file was deleted.
This file was deleted.
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